Linux and Unix PS command Examples

  • PS command syntax and tutorial
  • process status command examples
  • ps -ef command in Unix
  • ps -aef command in Linux
  • How to Kill process by name Killall
  • Kill Process Id
  • How to Stop the process in Linux

process status command Unix/Linux

PS abbreviated as the process status command list information about the active process running in the Linux/Unix machine.

This command list out all the active running process of a shell.

We will see frequently used ps command examples in the below sections. All these commands execute in the Linux/Unix command line

ps command without arguments

Ps command without arguments list out all the process of a current shell

root:~[0]# ps

and output is

PID TTY TIME CMD
10169 pts/0 00:00:00 bash
10247 pts/0 00:00:00 ps

ps -aef command

ps -aef command output list all the processes in the system to the console

root:~[0]# ps -aef

and output is

nagios 408 1 0 Jul17 ? 00:00:00 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f
root 410 1 0 Jul17 ? 00:00:10 /usr/sbin/cron -f
root 415 1 0 Jul17 ? 00:04:38 /usr/sbin/irqbalance --foreground
message+ 416 1 0 Jul17 ? 00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 429 1 0 Jul17 ? 00:04:09 /usr/sbin/rsyslogd -n
root 432 1 0 Jul17 ? 00:00:08 /lib/systemd/systemd-logind
Debian-+ 438 1 0 Jul17 ? 00:27:01 /usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f
root 439 1 0 Jul17 tty1 00:00:00 /sbin/agetty --noclear tty1 linux
root 441 1 0 Jul17 hvc0 00:00:00 /sbin/agetty --keep-baud 115200,38400,9600 hvc0 vt220
root 471 1 0 Jul17 ? 00:28:35 /usr/sbin/xe-daemon -p /var/run/xe-daemon.pid
root 475 471 0 Jul17 ? 00:00:00 logger -t xe-daemon
root 478 471 0 Jul17 ? 00:00:00 logger -t xenstore
ntp 515 1 0 Jul17 ? 00:07:04 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 109:113
Debian-+ 818 1 0 Jul17 ? 00:00:01 /usr/sbin/exim4 -bd -q30m
root 897 1 0 Jul25 ? 00:00:00 /lib/systemd/systemd --user
root 898 897 0 Jul25 ? 00:00:00 (sd-pam)
root 5636 2 0 Sep20 ? 00:00:03 [kworker/0:1]
root 6170 2 0 Sep18 ? 00:00:03 [kworker/0:2]
root 8211 2 0 Aug22 ? 00:00:00 [bioset]

PS with grep Search command ps -aef| grep java We can use ps command piping with grep. List all the processes in the Linux/UNIX with the name java.

root:~[0]# ps -aef| grep java

and output is

root 27101 1 0 Aug09 ? 00:34:40 /opt/java-jdk/jdk1.8.0_152/bin/java -classpath /root/abc/.mvn/wrapper/maven-wrapper.jar -Dmaven.home=/root -Dmaven.multiModuleProjectDirectory=/root/abc org.apache.maven.wrapper.MavenWrapperMain -Pprod
root 27783 27101 0 Aug09? 00:37:20 /opt/java-jdk/jdk1.8.0_152/jre/bin/java -cp /root/target/classes:/root/.m2/repository/org/springframework/boot/
.............................

Kill Process Id forcefully

Kill proceed to kill the process which has an id of the process. we can use kill -9 command for forcible killing the process.

root:~[0]#kill -9 pid

How to Kill process by name Killall in Unix

Killall is a command to kill a process with the process name

root:~[0]#Killall processname

processname is the name of the process name

How to Stop the process in Linux

kill 0 to stop all the processes.

root:~[0]#Kill 0 processname

Process Tree command in Linux

This command gives a process tree of all processes. This gives parent and child process-linked information.

root:~[0]# ps -e --forcast

and output is

31138 ? 00:00:25 packagekitd
31142 ? 00:00:00 polkitd
897 ? 00:00:00 systemd
898 ? 00:00:00 \_ (sd-pam)
27101 ? 00:34:40 java
27783 ? 00:37:20 \_ java
30699 ? 00:01:59 postgres
30701 ? 00:00:01 \_ postgres

ps aux command

This command list out all the process of all users

root:~[0]#ps aux

and output is

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 57276 4876 ? Ss Jul17 1:09 /sbin/init
root 2 0.0 0.0 0 0 ? S Jul17 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Jul17 0:07 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< Jul17 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S Jul17 7:21 [rcu_sched]
root 8 0.0 0.0 0 0 ? S Jul17 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S Jul17 0:12 [migration/0]
root 10 0.0 0.0 0 0 ? S< Jul17 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S Jul17 0:15 [watchdog/0]
root 12 0.0 0.0 0 0 ? S Jul17 0:00 [cpuhp/0]
root 13 0.0 0.0 0 0 ? S Jul17 0:00 [cpuhp/1]
root 14 0.0 0.0 0 0 ? S Jul17 0:16 [watchdog/1]

ps -ef command

This list out all processes in full format.

root:~[0]#ps -ef or ps -eF

and output is

UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jul17 ? 00:01:09 /sbin/init
root 2 0 0 Jul17 ? 00:00:00 [kthreadd]
root 3 2 0 Jul17 ? 00:00:07 [ksoftirqd/0]
root 5 2 0 Jul17 ? 00:00:00 [kworker/0:0H]
root 7 2 0 Jul17 ? 00:07:21 [rcu_sched]
root 8 2 0 Jul17 ? 00:00:00 [rcu_bh]
root 9 2 0 Jul17 ? 00:00:12 [migration/0]
root 10 2 0 Jul17 ? 00:00:00 [lru-add-drain]
root 11 2 0 Jul17 ? 00:00:15 [watchdog/0]
root 12 2 0 Jul17 ? 00:00:00 [cpuhp/0]
root 13 2 0 Jul17 ? 00:00:00 [cpuhp/1]