LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to kill ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-kill-493473/)

Volcano 10-18-2006 07:20 AM

how to kill ?
 
i have got 10 process numbers

say, 123 456 678 907 .....


How do i kill all of them in one go >?


kill - 15 123 456 678 907 ..blah blah ...does it work ?

Volcano 10-18-2006 07:25 AM

i have seen -15 is an additional parameter to be used in my manual given to me.

i dont know what it does.

matthewg42 10-18-2006 08:14 AM

Yes it should work with the GNU version of kill. I think some non-gnu implementations on other unix-like OSes may only accept one PID at a time.

The one problem with your command: the "- 15" shouldn't have a space in it.

What kill does is send a signal to the specified processes. Signals can be specified numerically or by their name. If you don't tell kill which signal to send, it sends one called SIGTERM (number 15). You can get a list of signal names/numbers by using the command:
Code:

kill -l
(that's a lower case L, not a number 1).

Background: for many signals the default action of a program is to terminate. Programmers can change this behaviour for most signals - all except number 9 - SIGKILL. SIGKILL will always terminate a program. Thus you often see people going something like this:

Code:

$ ps
  PID TTY          TIME CMD
10041 pts/3    00:00:00 annoyingprogram
$ kill 10041
$ ps
  PID TTY          TIME CMD
10041 pts/3    00:00:00 annoyingprogram
$ echo "OK tough guy, prepare to meet your fate."
OK tough guy, prepare to meet your fate.
$ kill -9 10041

Note that you can't send signals to just any process on the system - there is a permissions system. Generally speaking, you can send signals to all processes you "own", and root can send signals to any process.

Volcano 10-18-2006 08:25 AM

Quote:

Originally Posted by matthewg42
Yes it should work with the GNU version of kill. I think some non-gnu implementations on other unix-like OSes may only accept one PID at a time.

The one problem with your command: the "- 15" shouldn't have a space in it.

What kill does is send a signal to the specified processes. Signals can be specified numerically or by their name. If you don't tell kill which signal to send, it sends one called SIGTERM (number 15). You can get a list of signal names/numbers by using the command:


yahoooo.....thank you.

so you approve that the command works ...right ?


but i dont understand what that 15 does ?

please explain it.




and how does system will understand that 15 is not a process id ?

is it really that no process can have id 15 , 9 etc ?



Code:

kill -l
(that's a lower case L, not a number 1).

Background: for many signals the default action of a program is to terminate. Programmers can change this behaviour for most signals - all except number 9 - SIGKILL. SIGKILL will always terminate a program. Thus you often see people going something like this:

Code:

$ ps
  PID TTY          TIME CMD
10041 pts/3    00:00:00 annoyingprogram
$ kill 10041
$ ps
  PID TTY          TIME CMD
10041 pts/3    00:00:00 annoyingprogram
$ echo "OK tough guy, prepare to meet your fate."
OK tough guy, prepare to meet your fate.
$ kill -9 10041

Note that you can't send signals to just any process on the system - there is a permissions system. Generally speaking, you can send signals to all processes you "own", and root can send signals to any process.

matthewg42 10-18-2006 08:53 AM

Sorry, I was a little unclear.

If the first parameter to kill starts with - followed by a number (with no spaces in between), that number is interpretted as the signal number to send to the process IDs (the other numbers on the command line).

If the first parameter to kill doesn't start with a - the default signal number is used (15).

you can see the names associated with the signal numbers by using the "kill -l" (lower case L) command. Here's a few which are commonly used from the command line:
  • 1) SIGHUP - Hang up. Sent to processes when the terminal from which they were launched closes. This is sometimes used to tell server processes to re-read their configuration files.
  • 9) SIGKILL - cannot be over-ridden by programs - REALLY kill a process right now.
  • 15) SIGTERM - ask a program to terminate (it may ignore the signal, or take a little while because it has some cleanup routines to perform).

Incidentally, you don't have to use the signal number to specify a signal. You can also do this:

Code:

kill -KILL 12345
kill -TERM 12346

And so on. The various signals and their history are quite interesting for the curious geek. For example, SIGHUP gets it's name from the fact that it used to correspond to a serial line attached to a dumb terminal, telephone line etc. literally hanging up on the computer :)

usaf_sp 10-18-2006 01:31 PM

Check out the following commands to better understand kill:

man kill
info kill

You will find many answers this way.

Using man and info before any command you have a question about will pull up its documentation.

RMLinux 10-19-2006 02:36 AM

type ps - e | less
now you can navigate all the list of running task number followed by the name.
then kill [number] e.g. kill 1001;

matthewg42 10-19-2006 05:00 AM

See also killall

timmeke 10-19-2006 10:05 AM

Quote:

is it really that no process can have id 15 , 9 etc ?
No. Processes can indeed have ids 1, 2, etc. In fact, the process with id 1 is always there: it's a special process, often called "init" and one of the first processes launched when you boot your Linux machine.

As said, kill distinguishes the process IDs from the signal number by the "-" in front. That's why you shouldn't put a space between "-" and the signal number as well.
If you're worried about typos (ie mistakingly putting in the space), then you should stick with the names of the signals.

