- 25 ps command examples in Linux [Cheat Sheet]
- ps command syntax
- Different examples to use ps command
- 1. ps command to list all processes in the current shell
- 2. ps command to list all processes
- 3. ps command to list all processes with a terminal
- 4. ps command to list processes not associated with a terminal
- 5. ps command to list all processes owned by the current user
- 6. List all processes in BSD format
- 7. List processes with full-format
- 8. Display user-oriented format
- 9. Display virtual memory format
- 10. Display processes by effective User ID or Name
- 11. Display processes by the real user ID or Name
- 12. Display processes by real group ID or name
- 13. Display processes by effective group ID or name
- 14. List processes by process ID
- 15. Display specific process by using the parent process ID
- 16. List processes by terminal type
- 17. ps command to show environment after command
- 18. Hide the header of ps command output
- 19. Repeat the header lines of ps command output
- 20. ps command to display a process tree
- 21. ps command to show threads as if they were processes
- 22. Show threads with LWP and NLWP columns
- 23. Show format specifiers with ps command
- 24. Display signal format with ps command
- 25. ps command to display security info
- Conclusion
- What’s Next
- Further Reading
25 ps command examples in Linux [Cheat Sheet]
In Linux, a process is any executing (running) instance of a program. Whenever you run a program, it creates a new process. Linux is a multi-tasking and multi-user operating system that allows running several programs simultaneously. So, there are multiple Linux processes running at the same time. There are different tools to view and track processes in the Linux system. This article will introduce the ps command in Linux which displays a list of currently running processes and their PIDs. ps is the short form for Process Status.
ps command syntax
The syntax for ps command is:
Some options available in ps command are as follows:
- -A: List all processes on the system
- -e: List all processes on the system
- x: List processes owned by the current user
- -f: List processes with full format
- u: Display user-oriented format
Different examples to use ps command
1. ps command to list all processes in the current shell
When ps command is used without any options or arguments, it displays a list of running processes in the current shell.
Sample Output:
It displays the following information in the output.
- PID: It shows the unique process ID.
- TTY: It shows the terminal type into which the user is logged in.
- TIME: It displays the total time that the process has been running.
- CMD: It displays the name of the command that launches the process. As we can notice in the output, the second process is started by the ps command itself.
2. ps command to list all processes
You can use -A or -e option to list all running processes in the Linux system.
Sample Output:
3. ps command to list all processes with a terminal
The a option causes ps to list all processes associated with a terminal (TTY).
Sample Output:
The T option allows you to select all processes associated with this terminal only.
golinux@ubuntu-PC:~$ ps T PID TTY STAT TIME COMMAND 1925 pts/1 Ss 0:00 bash 2200 pts/1 R+ 0:00 ps T
4. ps command to list processes not associated with a terminal
The -a option shows all processes except both session leaders processes not associated with a terminal.
Sample Output:
Every process group is in a unique session. (When the process is created, it becomes a member of the session of its parent.) By convention, the session ID of a session equals the process ID of the first member of the session, called the session leader. A process finds the ID of its session using the system call getsid() .
5. ps command to list all processes owned by the current user
The x option causes ps to list all processes owned by the current user.
Sample Output:
Here, ps shows all processes owned by the user golinux.
6. List all processes in BSD format
You can combine a option with x option to list all running processes in BSD format.
Sample Output:
7. List processes with full-format
The -f option displays full format and the -F option displays extra full format.
Sample Output:
8. Display user-oriented format
The u option enables the user-oriented format and shows the information of the user who owns the processes.
Sample Output:
9. Display virtual memory format
The v option allows you to display the processes in the virtual memory format.
Sample Output:
%MEM shows the amount of memory the process is taking up.
10. Display processes by effective User ID or Name
The U , -u , or —user options display processes of the specified effective user name or ID.
Sample Output:
11. Display processes by the real user ID or Name
The -U or —User option selects the processes by the specified real user name or ID.
Sample Output:
12. Display processes by real group ID or name
You can list processes that belong to the specified group (real group ID or name) using -G or —Group option.
Sample Output:
13. Display processes by effective group ID or name
Similarly, you can use -g or —group option to list the processes owned by the specified effective group ID or name. The group ID will only work with -g when some group names are also specified. Otherwise, it lists the processes by session ID when only numeric IDs are specified.
ps --group group_id,group_name
14. List processes by process ID
The p , -p , or —pid option allows you to list specific processes using the process ID.
Sample Output:
golinux@ubuntu-PC:~$ ps -p 2867 PID TTY TIME CMD 2867 pts/1 00:00:00 su
You can also specify multiple process IDs.
golinux@ubuntu-PC:~$ ps -p 1320,1322,1325 PID TTY TIME CMD 1320 ? 00:00:00 gsd-rfkill 1322 ? 00:00:00 evolution-alarm 1325 ? 00:00:00 gsd-screensaver
15. Display specific process by using the parent process ID
The —ppid option allows you to list specific processes by parent process ID.
$ ps --ppid parent_process_ID
Sample Output:
16. List processes by terminal type
The t , -t , or —tty option helps to display processes having specific terminal types.
Sample Output:
17. ps command to show environment after command
The e option causes ps to show the environment after commands in the output. e and -e options are not the same. The -e option helps to display all processes.
Sample Output:
golinux@ubuntu-PC:~$ ps e PID TTY STAT TIME COMMAND 886 tty2 Ssl+ 0:00 /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --systemd --session=ubuntu XDG_SEAT=seat0 LOGNAME=golinux USER=golinux USE 891 tty2 Sl+ 0:56 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3 USER=golinux LC_TIME=en_GB.UTF-8 LANGUAGE=en_GB:en XDG_S 972 tty2 Sl+ 0:00 /usr/libexec/gnome-session-binary --systemd --systemd --session=ubuntu LANGUAGE=en_GB:en USER=golinux LC_TIME=en_GB.UTF-8 XDG_SEAT=seat0 XDG_SESSION_TYPE=x11 SSH_AGENT_PID=10 1840 pts/0 Ss+ 0:00 bash GJS_DEBUG_TOPICS=JS ERROR;JS LOG SSH_AUTH_SOCK=/run/user/1000/keyring/ssh SESSION_MANAGER=local/ubuntu-PC:@/tmp/.ICE-unix/1143,unix/ubuntu-PC:/tmp/.ICE-unix/1143 PAPERSI 1925 pts/1 Ss 0:00 bash GJS_DEBUG_TOPICS=JS ERROR;JS LOG SSH_AUTH_SOCK=/run/user/1000/keyring/ssh SESSION_MANAGER=local/ubuntu-PC:@/tmp/.ICE-unix/1143,unix/ubuntu-PC:/tmp/.ICE-unix/1143 PAPERSI 3042 pts/1 S 0:00 -bash SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin HOME=/home/golinux USER=golinux LOGNAME=golinux 3136 pts/1 R+ 0:00 ps e SHELL=/bin/bash LC_ADDRESS=bho_NP LC_NAME=bho_NP LC_MONETARY=bho_NP PWD=/home/golinux LOGNAME=golinux HOME=/home/golinux LC_PAPER=bho_NP LANG=en_US.UTF-8 LS_COLORS=rs=0:
18. Hide the header of ps command output
The h option hides the header in the output.
Sample Output:
19. Repeat the header lines of ps command output
The —header option is used to repeat the header lines, one per output page.
Sample Output:
You will only see the effect when the output is larger than one page.
golinux@ubuntu-PC:~$ ps --headers -A PID TTY TIME CMD 1 ? 00:00:01 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 4 ? 00:00:00 rcu_par_gp 6 ? 00:00:00 kworker/0:0H-events_highpri 9 ? 00:00:00 mm_percpu_wq 10 ? 00:00:00 rcu_tasks_rude_ 11 ? 00:00:00 rcu_tasks_trace 12 ? 00:00:00 ksoftirqd/0 13 ? 00:00:00 rcu_sched 14 ? 00:00:00 migration/0 15 ? 00:00:00 idle_inject/0 16 ? 00:00:00 cpuhp/0 17 ? 00:00:00 kdevtmpfs
20. ps command to display a process tree
The f or —forest option displays an ASCII art process tree.
Sample Output:
golinux@ubuntu-PC:~$ ps --forest -A PID TTY TIME CMD 2 ? 00:00:00 kthreadd 3 ? 00:00:00 \_ rcu_gp 4 ? 00:00:00 \_ rcu_par_gp 960 ? 00:00:00 \_ goa-identity-se 1118 ? 00:00:00 \_ at-spi-bus-laun 1124 ? 00:00:00 | \_ dbus-daemon 1137 ? 00:00:00 \_ gnome-session-c 1143 ? 00:00:00 \_ gnome-session-b 1322 ? 00:00:00 | \_ evolution-alarm 1377 ? 00:00:00 | \_ gsd-disk-utilit 1514 ? 00:00:01 | \_ update-notifier 1158 ? 00:03:26 \_ gnome-shell 1181 ? 00:00:00 | \_ ibus-daemon 1185 ? 00:00:00 | \_ ibus-dconf 1186 ? 00:00:01 | \_ ibus-extension- 1458 ? 00:00:00 | \_ ibus-engine-sim
You can print the process hierarchy using -H option.
golinux@ubuntu-PC:~$ ps -H -A PID TTY TIME CMD 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 1832 ? 00:00:37 gnome-terminal- 1840 pts/0 00:00:00 bash 1925 pts/1 00:00:00 bash 2867 pts/1 00:00:00 su 2868 pts/1 00:00:00 bash 3041 pts/1 00:00:00 su 3042 pts/1 00:00:00 bash 4010 pts/1 00:00:00 ps
21. ps command to show threads as if they were processes
The H option allows you to show threads as if they were processes.
Sample Output:
22. Show threads with LWP and NLWP columns
The -L option show threads, possibly with LWP (lightweight process) and NLWP (number of the lightweight processes) columns.
Sample Output:
23. Show format specifiers with ps command
The L option shows all format specifiers.
Sample Output:
24. Display signal format with ps command
The s option is used to display signal format.
Sample Output:
golinux@ubuntu-PC:~$ ps s UID PID PENDING BLOCKED IGNORED CAUGHT STAT TTY TIME COMMAND 1000 886 0000000000000000 0000000000000000 0000000000001000 0000000180014000 Ssl+ tty2 0:00 /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session 1000 891 0000000000000000 0000000000000000 0000000000001000 00000001c18066ef Rl+ tty2 1:40 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -k 1000 972 0000000000000000 0000000000000000 0000000000001000 0000000180004002 Sl+ tty2 0:00 /usr/libexec/gnome-session-binary --systemd --systemd --session=ubuntu 1000 1840 0000000000000000 0000000000000000 0000000000380004 000000004b817efb Ss+ pts/0 0:00 bash 1000 1925 0000000000000000 0000000000010000 0000000000380004 000000004b817efb Ss pts/1 0:00 bash 1000 3042 0000000000000000 0000000000010000 0000000000380004 000000004b817efb S pts/1 0:00 -bash 1000 4305 0000000000000000 0000000000000000 0000000000000000 00000001f3d1fef9 R+ pts/1 0:00 ps s
25. ps command to display security info
The -M option adds a column of security data and is used to get the security information of the processes.
Sample output:
Conclusion
This tutorial demonstrates the different examples of ps command to display information about active processes in the Linux system. It is a very useful command to monitor running processes in the system. If you still have any confusion, please feel free to ask us in the comment section.
What’s Next
Further Reading
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!