- PID is the unique process ID of the process
- TTY is the type of terminal user is logged in to. pts means pseudo terminal
- TIME gives you for how long the process has been running
- CMD is the command that you run to launch the process
Now this doesn’t really provide any real, useful information. Let’s see some better examples of ps command:
1. See all your running process
If you want to see all the processes run by you, you can use the ps command with option x like this:
The x option will display all the processes even if they are not associated with current tty (terminal type) or if they don’t have a controlling terminal (like daemons).
The – before option x is optional but the general Linux convention is to use – before options so I advise you to keep on following it. It won’t hurt you.
This is what the output looks like. I have truncated the output because it had hundreds of lines:
PID TTY STAT TIME COMMAND 503 pts/0 Sl 0:00 gedit 2245 ? S 0:00 /usr/bin/ssh-agent -D -a /run/user/1000/keyring/.ssh 3039 ? Ss 0:00 /lib/systemd/systemd --user 3040 ? S 0:00 (sd-pam) 3054 ? SLl 0:01 /usr/bin/gnome-keyring-daemon --daemonize --login 3059 tty2 Ssl+ 0:00 /usr/lib/gdm3/gdm-x-session --run-script env
The STAT in the above output means Process State Codes. You can find a detailed table in the man page of the ps command.
But you’ll rarely see ps command used with just option x. It is usually accompanied by option u in this manner:
With option u, you’ll have detailed information about each process:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND abhishek 503 0.0 0.4 681580 37516 pts/0 Sl 18:09 0:00 gedit abhishek 2245 0.0 0.0 11300 1496 ? S 18:37 0:00 /usr/bin/ssh-agent -D -a /run/user/1000/keyring/.ssh abhishek 3039 0.0 0.0 77344 3508 ? Ss 10:37 0:00 /lib/systemd/systemd --user abhishek 3040 0.0 0.0 114632 360 ? S 10:37 0:00 (sd-pam) abhishek 3054 0.0 0.1 517104 11512 ? SLl 10:37 0:01 /usr/bin/gnome-keyring-daemon --daemonize --login
As you can see, now you get the user name and the CPU consumption and memory usage of each process. RSS shows how much memory the process currently has in RAM while VSZ is how much virtual memory the process has in total.
2. See all running processes with ps aux command
You’ll probably see
ps -aux or
ps aux all the time in Linux tutorials and documentations.
With the added -a option, you can see the running processes by all the users on Linux system.
The command output is the same as ps -ux but now you have processes from other users as well. Thanks to the -u option, you can identify which process belongs to which user.
3. See all running processes with ps -ef command in Linux
Apart from ps -aux, you can also list all the running processes with -e command. The common practice is to combine it with option f to get full listing of the commands used to run the processes.
Do note that – before e is important otherwise it will show different result. I told you, ps is a messed up, complicated command.
You can also combine the H option to see all the processes in a threaded view with child processes under their parents:
4. See all running processes by a certain user
To get the information about all the processes run by a certain user, you can use the -U option with the user name:
ps -U user_name
For example, I can see all the processes running by the root user like this:
ps -U root PID TTY TIME CMD 1 ? 00:00:41 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 4 ? 00:00:00 rcu_par_gp 8 ? 00:00:00 mm_percpu_wq 9 ? 00:00:03 ksoftirqd/0 10 ? 00:01:22 rcu_sched
5. See all processes run by a group
You can also categorize running processes by group instead of user by providing group name or group id:
ps -G group_name_or_id
You can combine with option f to get the full listing.
6. Get all occurrences and PID of a program
One of the essential use of the ps command is to get the process ID (PID) of a running program. Normally when you are looking to kill a misbehaving program, you search for all the occurrences of the program, get their PIDs and use the kill command to end the process.
ps -C program__name
For example, if I have to find all running instances of the apt package manager:
ps -C apt PID TTY TIME CMD 11425 pts/1 00:00:00 apt
You can also use grep command to get a similar result.
ps aux | grep program_name
7. Get process information about a PID
Alright! You have got a PID but you don’t know which process it belongs to. You can use the ps command to find the process information from its PID in this way:
You can use more than one PIDs by separating them with comma:
Published @ March 23, 2022 9:19 am