jewee
asked on
Kill a process by name
In my perl script, I have the following:
my $processid = `ps -elf | pgrep \"SybProc\"`;
if ($processid)
{
my $killprocess = system ("kill $processid");
if ($killprocess != 0)
{
print "Cannot kill process\n";
}
}
if the SybProc process exists, it kills it. However, sometimes the system call does not return 0 even if it successfully killed the process.
What is wrong with the implementation?
my $processid = `ps -elf | pgrep \"SybProc\"`;
if ($processid)
{
my $killprocess = system ("kill $processid");
if ($killprocess != 0)
{
print "Cannot kill process\n";
}
}
if the SybProc process exists, it kills it. However, sometimes the system call does not return 0 even if it successfully killed the process.
What is wrong with the implementation?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the more than "SybProc" process is running, the script kills the first process but other process remain unkilled. so u amy need to change the script.
'ps -elf | pgrep \"SybProc\"` >> dump in a temp file;
cut the process id filed from the temp file put it an array
then use the "kill $procid" in loop, so that it will kill one by one.
'ps -elf | pgrep \"SybProc\"` >> dump in a temp file;
cut the process id filed from the temp file put it an array
then use the "kill $procid" in loop, so that it will kill one by one.
What does pgrep do?
what is $processid when the system call does not return 0?
what is $processid when the system call does not return 0?
ASKER