I'm writing an init.d script to start a program that I've written in C. The program follows a pretty standard template where it calls fork()
to create a child process, and then the parent process terminates almost immediately. The trouble I'm running into is that the PID file gets the parent process ID written to it, so later when I call "stop" it fails because the parent has long since ended and only the child is running.
Currently I have this command in my startup script:
start-stop-daemon --start --background -m --oknodo --pidfile "$PIDFILE" --exec "$SCRIPT" || return 2
I confess that I'm very new to all of this so I'm not even entirely sure what all those flags do. This was mostly a copy/paste from various articles I stumbled across. In any case, this would seem like a fairly common thing. How can I make it write the correct (i.e. child) process ID in the pid file?