I looked around, and none of the solutions worked for me. I want to terminate a perl script using the command line.
For example:
killall myscript.pl
I'm looking for a solution similar to this, all help is appreciated. Thanks.
I looked around, and none of the solutions worked for me. I want to terminate a perl script using the command line.
For example:
killall myscript.pl
I'm looking for a solution similar to this, all help is appreciated. Thanks.
You can try pkill, which is a standard on most of today's distributions.
Eg.
pkill -f myscript.pl
If you want a more portable solution, then you can grep for the name, extract the PID, and kill:
kill $(ps xa | grep [m]yscript | awk '{ print $1; exit }')
In perl, assigning to the variable $0
should change the name of the process listing. This will affect the output of the ps
command, on which killall
and pkill
rely.
killall myscript.pl
won't work without the extra -f
argument @tvm suggested because the script is running within another program (the perl interpreter) so the process will be listed as perl /path/to/myscript.pl
You could try pkill perl
but that will kill all perl interpreters that the current user has permission to kill so it could be dangerous.
The best way to go about this programmatically is to modify the name of the process by assigning to the $0
variable
#!/usr/bin/perl
$0 = 'myscript';
sleep 60;
... and then in a standard unix shell:
$pkill -9 myscript
See Dynamically name processes for more info.