in reply to Help to monitor a PID

As for your second question: After your sleep, you only update $pid after printing the message. Maybe consider always updating $pid directly after the sleep instead of updating it after printing in two parts of your program:

$pid = `pgrep -f '[a]bc'`; ... until ($i > 60) { if ($pid) { $timestamp = localtime(time); print $fh ("$pid , $timestamp , $msg\n"); }else{ $timestamp = localtime(time); print $fh ("No pid , $timestamp\n"); } $i = $i +1; sleep 10; $pid = `pgrep -f '[a]bc'`; }

Replies are listed 'Best First'.
Re^2: Help to monitor a PID
by lsvolo (Novice) on Sep 13, 2016 at 10:17 UTC
    Thank you both for you comments and the time spend to assist! Work fine now