How To List All Background Processes in Linux
This post will guide you how to find out all background processes in your Linux operating system. How do I show what processes are running in the background using a command on Linux.
- Run A Command in the Background
- List Your Background Processes
- List All Running Processes in the Background
Run A Command in the Background
If you want to run your process or command or a shell script in the background, and you just need to type an ampersand character (&
) at the end of the command or shell script you want to run in your current shell session.
For example, you want to run a ping
command in the background, and you can type:
$ ping 192.168.3.50 &
Outputs:
[devops@mydevops ~]$ ping 192.168.3.50 & [1] 2672
List Your Background Processes
If you want to list your background processes, and you can type the jobs
command, type:
$ jobs
Outputs:
[devops@mydevops ~]$ jobs
[1]+ Running ping 192.168.3.50 &
If you want to bring a background process to the foreground, and you can use the fg
command. type:
$ fg %n $ fg %1
Note: the number n
is the jobs’s number in the background.
If you want to kill a running background process, and you can use the kill
command, type:
% kill %n $ kill %2
Outputs:
[devops@mydevops ~]$ jobs [1]+ Stopped vim /etc/passwd [2]- Running ping 192.168.1.50 > /dev/null & [devops@mydevops ~]$ kill %2 [devops@mydevops ~]$ jobs [1]+ Stopped vim /etc/passwd [2]- Terminated ping 192.168.1.50 > /dev/null
List All Running Processes in the Background
If you want to list all running processes in the background in your Linux system, and you can use ps -aux or top command. type:
$ ps -aux | less
or
$ top
Outputs:
$ ps -aux | less USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 1.0 178980 13784 ? Ss 01:20 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 17 root 2 0.0 0.0 0 0 ? S 01:20 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 01:20 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 01:20 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 01:20 0:00 [kworker/0:0H-kblockd] root 8 0.0 0.0 0 0 ? I< 01:20 0:00 [mm_percpu_wq] root 9 0.0 0.0 0 0 ? S 01:20 0:00 [ksoftirqd/0] root 10 0.0 0.0 0 0 ? I 01:20 0:00 [rcu_sched] root 11 0.0 0.0 0 0 ? S 01:20 0:00 [migration/0] root 12 0.0 0.0 0 0 ? S 01:20 0:00 [watchdog/0] root 13 0.0 0.0 0 0 ? S 01:20 0:00 [cpuhp/0] root 15 0.0 0.0 0 0 ? S 01:20 0:00 [kdevtmpfs] root 16 0.0 0.0 0 0 ? I< 01:20 0:00 [netns] root 17 0.0 0.0 0 0 ? S 01:20 0:00 [kauditd] $ top top - 02:09:33 up 48 min, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 160 total, 2 running, 157 sleeping, 1 stopped, 0 zombie %Cpu(s): 5.6 us, 11.1 sy, 0.0 ni, 83.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 1326.2 total, 393.1 free, 484.0 used, 449.1 buff/cache MiB Swap: 3228.0 total, 3228.0 free, 0.0 used. 688.2 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2749 devops 20 0 63884 4360 3724 R 12.5 0.3 0:00.02 top 1 root 20 0 178980 13784 8972 S 0.0 1.0 0:01.75 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 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 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kblockd
Conclusion
You should know that how to find out what processes are running in the background using bg/fg/kill commands in your Linux system.