If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Linux Kill script

I'm trying to write a script to pull a PID number out of a file and then pipe that into the kill command.

For example..I wrote a start script to start a daemon, but I need to write a stop script as well to stop the daemon....when the daemon is started it creates a file "file.pid" which holds the process number that the daemon started with. I need to pull that number from the .pid file and feed it to the kill command.

I'm not the best programmer in the world, but if somebody can give me the syntax or what not for that, i can probably take it from there...or if someone has a better idea I'm open to that as well....I tried killall, but no joy.

Would recommend you use -15 instead of -9 first. -15 is a normal close process signal. Some processes are particularly ticky about having everything dropped out beneath them (which is what 9 does...think of it as 'die, die now, don't do anything else but die'). Kill -9 is great when a process is truly hung, but if you are just wanting to stop a running process that isn't hung, 15 is much safer.

EDIT: Side note, many variations of unix also have a pkill command, which will let you kill by the process name, rather than the PID, which could also be helpful for scripting a shutdown process.

EDIT 2: 'kill' is also a misnomer. Kill is really a signaling program that can be used to send out of program signals to a running process. Somewhere in your unix source includes should be a signal.h if you want to look at all the different signals you can send. AFAIK, you'll need to send what signal you want to send to the process when you issue the command (so kill `cat /somedir/someprocess.pid` should also have the -15 or -9 (or whichever) in there as well.

Last edited by nebulus200; November 24th, 2006 at 03:46 PM.

There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.