LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2006, 07:20 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Rep: Reputation: 15
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 ?
 
Old 10-18-2006, 07:25 AM   #2
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
i have seen -15 is an additional parameter to be used in my manual given to me.

i dont know what it does.
 
Old 10-18-2006, 08:14 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 10-18-2006, 08:25 AM   #4
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15
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.
 
Old 10-18-2006, 08:53 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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
 
Old 10-18-2006, 01:31 PM   #6
usaf_sp
Member
 
Registered: Jul 2005
Location: Tennessee
Distribution: openSUSE
Posts: 419

Rep: Reputation: 30
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.
 
Old 10-19-2006, 02:36 AM   #7
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
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;
 
Old 10-19-2006, 05:00 AM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
See also killall
 
Old 10-19-2006, 10:05 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 10-24-2006, 06:06 AM   #10
Adrian Baker
Member
 
Registered: Apr 2004
Distribution: PCLinuxOS 2007 on my laptop and Suse 10.2 on my desktop.
Posts: 341

Rep: Reputation: 30
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
 
Old 10-24-2006, 06:48 AM   #11
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 10-24-2006, 07:01 AM   #12
Adrian Baker
Member
 
Registered: Apr 2004
Distribution: PCLinuxOS 2007 on my laptop and Suse 10.2 on my desktop.
Posts: 341

Rep: Reputation: 30
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.
 
Old 10-24-2006, 07:52 AM   #13
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What if 'kill -9' fails to kill a task? chii-chan Linux - Newbie 15 03-27-2013 03:47 PM
how to use kill to kill a batch of processes with same name? dr_zayus69 Linux - Software 2 09-03-2005 06:35 PM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
kill X = kill computer! jd243 Slackware 3 07-01-2003 11:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration