lsvolo has asked for the wisdom of the Perl Monks concerning the following question:
Now I face two problems that I would need your kind help if possible. First is that the print outcome in the file is using two line instead of oneuse warnings; # Some Variables $pid = `pgrep -f '[a]bc'`; $msg = "Alive"; $timestamp = localtime(time); # Open file open $fh, '>>' , 'file.txt' or die ( "Could not open file! $!\n" ) ; # Loop Condition $i = 0; until ($i > 60) { if ($pid) { $timestamp = localtime(time); print $fh ("$pid , $timestamp , $msg\n"); $pid = `pgrep -f '[a]bc'`; }else{ $timestamp = localtime(time); print $fh ("No pid , $timestamp\n"); $pid = `pgrep -f '[a]bc'`; } $i = $i +1; sleep 10; } print $fh ("Time over , $timestamp\n"); close $fh;
Second is that when the script is in "sleep 10" if I kill the PID the next print in the file will show that is still Alive. I have used IO::Handle and $|=1 to solve this but it didn't work. I don't use perl much possibly twice a year so apologies in advance if my questions are not appropriate. Any help will be much appreciate.example: 9910 abc , Tue Sep 13 04:44:33 2016 , Alive
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help to monitor a PID
by haukex (Archbishop) on Sep 13, 2016 at 10:14 UTC | |
|
Re: Help to monitor a PID
by Cuhulain (Beadle) on Sep 13, 2016 at 09:44 UTC | |
by lsvolo (Novice) on Sep 13, 2016 at 10:08 UTC | |
|
Re: Help to monitor a PID
by Corion (Patriarch) on Sep 13, 2016 at 10:13 UTC | |
by lsvolo (Novice) on Sep 13, 2016 at 10:17 UTC |