Question about writing a daemon in C

Hello,

I have some question regarding programming a daemon. Do I need to write pid of my process in /var/run/app.pid ?

I know it helps at restarting the daemon but how is better, with or without that file?
 
As you said, it helps restarting/stopping the daemon. From the point of view of your program it really doesn't matter.
 
Generally what you will find is this isn't handled via the actual program itself but you can get your programs pid from libc at runtime.

http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?getpid+2

Generally the init-scripts are simply a script which will start stop restart and do any invoke's of the actual program so you never touch the binary.

So this means the init-script will get/read the pid and then touch a file with the pid etc. Just take a look at a few init-scripts each os has there own way of doing them and they are very standardised.
 
Back
Top