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 02-27-2003, 05:04 PM   #1
lazlow69
Member
 
Registered: Jan 2003
Location: Central New Jersey
Distribution: Knoppix to play, Slack current, OpenBSD stables
Posts: 111

Rep: Reputation: 15
Question Really Killing a Process!


I know I can stop a process by hitting ctrl-z, but when I type "ps" to see what forks are still alive, the process is still in the threads. How do I quit a program, kill the thread, stop the process completely, instead of just stopping it temporarily as ctrl-z seems to do?
 
Old 02-27-2003, 05:06 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
ctrl+c will break out of a program normally. if not, suspend it with z and kill it kill "kill" simple as that...
 
Old 02-27-2003, 07:30 PM   #3
lazlow69
Member
 
Registered: Jan 2003
Location: Central New Jersey
Distribution: Knoppix to play, Slack current, OpenBSD stables
Posts: 111

Original Poster
Rep: Reputation: 15
so the syntax for "kill" would just be "kill [pid number]" like kill 123 or something like that?
 
Old 02-27-2003, 07:46 PM   #4
pilot1
Member
 
Registered: Jun 2002
Location: USA
Distribution: Gentoo, Fedora Core
Posts: 408

Rep: Reputation: 30
Right, for example if the pid was 123 it would be "kill 123".
If you need to know how to get the pid you can always do a
"ps -aux | grep proccessname"
 
Old 02-27-2003, 08:59 PM   #5
Texicle
Member
 
Registered: Oct 2002
Location: Northern Ontario, Canada
Distribution: Slackware 10.0
Posts: 789

Rep: Reputation: 30
You could also type:

ps -a to get a list of all the current processes and their PIDs.

Then, you can do a kill <pid> (<pid> is the pid without the <>'s). Additionally there's kill -9 <pid> for those processes that just won't die with a regular kill command.
 
Old 02-28-2003, 02:07 AM   #6
doublefailure
Member
 
Registered: Mar 2002
Location: ma
Distribution: slackware
Posts: 747

Rep: Reputation: 30
killall -9 [program name]
= kill -9 [pid]
 
Old 02-28-2003, 04:33 AM   #7
mhearn
LQ Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
kill -9 `pidof foobar`

useful

Another quick tip, if you start a program from a term and wish you'd stuck & on the end to put it into the background, just do ctrl-z to suspend it, then "bg" will refork it into the background
 
Old 02-28-2003, 10:08 AM   #8
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Also, if you start a program from command line and either use
the background (&) at runtime or suspend and then background it,
it'll receive a "job number", which you can view with the command
Code:
jobs
You can then kill the offending program with:
Code:
kill %jobnumber
 
Old 02-28-2003, 10:51 AM   #9
lazlow69
Member
 
Registered: Jan 2003
Location: Central New Jersey
Distribution: Knoppix to play, Slack current, OpenBSD stables
Posts: 111

Original Poster
Rep: Reputation: 15
I assume (and hope) that killing processes is not a dangerous or bad habit. I know that within windows, stopping threads works alright once you are at the NT level, but it still is definitely not the best way to go about things.

Linux, I'm sure, is a lot more solid in this regard, but I would still be interested to know if killing processes on a regular basis is a very bad habit.
 
Old 02-28-2003, 10:54 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it will naturally depend how each individual program is written, and how well it will respond to having the carpet whipped out fromunder it, but genreally it's absolutely fine.
 
Old 02-28-2003, 03:40 PM   #11
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Typically, you want to avoid the use of the "kill -9" command, as that tells
the kernel to disconnect the process. This is bad because a program cannot
catch the "KILL" signal, and thus cannot clean up after themselves as they
can with other signals.
 
Old 03-05-2003, 02:20 PM   #12
doublefailure
Member
 
Registered: Mar 2002
Location: ma
Distribution: slackware
Posts: 747

Rep: Reputation: 30
moses thanks for the info..

by the way, some apache readme suggests to kill server by 'kill -9'
(the one i have(1.2.26 slackware package))

what do u think about this?

thank you
 
Old 03-05-2003, 02:30 PM   #13
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
Ok, I'm by far no Moses, but here's my guess:

If you are killing something like Apache, you normally aren't killing it for fun. I'd say it's gonna be for intrusion, disconnecting yourself from the net, or something drastic. So, instead of saying "At your convenience, stop and disconnect" you say "Drop it and run!"

Cool
 
Old 03-05-2003, 09:49 PM   #14
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
I don't know why Apache would recommend kill -9, it could easily
be a matter of misunderstanding by the documentation writer, a
simple mistake, or for a good reason (I can't really think of a
good reason to recommend such a course of action). As long as
apache doesn't litter as it starts up, there probably isn't a real
problem with kill -9.

I find it very unlikely that apache doesn't create files (lock, or
other) as it starts up, so I would recommend against kill -9.

IMHO, if Apache is recommending that you kill their program with
a KILL signal, they need to rewrite their signal catching code to
catch the correct signals and exit cleanly.
 
Old 05-10-2003, 10:31 PM   #15
sangram_t
LQ Newbie
 
Registered: May 2003
Posts: 1

Rep: Reputation: 0
killing kernel threads from used space

I agree about using Cntl Z and then "kill -9" on the process to kill the process and all it children.

However, I have a different situation here.
I have a user process that make a system call and within the kernel forks multiple kernel threads.
Is there any way in which I could kill these threads from the user space.

assistance in this respect would be appreciated.
 
  


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 a process fails. Have tried all I know. Racy Linux - Software 6 09-18-2005 12:57 PM
Process killing script owix Linux - General 2 07-19-2005 11:08 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 child process coolfrog Programming 3 09-28-2004 02:58 PM

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

All times are GMT -5. The time now is 11:07 PM.

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