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