ps: command not found

The ps command invokes the process table, a record that summarizes the currently running processes on a system. When the command is run without any option, it displays the processes run by the current shell with details such as the PID, the terminal associated with the process, the accumulated CPU time, and the command that started the process. However, different options may be used along with the command to filter the displayed fields or processes.

Syntax

The syntax of the ps command is:

$ ps [options]

Command Option Syntax Styles

The ps command supports three different styles of command option syntax: Unix- style (preceded by a hyphen), GNU-style (preceded by two hyphens), and BSD-style (no hyphen). Mixing these styles will not always produce the same results. For example, the ps command (BSD-style) will print all processes with a controlling terminal, including session leaders (the first member of a group of processes). It will also print the status of each process, as well as the full command (including options) of each process. The ps -a command (Unix-style) also prints all processes with a controlling terminal, but does not include session leaders, the status of each process, nor the full command of each process.

ps Command Options

The ps command supports several options. Some of the more prominent options are listed here.

Option Used To
a List all user-triggered processes.
-e List all processes.
-l List processes using a long listing format.
u List processes along with the user name and start time.
r Exclude processes that are not running currently.
x Include processes without a terminal.
T Exclude processes that were started by any terminal other than the current one.
-U {user name} Display the processes based on the specified user.
-p {PID} Display only the process associated with the specified PID.
-C {command} Display all processes by command name.
–tty {terminal number} Display all processes running on the specified terminal.

If you encounter the below error while running the ps command:

ps: command not found

you may try installing the below package as per your choice of distribution:

OS Distribution Command
Debian apt-get install procps-ng
Ubuntu apt-get install procps-ng
Arch Linux pacman -S procps-ng
Kali Linux apt-get install procps-ng
CentOS yum install procps-ng
Fedora dnf install procps-ng
Raspbian apt-get install procps-ng

ps Command Examples

1. To see the zombie process:

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z

2. Listing zombie processes:

# ps -el | grep Z

3. To find/list the running processes:

# ps -r

4. Find processes for a particular user:

# ps -U apache
# ps U apache
# ps -u apache

5. To see every process running as root (real & effective ID) in user format:

# ps -U root u

6. To find/list the processes which has test.pl in its command execution:

# ps -f -C test.pl

7. List the processes based on PIDs:

# ps -f --ppid 9576

8. pgrep, pkill – look up or signal processes based on name and other attributes:

# pgrep 1234
# pkill 1234 OR # pkill httpd

9. Sorting the ps output:

# ps -eo uname,pid,ppid,nlwp,pcpu,pmem,psr,start_time,tty,time,args --sort -pcpu,-pmem

10. To print a process tree:

# ps -ejH
# ps axjf

11. Print only the process IDs of syslogd:

# ps -C syslogd -o pid=

12. Print only the name of PID 42:

# ps -p 42 -o comm=

13. List the Process based on the UID and Commands:

# ps -f -u wwwrun,postfix

14. List the processes based on PIDs or PPIDs:

# ps -f --ppid 9576

15. List Processes in a Hierarchy:

#  ps -e -o pid,args --forest

16. List elapsed wall time for processes:

# ps -p 1,29675 -o pid,etime=

17. To list the process hierarchy:

# ps -e -o pid,args --forest
# ps axjf
# ps -ejH

18. List all threads for a particular process:

# ps -C java -L -o pid,tid,pcpu,state,nlwp,args

19. To display a tree of processes:

# pstree

20. To list elapsed wall time for processes:

# ps -p 1,29675 -o pid,etime=

21. To get the process start time:

# ps -p PID -o lstart=

22. Display full information about each of the processes currently running:

# ps -ef | grep

23. To get info about threads:

# ps -eLf
# ps axms

24. To get security info:

# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

25. To see every process with a user-defined format:

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -eopid,tt,user,fname,tmout,f,wchan

26. List all threads for a particular process:

# ps -C java -L -o pid,tid,pcpu,state,nlwp,args

27. List all running processes including the full command string:

# ps auxww

28. Search for a process that matches a string:

# ps aux | grep string

29. List all processes of the current user in extra full format:

# ps --user $(id -u) -F

30. List all processes of the current user as a tree:

# ps --user $(id -u) f

31. Get the parent PID of a process:

# ps -o ppid= -p pid

32. Sort processes by memory consumption:

# ps --sort size
Related Post