get_pid() will check to make sure the pid actually exists
authorSteve Singer <ssinger@ca.afilias.info>
Thu, 8 Nov 2012 19:02:20 +0000 (14:02 -0500)
committerLuiz K. Matsumura <luiz.matsumura@gmail.com>
Thu, 8 Nov 2012 22:14:28 +0000 (20:14 -0200)
tools/altperl/slon-tools.pm

index 4072ccfd925f0473bf20ecf9b6ef98753b9731be..cde1663a4fbb712018b7c6d6d73c43c0040ce3e5 100644 (file)
@@ -4,6 +4,7 @@
 # Copyright 2004-2009 Afilias Canada
 
 use POSIX;
+use Errno;
 use File::Temp qw/ tempfile tempdir /;
 
 sub add_node {
@@ -147,6 +148,12 @@ sub get_pid {
   #print "Command:\n$command\n";
   chomp $pid;
 
+  #make sure the pid actually exists
+  kill(0,$pid);
+  if ($! == Errno::ESRCH) {
+         return 0;
+  }
+
   return $pid;
 }