Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Can I see how long a process has been running?

by soffen (Acolyte)
on Sep 30, 2002 at 16:14 UTC ( [id://201754]=perlquestion: print w/replies, xml ) Need Help??

soffen has asked for the wisdom of the Perl Monks concerning the following question:

If I know the process id (PID) of a process that is (or should be) running (like a script that takes 3 to 5 or more minuts to run), can I use it in a seperate script (like, haveing the process write its PID to a file, and having the other script open the file and read the PID) to check how long that process has been running and/or if it is still running? if so, how?
  • Comment on Can I see how long a process has been running?

Replies are listed 'Best First'.
Re: Can I see how long a process has been running?
by fglock (Vicar) on Sep 30, 2002 at 16:26 UTC

    This works for me (FreeBSD - it is not portable):

    $process = 224; @a = `ps -p $process`; @b=split(/\s+/,$a[1]); print $b[4];
Re: Can I see how long a process has been running?
by robartes (Priest) on Sep 30, 2002 at 17:49 UTC
    Hi soffen, you could try parsing the output from ps, but a search of CPAN for "process managment" turns up the module Proc::Processtable::Process. You should specifically be interested in the time and start methods, respectively to get the CPU time and (with a bit of arithmetic) the wall time consumption of the process.
Re: Can I see how long a process has been running?
by Moonie (Friar) on Sep 30, 2002 at 16:24 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found