Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it good practice to create a directory in /run/shm (formerly /dev/shm) and use that like a temp directory for an application?

Background: I am writing black box tests for a program which does a lot of stuff with files and directories. For every test I create a lot of files and directories and then run the program and then create the expected set of files and directories and then run diff to compare. I now have about 40 tests and they are already taking over 2 seconds to run. Hoping to speed things up I want to run the tests in a directory on some sort of ramdisk.

Researching about ram disk I stumbled upon this question with an answer stating that it is okay to create a directory in /dev/shm and use that like a temp directory. Researching some more however I stumbled upon this article from debian stating that it is an error to use /dev/shm directly. I should use the shm_* functions. Unfortunately the shm_* functions seem to be not available for use in a shell script.

Now I am confused. Is it okay or not to use /run/shm (formerly /dev/shm) like a temp directory?

share|improve this question
    
Yes, many users also mounts /tmp into shared memory. –  Eddy_Em Apr 22 '13 at 11:08

1 Answer 1

up vote 4 down vote accepted

It's perfectly okay to use some directory in /run as long as you have the appropriate rights on it. In some modern distros, /tmp is already a virtual file system in memory or a symlink to a directory inside /run. If this is your case (you can check that in /etc/fstab, or typing mtab), you could use /tmp as your temporary directory.

Also, don't get confused with the article from Debian. shm_* functions are used to create shared memory segments for Inter-Process Communication. With those functions, you can share a fragment of memory between two or more processes to have them communicate or collaborate using the same data. The processes have the segment of memory attached in their own adressing space and can read and write there as usual. The kernel deals with the complexity. Those functions are not available as shell functions (and wouldn't be very useful in a shell context). For further information, have a look at man 7 shm_overview. The point of the article is that no program should manage directly the pseudo-files representing shared segments, but instead use the appropriate functions to create, attach and delete shared memory segments.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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