Simple process selection : Shows the processes for the current shell
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.
[root@rhel7 ~]# ps
PID TTY TIME CMD
12330 pts/0 00:00:00 bash
21621 pts/0 00:00:00 ps
View Processes : View all the running processes use either of the following option with ps
[root@rhel7 ~]# ps -A
[root@rhel7 ~]# ps -e
View Processes not associated with a terminal : View all processes except both session leaders and processes not associated with a terminal
[root@rhel7 ~]# ps -a
PID TTY TIME CMD
27011 pts/0 00:00:00 man
27016 pts/0 00:00:00 less
27499 pts/1 00:00:00 ps
View all the processes except session leaders View all the processes except session leaders
[root@rhel7 ~]# ps -d
View all processes except those that fulfill the specified conditions (negates the selection)
[root@rhel7 ~]# ps -a -N
OR
[root@rhel7 ~]# ps -a --deselect
View all processes associated with this terminal
[root@rhel7 ~]# ps -T
View all the running processes
[root@rhel7 ~]# ps -r
View all processes owned by you : Processes i.e same EUID as ps which means runner of the ps command
[root@rhel7 ~]# ps -x
Select the process by the command name
ps -C command_name
Select by group ID or name. The group ID identifies the group of the user who created the process.
ps -G group_name
ps --Group group_name
View by group id
ps -g group_id
ps -group group_id
View all the processes belongs to any session ID
ps -s session_id
ps --sid session_id
Select by tty. This selects the processes associated with the mentioned tty
ps t tty
ps -t tty
ps --tty tty
Use -f to view full-format listing
[tux@rhel7 ~]$ ps -af
Use -F to view Extra full format
[tux@rhel7 ~]$ ps -F
To view process according to user-defined format
[root@rhel7 ~]# ps --format column_name
[root@rhel7 ~]# ps -o column_name
[root@rhel7 ~]# ps o column_name
View in BSD job control format
[root@rhel7 ~]# ps -j
Display BSD long format
[root@rhel7 ~]# ps l
Add a column of security data
[root@rhel7 ~]# ps -aM
View command with signal format
[root@rhel7 ~]# ps s 766
Display user-oriented format
[root@rhel7 ~]# ps u 1
Display virtual memory format
[root@rhel7 ~]# ps v 1
If you want to see environment of any command. Then use option **e** –
[root@rhel7 ~]# ps ev 766
View processes using highest memory
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem
print a process tree
[root@rhel7 ~]# ps --forest -C sshd
List all threads for a particular process. Use either the -T or -L option to display threads of a process
[root@rhel7 ~]# ps -C sshd -L
To view only the processes running as a specific user, type the following command, where linuxize
is the name of the user
ps -f -U linuxize -u linuxize
To print information only about the PID
and COMMAND
, you would run one of the following commands
ps -efo pid,comm
ps auxo pid,comm
to display the output of the ps
command, one page at a time pipe it to the less
command
ps -ef | less
The output of the ps
command can be filtered with grep
. For example, to show only the process belonging to the root user you would run
ps -ef | grep root
If you run the ps command without any arguments, it displays processes for the current shell
$ ps
Display every active process on a Linux system in generic (Unix/Linux) format
$ ps -A
OR
$ ps -e
$ ps -x
$ ps -U root -u root
$ ps -fL -C httpd
$ ps L
$ ps -C sshd
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
OR
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
To kill Linux processes/unresponsive applications or any process that is consuming high CPU time
$ ps -A | grep -i stress
use the kill command to terminate it immediately
$ kill -9 2583 2584
$ ps -eM
OR
$ ps --context
display security information in a user-defined format with this command
$ ps -eo euser,ruser,suser,fuser,f,comm,label
$ watch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
To perform a full-format listing, add the -f
or -F
flag
$ ps -ef
OR
$ ps -eF