Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Just another Perl shrine
 
PerlMonks  

Re^2: how can a perl script determine it's own PID while running

by Anonymous Monk
on Aug 14, 2006 at 19:59 UTC ( #567320=note: print w/ replies, xml ) Need Help??


in reply to Re: how can a perl script determine it's own PID while running
in thread how can a perl script determine it's own PID while running

OK - this is perfect (exactly what I was looking for)
Now.... I would like to take this a step further:
I would like to take the newly found value from $$ and send it to another script, (the sending part is not a problem), and have that new program check on a regular basis (still linux OS) and see if the PID still exists... once the PID that the new program is monitoring finishes the new program will do something.
The question is: How do I monitor said PID from the current script??
Thanks Again for Your Great Wisdom!


Comment on Re^2: how can a perl script determine it's own PID while running
Re^3: how can a perl script determine it's own PID while running
by friedo (Prior) on Aug 14, 2006 at 20:06 UTC
    You can use the unfortunately named kill function with a signal value of zero to see if a process is still alive.

    my $pid = 1234; if( kill 0, $pid ) { # it's alive } else { # it's dead }
Re^3: how can a perl script determine it's own PID while running
by vxp (Pilgrim) on Aug 14, 2006 at 20:07 UTC
    i'd suggest making a /var/run/yourProgram.run file that containts the PID of your script, like so many other UNIX programs have. Have the file deleted when your script exits. then have your other script monitor that file.
      Though if your script gets severely trashed a la kill -9 the file would still be there. Usually you are best off combining the pid file with a kill check... or a check for the proc dir.

                      - Ant
                      - Some of my best work - (1 2 3)

        That's why you don't just check for the file. If the file exists, you read the process's pid from the file and then check for the process.
Re^3: how can a perl script determine it's own PID while running
by Anonymous Monk on Aug 15, 2006 at 18:03 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://567320]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-04-17 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (441 votes), past polls