• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to kill a process in Linux

LuckyTaxi

Diamond Member
How do I kill all instances of a certain program that is running? if i do a "ps aux | grep xmms"
I see like 3 or 4 instances of it running. I normally do 'kill -9 [PID], but it's ridiculous when I have to
do it for all 4 instances.
 
Why is it rediculous? If you are running 4 copies of it why should it kill all 4 processes? If it did do something like that I would consider it a SERIOUS bug.
 


<< Why is it rediculous? If you are running 4 copies of it why should it kill all 4 processes? If it did do something like that I would consider it a SERIOUS bug. >>



uhhh...i saw four different PIDs. I only opened it once. I've seen this happen with other progs as well. Wasn't there something like
a 'kill -HUP?' Something along those lines?
 


<< You can do "killall -9 <processname>" to kill all processes with that name. >>



thx sunner. I hate the type of ppl who question you. Just tell me the answer! I wouldn't
have asked it in the beginning if it wasn't true! 😛
 
HUP sends a signal 1, forcing a process to re-read its configuration, then proceed with the same process id, for instance, if you have named running, and you make some configuration changes, you'd kill -HUP it to make it read the new config.
 
killall -9 sends SIGKILL to a process, not allowing it to clean up after itself. Using killall <pid> sends SIGTERM and is a much nicer way. From the FreeBSD handbook:

Two signals can be used to stop a process, SIGTERM and SIGKILL. SIGTERM is the polite way to kill a process; the process can catch the signal, realize that you want it to shut down, close any log files it may have open, and generally finish whatever it is doing at the time before shutting down. In some cases a process may even ignore SIGTERM if it is in the middle of some task that can not be interrupted.

SIGKILL can not be ignored by a process. This is the ``I do not care what you are doing, stop right now'' signal. If you send SIGKILL to a process then FreeBSD will stop that process there and then[1].

The moral of the story: try killall <pid> first, then try killall -9 <pid>.
 
Be carefull with killall, I believe Linux is the only unix OS where it works like that. All the others I've ran it on (Tru64 and Solaris) it actually kills all, meaning all processes on the system die.

Also, like BlackOmen said, only use -9 or -KILL as a last resort because you just rip everything out from under the process and if it doesn't have a chance to clean up before it shuts down you might run into some strange problems.
 
Good point Nothinman, didn't think of using killall on other unixes. This is from the man page on SunOS 5.7:
DESCRIPTION
killall is used by shutdown(1M) to kill all active
processes not directly related to the shutdown procedure.

killall terminates all processes with open files so that
the mounted file systems will be unbusied and can be
unmounted.

killall sends signal (see kill(1)) to the active processes.
If no signal is specified, a default of 15 is used.

The killall command can be run only by the super-user.


So it might be better practice to use kill and the individual pid's.
 
Back
Top