Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing PID File on Linux

I am currently working on a linux daemon that needs to be single instance (i.e restricted to 1 user 1 process). What would be the best way of doing so without having to use getpid() to manually write the pid out to /var/run/ and then lock it using flock()?

like image 426
Error1f1f Avatar asked Mar 18 '11 16:03

Error1f1f


People also ask

What is a Linux PID file?

A Pid-File is a file containing the process identification number (pid) that is stored in a well-defined location of the filesystem thus allowing other programs to find out the pid of a running script.

Where is the PID file in Linux?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.


1 Answers

Wrap the start-up and shut-down with start-stop-daemon.

like image 197
wnoise Avatar answered Sep 24 '22 23:09

wnoise