Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In a program of mine, I've forked a new process. I want the pid of the new process to be preserved with the original parent program. In fact, I want it to be preserved even after the parent program has terminated, so that next time this program is executed, it knows the pid of the process that had been created in its previous execution (the user may want it to be 'killed', for which the pid is required). I know I can store the pid in a text file and later on read it, but that'll be quite risky, since anyone can alter the contents of the file, or even delete it. Is there some other way of retaining the pid?
Most software I'm familiar with just writes it out to a file (usually in /var/run -- obviously this file should only be root writeable (or writeable by only the user the program runs as) to keep just anybody from messing with it. I suppose you could try some esoteric strategy of storing it in a shared memory segment, but you still need a key to access the segment so that really doesn't gain you anything except for more trouble. You could also have your program parse the ps output, but that brings on its own set of troubles (for instance, an instance may not be the instance kicked off the last time this program ran).
It's just a place where programs can store data about their execution such as a file containing their PID or a socket that can be used to send data to the program. There's no reason this has to be stored in /var/run, but a lot of programs do. Why not look at /var/run on your own system and see what's there to get an idea about this?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.