Linux is a multitasking operating system, which means that the system can run multiple applications simultaneously. Some applications run in the foreground, and some run in the background. A foreground application is active in a desktop window or in a terminal window. A background application is usually an operating system service that the user does not directly start or use. These background applications are known as daemons.
To an operating system, there is no difference between a desktop application, a command, or a service. When you launch a desktop application or run a command, or when the operating system starts a service, Linux starts a process. Each process has an numeric ID, which is called a process ID (PID). When the application, command, or service ends, Linux ends the process.
In the GNOME desktop, you list all active processes by using the System Monitor application. System Monitor displays all processes by name, along with the percentage of CPU activity that the process generates, the amount of RAM the process has reserved, the PID, disk activity, and more.
To see all processes on your system, click the main menu in System Monitor, and select .
The list provides an overview of which processes use more resources than others. Most of the statistics change quickly because few processes are static. If your system suddenly starts running slowly, then use System Monitor to identify the processes that use the most CPU cycles. Increased CPU activity can reveal that the application has crashed or is stuck on something that it cannot resolve. Click any column on the tab to sort the process list by that column's values.
The safe way to stop a desktop application is through its menu system. However, if an application has crashed, then you might not have access to its menu. You can force a process to stop in System Monitor.
First, launch System Monitor. Use the icon in the upper right of the System Monitor window to search for a process by name or PID. Alternatively, sort the process list and review the list until you find the application that you want to stop.
After you locate the process that you want to stop, click the process's row and then click at the bottom left of the System Monitor window. When you are prompted for confirmation, click in the confirmation dialog.
This operation is also known as killing or terminating the process.
To see an overview of your system resources, click the tab in the System Monitor window. The tab displays CPU core usage, RAM availability, and network activity.
What you see here depends upon the activity on your system.
You can generate predictable activity in the panel by using the ping command to send a signal to your own system.
Launch the Terminal application and use the ping command to create traffic to a server on the internet.
Without the -c option to limit how many pings are sent, this command runs until you stop it, so let it run.
[user@host ~]$ ping google.comIn the System Monitor window, the panel displays activity as the ping command runs.
To stop the ping command, press Ctrl+C in the Terminal window.
On the command line, you can list all active processes by using the top command.
[user@host ~]$ topThe top command launches an interactive application that runs in the terminal, so there is no command prompt after starting it.
Instead, the Terminal window displays a list of processes by PID, CPU percentage, RAM usage, name, and other attributes.
top - 22:09:52 up 3:16, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 125 total, 1 running, 124 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
MiB Mem : 1770.8 total, 1232.2 free, 411.8 used, 280.7 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 1359.0 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 106300 15896 10360 S 0.0 0.9 0:01.83 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
5 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns
7 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-events_highpri
9 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
11 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_kthre
12 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_rude
[...]The list updates regularly, depending on how it is sorted.
By default, the process list is sorted by CPU percentage.
To make the sort column bold, press x on your keyboard.
To change the designated sort column, press the less than symbol (<) or the greater than symbol (>) on your keyboard.
Press R to reverse the sort order.
To exit the top command and return to a command prompt, press q.
You can use the top interface to stop a process, but first you must determine the ID for the process that you intend to stop.
In the top interface, press L on your keyboard.
Interactive prompts in the top interface appear above the column labels.
top - 22:09:52 up 3:16, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 125 total, 1 running, 124 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
MiB Mem : 1770.8 total, 1232.2 free, 411.8 used, 280.7 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 1359.0 avail Mem
Locate string
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMANDType the name of the process that you want to stop after the Locate string prompt, and then press Enter.
The top interface is updated to display any matches for your search term.
Review the list of matches for the process that you want to stop, and take note of its PID.
To stop the process, press k on your keyboard.
Enter the PID of the process into the top prompt and then press Enter.
top - 22:35:28 up 3:41, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 223 total, 1 running, 222 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.2 us, 0.1 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 5664.6 total, 4057.0 free, 1167.7 used, 708.0 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 4497.0 avail Mem
PID to signal/kill [default pid = 3601] 3601
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3601 student 20 0 773408 58324 39472 S 0.0 1.0 0:00.40 gedit
3625 root 20 0 0 0 0 I 0.0 0.0 0:00.01 kworker
[...]Press Enter again when the top command prompts you for the signal to send.
You can also use the kill command to terminate a process.
The kill command is not an interactive utility so you must provide the ID of the process to terminate.
In the following example you terminate the process with the ID of 7460.
[user@host ~]$ kill 7460You can retrieve a PID without launching the top command by using the pgrep command.
[user@host ~]$ pgrep gedit
3680You can view processes noninteractively by using the ps command with the -e option to include every running process, and the -f option to mimic the layout of the top interface.
Because there are hundreds of lines of output, you can pipe the output to the less command so that you can scroll through it.
To exit the less command before the end of the list, press q on your keyboard.
[user@host ~]$ ps -ef | less
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 18:53 ? 00:00:01 /usr/lib/systemd/systemd...
root 2 0 0 18:53 ? 00:00:00 [kthreadd]
root 3 2 0 18:53 ? 00:00:00 [rcu_gp]
root 4 2 0 18:53 ? 00:00:00 [rcu_par_gp]
root 5 2 0 18:53 ? 00:00:00 [netns]
root 7 2 0 18:53 ? 00:00:00 [kworker/0:0H-events_highpri]
root 9 2 0 18:53 ? 00:00:00 [mm_percpu_wq]
root 11 2 0 18:53 ? 00:00:00 [rcu_tasks_kthre]
root 12 2 0 18:53 ? 00:00:00 [rcu_tasks_rude_]
root 13 2 0 18:53 ? 00:00:00 [rcu_tasks_trace]
[...]
less(1), pgrep(1), ping(1), ps(1), and top(8) man pages
For more information about monitoring processes, refer to An Introduction to Linux User Account Monitoring at https://learn.spidernet.pl/sysadmin/monitor-users-linux