Question

what is difference in operation using kill command format, in what scenario which one to used.

kill -9 process-id
kill SIGUSR2 process-id
Was it helpful?

Solution

If you want to send SIGUSR2 to a process, you would use either:

kill -SIGUSR2 $pid
kill -USR2 $pid
kill -10 $pid   # This will vary with platform

If you want to send SIGKILL to a process, you would use either:

kill -SIGKILL $pid
kill -KILL $pid
kill -9 $pid

Not sure how to answer your question about "which scenario". If you want to send USR2, then you use one of the former 3 commands. If you want to send KILL, you use one of the latter. You typically want to avoid using KILL, as a process that receives a KILL cannot clean up after itself. On the other hand, a lot of software is written poorly and can only be terminated via SIGKILL. It is usually considered more polite to send TERM, then wait some period of time before sending TERM a second time, then wait again before sending KILL. USR2 is typically only useful for programs that are expecting it and will respond in some useful way. If the program is not expecting the signal and no action has been taken to ignore it, the default behavior is to terminate.

Note that the specific signal number of SIGUSR2 varies. Depending on the platform, it may be 10, 12, 31, and probably many other values. It is best to avoid setting the value explicitly. The only signal numbers which are standardized are 1,2,3,6,9,14, and 15, so 9 is always SIGKILL, but SIGUSR2 may (and does!) vary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top