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?
|
ctrl+c will break out of a program normally. if not, suspend it with z and kill it kill "kill" simple as that...
|
so the syntax for "kill" would just be "kill [pid number]" like kill 123 or something like that?
|
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" |
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. |
killall -9 [program name]
= kill -9 [pid] |
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 |
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 Code:
kill %jobnumber |
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. |
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.
|
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. |
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 |
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 |
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. |
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 11:02 AM. |