SPUG:
Jonathan Gardner
jgardn at alumni.washington.edu
Mon Aug 26 20:55:27 CDT 2002
On Monday 26 August 2002 04:40 pm, Creede Lambard wrote:
> I'd say, every time program A or program B runs, save its PID in a file
> somewhere (or database table, or whatever). Then, when you decide to
> shut down, go through the list in that file and kill all the pids in it.
>
> If you do this be sure to remove the PID entry when an instance of the
> program exits or you could cause yourself unnecessary work.
>
It's not much work to check to see if a PID stored in a file is valid. Try
this:
$pid = `cat $pidfile`;
chomp $pid;
if (kill 0, $pid) {
# still running.
} else {
# dead - stale lockfile.
}
There is a small chance that the child has been long dead and you have cycled
through the available PIDs, and a different process is running as that PID,
but what can you do about that?
--
Jonathan Gardner
jgardn at alumni.washington.edu
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list