Linux process control Which command is used to terminate (send a signal to) a running process by Process ID (PID) or by name?

Difficulty: Easy

Correct Answer: kill

Explanation:


Introduction / Context:
Process management is a core skill in Linux administration. Sometimes a process misbehaves or must be stopped for maintenance. Linux uses signals to control processes, and the standard command to send these signals is kill (and its variants). Understanding how and when to use kill is essential for safe system operation.


Given Data / Assumptions:

  • You have a target process identified by PID or name.
  • You need to terminate, interrupt, or otherwise signal that process.
  • Standard userland tools are available.


Concept / Approach:
The kill command sends a signal to a process. By default it sends SIGTERM (15), requesting graceful termination. If the process does not exit, SIGKILL (9) can be used to force termination. Utilities like killall or pkill target processes by name, but they are wrappers around the same signaling mechanism.


Step-by-Step Solution:
Find the PID via ps, pgrep, or top.Attempt graceful stop: kill (SIGTERM).If needed, force stop: kill -9 (SIGKILL).For name-based: pkill or killall (distribution dependent).


Verification / Alternative check:
Confirm with ps or pgrep that the process has exited. Review logs if a service manager (systemd) restarts it automatically; in that case, use systemctl stop for managed services.


Why Other Options Are Wrong:
cancel: not a standard Linux process signaling command.haltsys and shutdown: control system power state, not individual processes.


Common Pitfalls:

  • Using SIGKILL prematurely, which prevents cleanup handlers from running.
  • Forgetting that services supervised by systemd may respawn after kill.
  • Signaling the wrong PID; always double-check with ps/top.


Final Answer:
kill

More Questions from Linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion