On this page 14 sections
- Processes in Linux
- ps aux
- Understand ps aux columns
- Search for a process
- Show processes as a tree
- Inspect one process
- Sort by CPU usage
- Processes for a specific user
- Custom process output
- Long-running processes
- Inspect process command line from /proc
- Inspect process environment
- Find network process relationships
- Useful process overview
Processes in Linux
Every running program is represented by a process with a PID. Processes also have an owner, parent process, resource usage and command line. Understanding the process tree is useful for administration, troubleshooting and security analysis.
psps aux
ps aux is one of the most common ways to display processes from all users with CPU, memory and command information.
ps auxUnderstand ps aux columns
USER identifies the owner, PID is the process ID, %CPU and %MEM show resource usage, VSZ and RSS represent memory information, STAT shows process state, START indicates when it started and COMMAND contains the executed command.
Search for a process
grep can quickly filter ps output, although pgrep is often cleaner for scriptable process lookup.
ps aux | grep "[n]ginx"ps aux | grep "[s]shd"pgrep -a nginxShow processes as a tree
A process tree makes parent-child relationships visible and helps explain which service launched another process.
ps auxfpstree -pInspect one process
ps can show selected fields for a specific PID instead of printing the complete process list.
ps -p 1234 -o pid,ppid,user,%cpu,%mem,etime,cmdSort by CPU usage
ps can sort processes directly, which is useful when investigating performance problems.
ps aux --sort=-%cpu | headps aux --sort=-%mem | headProcesses for a specific user
Processes can be filtered by user to understand which applications or services are running under a particular security context.
ps -u root -fps -u www-data -fCustom process output
The -o option allows only useful fields to be displayed, producing much cleaner output for scripts and investigations.
ps -eo pid,user,ppid,cmdps -eo pid,user,%cpu,%mem,cmd --sort=-%cpuLong-running processes
etimes displays elapsed runtime in seconds. Long-running or unexpectedly new processes can both be interesting depending on the troubleshooting context.
ps -eo pid,user,etimes,cmd --sort=-etimesInspect process command line from /proc
The proc filesystem exposes detailed information about each running process. cmdline contains the arguments used when starting the process.
tr '\0' ' ' < /proc/1234/cmdlinereadlink -f /proc/1234/exeInspect process environment
Environment variables associated with a process can be viewed through /proc when permissions allow it. They may contain configuration values relevant to troubleshooting.
tr '\0' '\n' < /proc/1234/environFind network process relationships
ps and ss work well together. ss identifies which PID owns a listening socket and ps can then provide detailed information about that process.
sudo ss -lntpps -p 1234 -o pid,ppid,user,etime,cmdUseful process overview
A clean process listing sorted by user and PID is often easier to review than raw ps aux output.
ps -eo user,pid,ppid,%cpu,%mem,etime,cmd --sort=user,pid