How can I store PID into a file [on hold]
up vote
0
down vote
favorite
I need to store the pid number in a file/files. How to do it?
pidfile
New contributor
put on hold as too broad by Jeff Schaller, Thomas, jimmij, RalfFriedl, Isaac 2 days ago
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I need to store the pid number in a file/files. How to do it?
pidfile
New contributor
put on hold as too broad by Jeff Schaller, Thomas, jimmij, RalfFriedl, Isaac 2 days ago
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
2
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to store the pid number in a file/files. How to do it?
pidfile
New contributor
I need to store the pid number in a file/files. How to do it?
pidfile
pidfile
New contributor
New contributor
edited 2 days ago
ctrl-alt-delor
9,93831954
9,93831954
New contributor
asked 2 days ago
user321453
6
6
New contributor
New contributor
put on hold as too broad by Jeff Schaller, Thomas, jimmij, RalfFriedl, Isaac 2 days ago
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as too broad by Jeff Schaller, Thomas, jimmij, RalfFriedl, Isaac 2 days ago
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
2
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago
add a comment |
6
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
2
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago
6
6
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
2
2
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
PID files can be created by the process itself or by a helper program, which writes a PID file after starting the main program.
On Unix-like systems, new programs are often created using fork()
and exec()
system calls. fork()
creates a copy of the calling process, returning child's process ID (PID) in parent and 0 in the child. The parent process (helper program) can save the PID in a PID file. exec()
is then used to launch the new program.
The process can get its own PID using getpid()
system call and then saves it to a file.
If you are starting a program from the shell, you could use a helper program such as start-stop-daemon
(if on a Debian-based system), which can write a PID file after starting the program. If your program demonizes itself, you can also store the PID from the shell by accessing the $$
variable.
... and a shell can use"$$"
.
– Kusalananda
2 days ago
exec
does not create a new process.
– ctrl-alt-delor
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
PID files can be created by the process itself or by a helper program, which writes a PID file after starting the main program.
On Unix-like systems, new programs are often created using fork()
and exec()
system calls. fork()
creates a copy of the calling process, returning child's process ID (PID) in parent and 0 in the child. The parent process (helper program) can save the PID in a PID file. exec()
is then used to launch the new program.
The process can get its own PID using getpid()
system call and then saves it to a file.
If you are starting a program from the shell, you could use a helper program such as start-stop-daemon
(if on a Debian-based system), which can write a PID file after starting the program. If your program demonizes itself, you can also store the PID from the shell by accessing the $$
variable.
... and a shell can use"$$"
.
– Kusalananda
2 days ago
exec
does not create a new process.
– ctrl-alt-delor
2 days ago
add a comment |
up vote
2
down vote
PID files can be created by the process itself or by a helper program, which writes a PID file after starting the main program.
On Unix-like systems, new programs are often created using fork()
and exec()
system calls. fork()
creates a copy of the calling process, returning child's process ID (PID) in parent and 0 in the child. The parent process (helper program) can save the PID in a PID file. exec()
is then used to launch the new program.
The process can get its own PID using getpid()
system call and then saves it to a file.
If you are starting a program from the shell, you could use a helper program such as start-stop-daemon
(if on a Debian-based system), which can write a PID file after starting the program. If your program demonizes itself, you can also store the PID from the shell by accessing the $$
variable.
... and a shell can use"$$"
.
– Kusalananda
2 days ago
exec
does not create a new process.
– ctrl-alt-delor
2 days ago
add a comment |
up vote
2
down vote
up vote
2
down vote
PID files can be created by the process itself or by a helper program, which writes a PID file after starting the main program.
On Unix-like systems, new programs are often created using fork()
and exec()
system calls. fork()
creates a copy of the calling process, returning child's process ID (PID) in parent and 0 in the child. The parent process (helper program) can save the PID in a PID file. exec()
is then used to launch the new program.
The process can get its own PID using getpid()
system call and then saves it to a file.
If you are starting a program from the shell, you could use a helper program such as start-stop-daemon
(if on a Debian-based system), which can write a PID file after starting the program. If your program demonizes itself, you can also store the PID from the shell by accessing the $$
variable.
PID files can be created by the process itself or by a helper program, which writes a PID file after starting the main program.
On Unix-like systems, new programs are often created using fork()
and exec()
system calls. fork()
creates a copy of the calling process, returning child's process ID (PID) in parent and 0 in the child. The parent process (helper program) can save the PID in a PID file. exec()
is then used to launch the new program.
The process can get its own PID using getpid()
system call and then saves it to a file.
If you are starting a program from the shell, you could use a helper program such as start-stop-daemon
(if on a Debian-based system), which can write a PID file after starting the program. If your program demonizes itself, you can also store the PID from the shell by accessing the $$
variable.
edited 2 days ago
Fabby
2,94411125
2,94411125
answered 2 days ago
sebasth
7,86831845
7,86831845
... and a shell can use"$$"
.
– Kusalananda
2 days ago
exec
does not create a new process.
– ctrl-alt-delor
2 days ago
add a comment |
... and a shell can use"$$"
.
– Kusalananda
2 days ago
exec
does not create a new process.
– ctrl-alt-delor
2 days ago
... and a shell can use
"$$"
.– Kusalananda
2 days ago
... and a shell can use
"$$"
.– Kusalananda
2 days ago
exec
does not create a new process.– ctrl-alt-delor
2 days ago
exec
does not create a new process.– ctrl-alt-delor
2 days ago
add a comment |
6
You want to store a process ID in a file. What process' PID do you want to store, and why?
– Kusalananda
2 days ago
2
How do you have the PID number right now? A variable? By looking it up based on a process name?
– Jeff Schaller
2 days ago