Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Knoppix to play, Slack current, OpenBSD stables
Posts: 111
Rep:
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?
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.
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
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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
Distribution: Knoppix to play, Slack current, OpenBSD stables
Posts: 111
Original Poster
Rep:
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.
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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.
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!"
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.