Hello deyaneria,
The logic of the do ... while loop is wrong. If the user answers “N”, the script still asks for a PID and then attempts to kill it! Also, you shouldn’t mix system with backticks (they are two ways of doing the same thing). Try something like this (untested):
sub kill_process { print "Kill processes for the user? (y or n)?\n"; my $ans = <>; while ($ans =~ /^Y/i) { print "Enter pid to kill:\n"; my $pid = <>; chomp $pid; if (is_valid($pid)) { `kill $pid`; print "Process $pid killed\n"; } else { print "Process $pid is invalid\n"; } print "Kill more processes for the user? (y or n)?\n"; my $ans = <>; } }
(You will need to implement sub is_valid too.)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Killing processes
by Athanasius
in thread Killing processes
by deyaneria
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |