LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-22-2004, 08:05 AM   #1
linuxprogrammer
LQ Newbie
 
Registered: Jul 2004
Posts: 26

Rep: Reputation: 15
I want to preserve a pid


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?
 
Old 07-22-2004, 10:43 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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).
 
Old 07-22-2004, 10:52 AM   #3
Tuttle
Senior Member
 
Registered: Jul 2003
Location: Wellington, NZ
Distribution: mainly slackware
Posts: 1,291

Rep: Reputation: 52
all pids and program states are browsable in /proc, try 'grep commandname /proc/*/cmdline'
 
Old 07-23-2004, 08:26 AM   #4
linuxprogrammer
LQ Newbie
 
Registered: Jul 2004
Posts: 26

Original Poster
Rep: Reputation: 15
can u tell me what is the /var/run folder all about?
 
Old 07-23-2004, 09:55 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
rm cannot remove /var/run/atd.pid and /var/run/xdm.pid danishmr Linux - Software 1 05-04-2004 08:01 AM
preserve links jmr71769 Debian 2 04-22-2004 10:01 AM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 08:05 PM
preserve the ownership juno Linux - General 5 01-08-2003 11:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration