Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing pid file for a daemon run as user

Tags:

linux

daemon

pid

Is there a preferred place to store a pid file for a daemon that's run as a user? /var/run is the standard place, but this is for a user daemon so it doesn't have write privileges there. Presumably my daemon will be started from .profile or .bashrc or something. Is just saving it to /tmp a bad idea?

like image 1000
Falmarri Avatar asked Oct 18 '10 07:10

Falmarri


People also ask

Where should PID files be stored?

The normal location for pidfiles is /var/run . Most unices will clean this directory on boot; under Ubuntu this is achieved by /var/run an in-memory filesystem (tmpfs).

Do daemons have a PID?

For many daemons, only one instance of the daemon should be running on a system at any one time. In this use case, the daemon typically stores its PID in a well known directory (on Linux, currently /run , previously /var/run ) to indicate that an instance of the daemon is running.

What is PidFile Linux?

A PID file is a file which contains the PID of the executable which generated it. When an application terminates, that file is removed. If it is removed while the application is running, the application terminates. If the application restarts, a new PID is written to the file.


1 Answers

If it's being run for a user, let's see, what sort of storage exists that is user-specific.

Hmmm.

That's it! The home directory. I knew it would come to me eventually :-)


Sorry for the light jab. Seriously, I would just stash the PID into $HOME/.daemon.pid or ~/.daemon.pid (how you name the file is up to you of course).

This is, of course, assuming you will only have one daemon running for a user. If not, you'll need to be a bit trickier.


And hopefully allaying your fears that a user will inadvertently delete unknown files in their home directory, that's why you make it "hidden" by starting it with a . character.

Most non-experienced users should never even see these and experienced users should know better than to muck about with them.

like image 107
paxdiablo Avatar answered Sep 19 '22 02:09

paxdiablo