in reply to Determining a Unix PID
If you only need to make the determination once, then the answers above are good.
If you need to repeat the test, for instance, if you need to keep testing until the process has terminated, then you can save repeating the search process (by whatever method) more than once by retaining the PID from the first search and then use the trick described in perlfunc:kill.
If SIGNAL is zero, no signal is sent to the process. This is a useful way to check that the process is alive and hasn't changed its UID. See the perlport manpage for notes on the portability of this construct.
Ie. Once you know the process id
if( kill 0, $pid ) { # the process is still running } else { # has gone away. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Determining a Unix PID
by skyknight (Hermit) on Jul 25, 2003 at 15:17 UTC |