Hi,
is there any way to set the process name of a shell script? This is needed for killing this script with the killall command.
Thanks for any hint.
Hi,
is there any way to set the process name of a shell script? This is needed for killing this script with the killall command.
Thanks for any hint.
Erm... unless I'm misunderstanding the question, the name of a shell script is whatever you've named the file. If your script is named foo
then killall foo
will kill it.
You cannot do this reliably and portably, as far as I know. On some flavors of Unix, changing what's in argv[0] will do the job. I don't believe there's a way to do that in most shells, though.
Here are some references on the topic.
You can use the kill command on a PID so what you can do is run something in the background, get its ID and kill it
PID of last job run in background can be obtained using $!
.
echo test & echo $!
On Linux at least, killall dvb
works even though dvb
is a shell script labelled with #!
. The only trick is to make the script executable and invoke it by name, e.g.,
dvb watch abc write game7 from 9pm for 3:30
Running ps
shows a process named
/usr/bin/lua5.1 dvb watch ...
but killall dvb
takes it down.