Operations 5 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux Process Termination: kill, killall, and pkill Explained

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 120

You can also specify the signal by name or number:

$ kill -SIGKILL 125746
$ kill -9 125759

Using 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 2000

Using the pkill Command

pkill

combines 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.

Signal table
Signal table
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

process managementLinuxKill Commandsignalskillallpkill
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.