Linux and Command-Line Basics
When stopping a process that has stopped responding, it is recommended to first use "kill <process ID>" and to use "kill -9 <process ID>" only if that does not end it. Which of the following is the reason?
- AThe default SIGTERM (number 15) can be received by the process so that it can clean up before exiting, whereas SIGKILL (number 9) cannot be received and ends it forcibly without cleanup
- BSIGTERM (number 15), which kill sends by default, ends everything including child processes, whereas SIGKILL (number 9) ends only the specified process and so has less impact
- CSIGKILL (number 9) can be received by the process so that it can clean up before exiting, whereas SIGTERM (number 15), which kill sends by default, cannot be ignored and ends it at once
Show answer and explanation
Answer: A. The default SIGTERM (number 15) can be received by the process so that it can clean up before exiting, whereas SIGKILL (number 9) cannot be received and ends it forcibly without cleanup
A signal is a short notification by which the OS tells a process about an event, and each has a fixed number and name. Without options, kill sends SIGTERM (number 15); a program can provide a routine (handler) that receives it, saving files in progress or deleting temporary files before exiting. SIGKILL (number 9) can be neither received nor ignored by the process, and the kernel ends it forcibly, so half-written files may be left corrupted. The ID of the process to stop is found with ps or top.
- A. Correct. SIGTERM gives a chance to clean up, while SIGKILL ends the process forcibly.
- B. Both signals are sent to the specified process. Whether child processes also end is not decided by the type of signal.
- C. The behavior of SIGTERM and SIGKILL is reversed. The one that can be received for cleanup is SIGTERM.