Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
Process management is a critical aspect of working with Linux systems. This tutorial will introduce you to the basic concepts and commands associated with managing processes in Linux.
A process is an instance of a running program in a Linux system. Each process is assigned a unique Process ID (PID), which is used to track and manage the process during its lifetime.
To list all running processes, use the ps
command:
ps aux
a
lists processes from all usersu
provides a user-oriented formatx
includes processes without a controlling terminalAnother command for listing processes is top
. It provides a real-time, dynamic view of running processes and their resource usage:
top
To exit top
, press q
.
You can terminate processes using the kill
command followed by the signal and the PID:
kill -signal PID
Common signals used with kill
are:
SIGTERM (15)
: Asks the process to terminate gracefully, allowing cleanup and data saving.SIGKILL (9)
: Forces the process to terminate immediately without cleanup. Use this as a last resort.For example, to gracefully terminate a process with the PID 12345, use:
kill -15 12345
Alternatively, you can use the pkill
command to terminate processes based on their name:
pkill -signal process_name
You can pause a process by sending the SIGSTOP
signal, and resume it with the SIGCONT
signal. For example, to pause a process with PID 12345, use:
kill -SIGSTOP 12345
To resume the same process, use:
kill -SIGCONT 12345
Linux processes have a priority value called "niceness," which ranges from -20 (highest priority) to 19 (lowest priority). You can adjust a process's priority using the renice
command:
renice new_priority -p PID
For example, to change the priority of a process with PID 12345 to 5, use:
renice 5 -p 12345
To monitor the resource usage of specific processes, you can use the htop
command. htop
is an enhanced version of top
with additional features and an improved interface. To install htop
, use:
sudo apt install htop # Debian/Ubuntu-based distributions sudo yum install htop # CentOS/RHEL-based distributions sudo dnf install htop # Fedora-based distributions
To run htop
, simply type:
htop
To exit htop
, press q
.
In conclusion, understanding how to manage processes in Linux is crucial for effectively administering a system. By learning the basic concepts and commands for process management, you can ensure that your system runs smoothly and efficiently.
List running processes in Linux command line:
Use the ps
command to list running processes:
ps aux
Killing processes in Linux:
Terminate a process using the kill
command. For example, to kill a process with PID 1234:
kill 1234
To forcefully terminate a process:
kill -9 1234
Process priorities and scheduling in Linux:
Adjust process priority using the nice
command. For example, to start a process with lower priority:
nice -n 10 command
Monitoring system processes in Linux:
Use tools like top
or htop
for real-time monitoring of system processes. Install and run htop
:
sudo apt-get update sudo apt-get install htop htop
Foreground and background processes in Linux:
To run a process in the background, append &
to the command:
command &
To move a process to the background after it has started, press Ctrl + Z
to pause, then use the bg
command:
bg
Linux ps
command for process information:
The ps
command provides detailed information about processes. For example, to display information about all processes:
ps aux
Managing process resources in Linux:
Use tools like nice
, ionice
, and renice
to manage process resources. For instance, to set the I/O priority of a process:
ionice -c 2 -n 0 -p 1234