I never had to create my own pid; Your question was interesting.
Here is the bash code snippet I found:
#!/bin/bash PROGRAM=/path/to/myprog $PROGRAM & PID=$! echo $PID > /path/to/pid/file.pid
You will need to have root privileges to put the file.pid file in / var / run associated with many articles, so daemons have root privileges.
In this case, you need to put your pid in a certain place known to your start and terminate the scripts. You can use the fact that a pid file exists, for example, to prevent the second identical process from starting.
$ PROGRAM and puts the script in the background batch.
If you want the program to hang after the script exits, I suggest running it with nohup, which means that the program will not die when your script exits the system.
I just checked. PID is returned with nohup.
source share