What is a .pid file and what does it contain?

Not sure if that's these are the only reasons, but here's my the drill:

Depending on the way you write a shellscript to kill the desired proccess you could end up killing the kill PID before it kills your target, let's take mydaemon for example:

kill -9 `ps ax | grep mydaemon | awk '{ print $1 }'`

A) SIGPIPE-ing kill In a 32-bit Linux PID is usually a 15-bit integer, overflows do happen often, there's a fairly big chance that the grep or awk PIDs will appear prior to mydaemon's one. In 64-bit PID numbers are usually 22-bit, it's more than 100x less likely to happen, yet still pretty factible.

By killing either one of your pipes you'll receive a SIGPIPE and usually this means death as well, therefore kill would be killed before killing mydaemon rendering the kill attempt a fail.

B) Killing other PIDs Also, say you had vi /etc/mydaemon/mydaemon.conf running altogether, that PID might also be killed, not to mention other users' processes since you much likely would be issuing such command as root.

C) It's a simple unix-like lock -> No additional code/daemon required. PidFiles make a fairly simple way to create user-manageable locks to keep you from spawning a daemon twice inadvertently.


The pid files contains the process id (a number) of a given program. For example, Apache HTTPD may write its main process number to a pid file - which is a regular text file, nothing more than that - and later use the information there contained to stop itself. You can also use that information to kill the process yourself, using cat filename.pid | xargs kill

Tags:

Linux

Unix

Pid