-   Linux - Newbie (
-   -   Really Killing a Process! (

lazlow69 02-27-2003 05:04 PM

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?

acid_kewpie 02-27-2003 05:06 PM

ctrl+c will break out of a program normally. if not, suspend it with z and kill it kill "kill" simple as that...

lazlow69 02-27-2003 07:30 PM

so the syntax for "kill" would just be "kill [pid number]" like kill 123 or something like that?

pilot1 02-27-2003 07:46 PM

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"

Texicle 02-27-2003 08:59 PM

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.

doublefailure 02-28-2003 02:07 AM

killall -9 [program name]
= kill -9 [pid]

mhearn 02-28-2003 04:33 AM

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

moses 02-28-2003 10:08 AM

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

You can then kill the offending program with:

kill %jobnumber

lazlow69 02-28-2003 10:51 AM

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.

acid_kewpie 02-28-2003 10:54 AM

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.

moses 02-28-2003 03:40 PM

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.

doublefailure 03-05-2003 02:20 PM

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

MasterC 03-05-2003 02:30 PM

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!" ;)


moses 03-05-2003 09:49 PM

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.

sangram_t 05-10-2003 10:31 PM

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.

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