Saturday, May 26, 2007

Check whether a process is running or not

The example Perl code demonstrate checking whether a process is running or not.
#!/usr/bin/perl -w
#$file: watchProcess.pl - watch whether a proccess is running.

use strict;
use POSIX;

my $pid = shift;
die "usage: watchProccess pid\n" unless defined $pid;
my $times =0;
do{
  sleep(5);
  $times++;
  print "loop: $times\n";
}until kill(SIGCHLD,$pid)==0;
print "proccess $pid is end.\n";
 
Blogger Template Layout Design by [ METAMUSE ] : Code Name Gadget 1.1 Power By freecode-frecode.blogger.com & blogger.com Programming Blogs - BlogCatalog Blog Directory