Master Linux Process Termination: kill, killall, and pkill Explained
This guide shows how to identify a Linux process’s PID and safely terminate it using kill, killall, or pkill, covering signal options, common signals like SIGTERM and SIGKILL, and practical command examples for both foreground and background processes.
Linux Process Termination Signals
When a process is stopped by the operating system or a user, a termination signal is sent. Common signals include SIGTERM (15) for graceful shutdown and SIGKILL (9) for forced termination.
Getting a Process PID
To kill a process you need its PID. You can retrieve it by name using: pidof exact_process_name For example, to find the PID of a Java process: pidof java Output may show multiple PIDs, e.g., 8075 1032.
Using the kill Command
The kill command requires the PID and optionally a signal: kill [signal] <PID> If no signal is specified, kill defaults to SIGTERM (15). Example of killing a background sleep job:
$ sleep 120 &
[1] 125686
$ kill 125686
[1]+ terminated sleep 120You can also specify the signal by name or number:
$ kill -SIGKILL 125746
$ kill -9 125759Using the killall Command
If you don’t know the PID or want to terminate a process and all its children, use killall: killall [signal] <process-name> Without a signal, killall sends SIGTERM (15). Example killing all sleep processes:
$ sleep 120 &
[1] 112351
$ sleep 2000 &
[2] 112362
$ killall sleep
[1]- Terminated sleep 120
[2]+ Terminated sleep 2000Using the pkill Command
pkillcombines pgrep pattern matching with kill: pkill [options] pattern Useful options include: -u: match processes owned by a specific user -x: exact match of the process name -signal: specify termination signal (default SIGTERM)
Example terminating all nginx processes: pkill nginx These commands provide flexible ways to manage and terminate Linux processes safely and efficiently.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
