Red Hat Certified System Administrator RHCSA · Free Practice Question Easy
Question 16
Which of the following commands kills the process with the PID 112 but allows the process to "clean up" before exiting?
-
A
kill -KILL 112
-
B
kill -PIPE 112
-
C
kill -STOP 112
-
D
kill -TERM 112
Reveal correct answer
Correct answer: D
Explanation
The correct command is:
- kill -TERM 112
Explanation:
The command kill -TERM 112 sends a termination signal (SIGTERM) to the process with the Process ID (PID) 112. This signal requests the process to terminate gracefully, allowing it to carry out any necessary cleanup operations, such as saving data or closing open resources, before it exits.
Signal Type (
-TERM):SIGTERM (signal number 15) is a soft termination signal that tells a process to end but gives it the chance to do so cleanly. Processes that handle SIGTERM can perform final actions like saving state or closing files before actually terminating.
Alternative Signal -
-KILL:If the process does not respond to SIGTERM, you can use the stronger
kill -KILL 112(orkill -9 112). This sends a SIGKILL (signal number 9), which forcefully stops the process without allowing any cleanup. SIGKILL is only used when a process becomes unresponsive to SIGTERM.
Why SIGTERM First?:
Using
kill -TERMis a best practice as it gives the process a chance to end in a controlled manner, reducing the risk of data corruption or partial writes. Usingkill -KILLor other more forceful signals should only be a last resort if the process ignores SIGTERM or becomes unresponsive.
Other Options (
-PIPEand-STOP):kill -PIPE: There is no-PIPEoption for thekillcommand; this would be an invalid option.kill -STOP: This command pauses the process but does not terminate it, so it does not fulfill the requirement of ending the process. SIGSTOP is useful for temporarily suspending a process to resume later with SIGCONT.
Summary:
For a controlled termination that allows the process to clean up, kill -TERM is the appropriate command. Using a hard kill, such as kill -KILL, bypasses cleanup and should only be used if termination with kill -TERM fails.
Example Usage:
- # Gracefully terminate process 112
- kill -TERM 112
This command prompts the process to shut down in an orderly fashion, reducing the chance of data loss or incomplete tasks.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
