LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions
User Name
Password
Linux - Distributions This forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on... Note: An (*) indicates there is no official participation from that distribution here at LQ.

Notices


Reply
  Search this Thread
Old 12-13-2007, 04:24 AM   #1
nthillaiarasu
Member
 
Registered: Nov 2007
Posts: 39

Rep: Reputation: 15
Killing a process in linux/Unix


Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.

Before I used to kill process in linux by finding the process Id.
For Ex: if i want to kill the process apache then i have to search the process first
(i.e) ps -ef|grep apache
Then i will display in the terminal like this


root 7302 1 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7303 7302 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7304 7302 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7306 7302 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7307 7302 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7308 7302 0 15:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
nobody 7337 7302 0 15:01 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
root 9219 5954 0 15:34 pts/0 00:00:00 grep apache

Then we have to use kill -9 pid every time.I thing its waste of time
For that better we can group all the PID and we can go for kill
So i have started using the command
ps -ef| awk /apache/'{print $2}'
Now it will group all the processID like this


7302
7303
7304
7306
7307
7308
7337
9314

Now we can use kill command finally by passing the output of the above command
kill -9 `ps -ef| awk /apache/'{print $2}'`
I will display in the terminal like this "bash: kill: (9382) - No such process"
(since command itself searching for apache so that PID only 9382 so its displaying no such process)


Alternative Way I

Another way to kill the process in a single shot is by using the command pidof


pidof command is usefull to find the process ID of a running program.

Now you want to kill apache then type
pidof apache
7302 7303 7304 7306 7307 7308 7337 9219
Now we can use kill -9 `pidof apache` to kill the process

Alternative Way II

killall -9 apache

Last edited by nthillaiarasu; 12-13-2007 at 04:52 AM.
 
Old 12-13-2007, 04:45 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Or just
Code:
killall -9 apache
That kills all 'apache' named processes. Handy sometimes. By the way, using switch -9 isn't needed all the time, and I consider it an ugly way to end a process
 
Old 12-13-2007, 04:53 AM   #3
nthillaiarasu
Member
 
Registered: Nov 2007
Posts: 39

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by b0uncer View Post
Or just
Code:
killall -9 apache
That kills all 'apache' named processes. Handy sometimes. By the way, using switch -9 isn't needed all the time, and I consider it an ugly way to end a process
Thank for ur suggestions
 
  


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
killing the process in Linux nthillaiarasu Programming 8 12-11-2007 12:58 AM
Problems killing process Artik Debian 6 05-03-2005 10:29 AM
Killing a process by its name rabeea Linux - Networking 3 03-17-2005 05:30 AM
Killing Process probs collen Linux - General 4 09-16-2003 09:18 AM
Really Killing a Process! lazlow69 Linux - Newbie 14 05-10-2003 10:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions

All times are GMT -5. The time now is 03:52 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