4

I want to synchronize processes based on lock files (/ socket files). These files should only be removable by their creator user.

There are plenty of choices:

/dev/shm

/var/lock

/run/lock

/run/user/<UID>

/tmp

What's the best location for this purpose? And what way are above locations meant to be used for?

7
  1. /dev/shm : It is nothing but implementation of traditional shared memory concept. It is an efficient means of passing data between programs. One program will create a memory portion, which other processes (if permitted) can access. This will result into speeding up things.

  2. /run/lock (formerly /var/lock) contains lock files, i.e. files indicating that a shared device or other system resource is in use and containing the identity of the process (PID) using it; this allows other processes to properly coordinate access to the shared device.

  3. /tmp : is the location for temporary files as defined in the Filesystem Hierarchy Standard, which is followed by almost all Unix and Linux distributions. Since RAM is significantly faster than disk storage, you can use /dev/shm instead of /tmp for the performance boost, if your process is I/O intensive and extensively uses temporary files.

  4. /run/user/$uid: is created by pam_systemd and used for storing files used by running processes for that user.

Coming to your question, you can definitely use /run/lock directory to store your lock file.

  • 5
    Note that /run/ is non-portable - in case you like to use your software on other platforms tan Linux. UNIX uses /var/lock/ or /var/run/. – schily Apr 25 '16 at 11:55
0

Make a directory under /run/lock and chmod it to 700, then create your lock files in there.

/var/lock on Linux Mint is a link to /run/lock (on Ubuntu, Linux Mint 17 and CentOS 7)

I would only store things under /run/user/<UID> if the processes only ever run while you are logged in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.