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?










share|improve this question









New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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















up vote
0
down vote

favorite












I need to store the pid number in a file/files. How to do it?










share|improve this question









New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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













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?










share|improve this question









New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to store the pid number in a file/files. How to do it?







pidfile






share|improve this question









New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









ctrl-alt-delor

9,93831954




9,93831954






New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









user321453

6




6




New contributor




user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user321453 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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














  • 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










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.






share|improve this answer























  • ... and a shell can use "$$".
    – Kusalananda
    2 days ago










  • exec does not create a new process.
    – ctrl-alt-delor
    2 days ago


















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.






share|improve this answer























  • ... and a shell can use "$$".
    – Kusalananda
    2 days ago










  • exec does not create a new process.
    – ctrl-alt-delor
    2 days ago















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.






share|improve this answer























  • ... and a shell can use "$$".
    – Kusalananda
    2 days ago










  • exec does not create a new process.
    – ctrl-alt-delor
    2 days ago













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • ... 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



Popular posts from this blog

サソリ

広島県道265号伴広島線

Setup Asymptote in Texstudio