Skip to content

Linux Process Management Commands

Overview

Linux provides several commands for managing processes, which include starting, stopping, and monitoring processes. These commands are essential for controlling and managing the execution of programs and tasks on a Linux system. This document covers basic and commonly used process management commands.

Display Processes

ps

Displays information about active processes.

ps

Example

ps
# Output: Lists processes running in the current shell

ps aux

Displays a detailed list of all running processes, including those from other users.

ps aux

Example

ps aux
# Output: Detailed list of all running processes

top

Displays a dynamic, real-time view of system processes.

top

Example

top
# Output: Real-time display of active processes and system resource usage
# Use 'q' to quit

htop

An interactive process viewer similar to top, but with a more user-friendly interface.

htop

Example

htop
# Output: Interactive display of processes with user-friendly interface
# Use 'q' to quit

pgrep

Searches for processes by name or other attributes.

pgrep <name>

Example

pgrep ssh
# Output: Lists process IDs of processes matching 'ssh'

Manage Processes

kill

Sends a signal to a process, commonly used to terminate it.

kill <PID>

Example

kill 1234
# Sends the default SIGTERM signal to the process with PID 1234

kill -9

Forcibly terminates a process.

kill -9 <PID>

Example

kill -9 1234
# Sends the SIGKILL signal to the process with PID 1234, forcibly terminating it

pkill

Sends a signal to processes by name.

pkill <name>

Example

pkill firefox
# Sends the default SIGTERM signal to all processes named 'firefox'

killall

Sends a signal to all processes with a specific name.

killall <name>

Example

killall firefox
# Sends the default SIGTERM signal to all processes named 'firefox'

Process Prioritization

nice

Runs a command with a specified priority level.

nice -n <priority> <command>

Example

nice -n 10 gzip largefile.txt
# Runs 'gzip largefile.txt' with a priority level of 10

renice

Changes the priority of a running process.

renice <priority> -p <PID>

Example

renice 5 -p 1234
# Changes the priority of the process with PID 1234 to 5

Background and Foreground Jobs

&

Runs a command in the background.

command &

Example

sleep 60 &
# Runs the 'sleep 60' command in the background

jobs

Lists all background jobs.

jobs

Example

jobs
# Output: Lists background jobs and their job numbers

fg

Brings a background job to the foreground.

fg %<job_number>

Example

fg %1
# Brings the background job with job number 1 to the foreground

bg

Resumes a suspended job in the background.

bg %<job_number>

Example

bg %1
# Resumes the suspended job with job number 1 in the background

Summary

Linux offers a variety of commands for managing processes, from displaying and monitoring to controlling and prioritizing. Understanding these commands helps effectively manage and troubleshoot processes on a Linux system. For more detailed information on each command, refer to the Linux manual pages.