Adrian Baker 10-24-2006 06:06 AM

Hi there

I've read the above but still can't see how to use this command.

Yast has locked up on my laptop (does it regularly!) How do I kill it??


I use the kill command, but with what? you seem to say that processes have numbers.. how do I find this out for Yast?

Thanks

matthewg42 10-24-2006 06:48 AM

OK, I don't have SuSE, so I can't tell you exactly how to kill off YaST because it only runs with SuSE. I can provide an example which is very similar though, and you should be able to apply this process to your problem.

Killing Synaptic Package Manager

First thing to note - killing off synaptic if it's half way through installing something may leave your package database in a bad way, and you'll have to fix this somehow. This is just an example!

OK, lets assume synaptic is running, but has locked up. Here's how to kill it using the kill command.

Firstly, synaptic runs with root permissions. This means regular users can't send signals to it - only root can send signals to a process running as root. Because of this, we need to start a terminal, and switch to the root user.

There several ways to do this. On systems which allow it, the easiest way is to use the command

Code:

su - root
You'll be prompted for the root password. If the command is successful, the prompt will probably change to something with the # character at the end.

For systems which disable the root user, such as ubuntu, you can still get a root shell by using this command as a user who is allowed to use sudo:

Code:

sudo bash
...and then entering the proper password for sudo. On Ubuntu this is the user's regular password, but it only word for users who are in the "adm" group.

OK, so now you should have a terminal running with a root shell.

The next step is to find out the process ID (PID) of the process which we want to kill.

We know the name of the program - in this case synaptic. There are lots of ways to find the process ID of the process, but we're going to use the time-old ps and grep method. Here's the command:

Code:

ps aux |grep -i synaptic
This command lists all processes on the system (this is what "ps aux" does) and then filters that list for the word "synaptic" (this is what the "grep -i synaptic" bit does).

Here's the output I get:

Code:

root      6950  1.1  4.9  50496 25504 pts/1    S    12:32  0:02 synaptic
root      7056  0.0  0.1  2892  812 pts/1    R+  12:36  0:00 grep -i synaptic

Note that I see the grep process as well... grep -i synaptic matches it's own command. Far out. Anyway, the bit we're interested in is the second column of the line for synaptic itself. This is the PID of that process, in this case 6950.

So now we know the process ID to kill, lets kill it. First we'll let kill send the default signal, which is called SIGTERM. This signal will "request" that the program terminates. Maybe the program will ignore this. Lets see. Notice that since we're send the default signal, we don't need to tell kill which signal - we don't provide the -TERM or -15 option.

Code:

kill 6950
OK, lets' see if it died.

Code:

ps aux |grep -i synaptic
root      7095  0.0  0.1  2892  860 pts/1    R+  12:40  0:00 grep -i synaptic

You can see that synaptic has vanished. yay - we killed it.

If it had not died, we could have got serious by sending the KILL signal. This doesn't just ask a process to terminate, it tells it. There's no argument with the kill signal. Here's how I would have done it:

Code:

kill -KILL 6950
I could also have done it this way:

Code:

kill -9 6950
...because the -KILL and the -9 are just different ways to say "use the kill signal".



Now the caveats.
  1. Sometimes program have more than one process, so you may need to kill several processes to stop a program running.
  2. You need to search for the name of the program file which is executed to run the program you want to kill. This isn't always the same as the name of the program which you see in the user interface. For example the gnome system monitor program has the program name gnome-system-monitor.
  3. If a process runs as root, you must kill it as root
  4. Use kill without the -KILL option first - some programs will intercept this signal and do nice things like saving open files, cleaning up temp files and so on beforer dying. The KILL signal doesn't give programs any chance to do this sort of thing - it just slays those processes immediately.

Hope that wasn't too long and boring.

Adrian Baker 10-24-2006 07:01 AM

Too long and boring??? No way!!

That is such a great answer - thank you so much for talking me through it all. :)

I can now play around and see what happens. Thank you for taking the time to explain.

matthewg42 10-24-2006 07:52 AM

Good, glad to help.

There are several other programs which can list and send signals to processes, but kill from a terminal is a good approach especially if you need to switch user before using it.

If you use the gnome desktop environment, there is a program called "gnome-system-monitor" which can list processes and you can use it to send TERM and KILL signals etc. In ubuntu, this is available from the administratioon menu, called "System Monitor".

"KDE system guard" has similar facilities for KDE users. On kubuntu, pressing control-escape launches KDE system guard.

Both of these programs have nice GUI interfaces, so if you prefer that sort of thing try them.

The command line discussed here is more consistently available across different unix-like OSes - I can use ps, kill and grep from the terminal on Solaris, HPUX, BSD, Linux, etc (although sometimes the exact usage differs a little between these OSes).

The other advantage is for administering remote machines for which you can't use a GUI for some reason (many servers don't run X, or maybe the connection isn't fast enough to conveniently use a remote X session).


All times are GMT -5. The time now is 09:07 AM.