Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am getting a lot of mixed messages from people, and was wondering if it there really is not much of a difference in what you use.

kill 'x'
killall 'x'
kill -9 'x'

These are some options I've been told to use so far, but some people say that kill -9 is just overkill, kill by itself doesn't work, etc.

Does anyone have any advice on which one should be used in the most standard case of just terminating a process (and thus its state as well)?

[edit] I am looking for what to use when you want to stop the execution of your process so that you can run a new one, fresh from the start

share|improve this question
1  
See also UUK9 form letter which cautions against abusing SIGKILL. –  jw013 Jan 8 '12 at 0:18
1  
To list the all the different signals, along with their number: kill -l and to translate a number to its corresponding signal name e.g. kill -l 9 will return KILL. –  Herman Torjussen Jan 8 '12 at 1:28

2 Answers 2

There are a number of signals whose default disposition is to terminate the process. The ultimate termination signal is SIGKILL since it cannot be handled and the process has no choice but to die. This however also means that if you send it, the process is deprived of an opportunity to clean up. Therefore, good manners require to send a signal like SIGTERM that can be handled first and only if the process does not exit after some time send it SIGKILL.

Note that SIGINT and SIGQUIT are not good candidates for arbitrary process termination. Due to the fact that they can be generated from terminal's keyboard, many applications use them for special purposes. For example, python interpreter uses SIGINT to generate KeyboardInterrupt exception (also in interactive python sessions where it simply returns to the prompt) and JVM uses SIGQUIT to dump stack traces. SIGINT and SIGQUIT do remain effective for most standard command-line utilities like find or cat.

During system shutdown, most UNIX and Linux systems send SIGTERM to all process, followed by 5 seconds wait, followed by SIGKILL. This is the recommended way to safely shut down an arbitrary process.

Note also that even SIGKILL may not terminate a process stuck in an uninterruptible wait until the process wakes up.

share|improve this answer
1  
Excellent answer. Do you have a reference for the kill -SIGTERM $pid; sleep 5; kill -SIGKILL $pid; recommendation? –  l0b0 Jan 9 '12 at 16:20
    
+1 kind of answer. And what about SIGHUP? –  Alois Mahdal May 13 '12 at 22:02
1  
@AloisMahdal: SIGHUP comes from the day when dial-up lines were common. That signal was sent to indicate that the line hung-up. Later, when that was less common SIGHUP was sometimes used by daemons to re-read the config file without restarting the process. In these modern times SIGHUP is rarely used. Many daemons will have their own way of reinitializing (i.e., apachectl graceful or rndc reconfig. For things that don't you should use [init.d|smf|upstart|launchd] controls where possible. –  bahamat Jun 27 '12 at 18:54

You should start with the gentlest one and escalate from there. This means, SIGINT, SIGTERM, SIGQUIT, SIGKILL. Although most people skip SIGINT and SIGQUIT.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.