In this guide, we try to cover most part of processes and understand how to manage them on your Linux system. So when we execute a program it represents one or more processes, in order to make our system operations smooth, the management and control of processes is essential. Usually, processes on the Linux system will execute, live, and get killed without intervention from the user because kernel manage them automatically. However, there can be some cases when a process is executed and after sometime the process can die for some unknown reason and it needs a restart to get the work done. Or a process may run fiercely and consume lots of system resources, in such case requiring a termination. We may need a instruct running process to perform certain operation, such as rereading a configuration file.

How a process works: When Linux system boots up, the kernel executes some of its own processes, basically, runs series of shell scripts to make system ready to use. Many of these processes are implemented as daemon processes, processes that just sit in the background and perform their task without having any interaction with user. So even you are just boot up the system and don't log-in, the system is little busy performing routine jobs.

The kernel of the system maintains information of each process executed to keep system well organized. For instance, when a process is executed a number called PID (process ID) assigned to it. PID (process ID) are always assigned in ascending order. The kernel also helps keep track of system memory assigned to each process, as well as those processes' ready to resume their execution.

Lets follow the guide, how to manage processes on your system:

Viewing Processes with "PS"

PS - this command can be used to get the information about running processes. There are almost 80 options available for ps command, we will cover some combinations of them.
Run this command in your system to display the processes information:
ps

To view processes by the your logged-in user:
ps -ux

View processes by user 'noobslab':
ps -U noobslab

View processes by program name:
ps -C gnome

View particular process by PID:
ps -p1,2,18076

View more refined output of ps using grep:
ps -ux | grep gnome
ps aux | grep gnome
ps auxw | grep gnome

It shows every running process with details:
ps aux

Displays all processes in a threaded view, with parent/child process hierarchy and session IDs:
ps -ejH

View processes hierarchy in BSD-style:
ps axjf

If you want to dive more into PS command then check manual using this command:
man ps

Viewing Processes with "PSTREE"

PSTREE - It is used to display the hierarchical list of processes in tree format. It is very useful for understanding the parent/child processes relationship.
Run this command in your system to display the processes in tree format:
pstree

Display processes tree including PID:
pstree -p

for more options check manual:
man pstree


Viewing Processes with "TOP"

TOP - This command is similar to ps but it displays continuous updated results. It is very useful when you need to keep an eye on one or more processes to check how they are performing and consuming resources. In addition, it displays CPU-intensive process at the top (displaying processes using CPU from higher to lower). Further more, we can use this command with other options to get expected results.
You can run this command in your system to get processes information:
top

Display processes with delay of 1 second (default 3 seconds):
top -d 1

Display processes of a user:
top -u noobslab

Display processes using PID:
top -p 1,2,18076,18092

It runs 'top' command for sometime and log output in the file:
top -b -n 1000 > processes_log.txt

To know more options for TOP run this command:
man top


Viewing Processes with "PGREP"

PGREP - It lets you look up the process and get the information about the process
Run this command to display the process information:
pgrep -l gnome

Run this command to list all processes by user:
pgrep -lu noobslab

You can get more information using this command:
man pgrep

Beside these popular command utilities, do you use anything else? Let everybody know in the comment below!
Share To:
...