Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

how can a perl script determine it's own PID while running

by Anonymous Monk
on Aug 14, 2006 at 19:22 UTC ( #567304=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

On Linux OS, how can a running Perl Script determine it's own PID and store it to a variable???

Comment on how can a perl script determine it's own PID while running
Re: how can a perl script determine it's own PID while running
by Joost (Canon) on Aug 14, 2006 at 19:24 UTC
      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!
        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 }
        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-20 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls