views:

54

answers:

5

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.

+1  A: 

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.

VoteyDisciple
Not true. Try it. Create a file called "tst.sh", make it executable, have it do something like a "sleep 30", and fire it up. You'll note that the process name associated with it is "/bin/sh" or "/bin/bash" or whatever you put in the shebang line.
Brian Clapper
A: 

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.

Brian Clapper
A: 
Weboide
A: 

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 $!

Abs
A: 

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.

Norman Ramsey