The Linux ps command: list running processes
In Unix-type operating systems, especially Linux, managing and monitoring running processes is a key task for any system manager or developer. The commandps(process status) allows you to obtain a snapshot of the active processes, showing information such as the process identifier (PID), the owner user, CPU consumption and memory, and the command that initiated them. Unlike interactive tools liketoporhtop, psis non-interactive and can be used in scripts, pipes and combinations with other commands to filter, format and analyze system status quickly and efficiently.
What's ps?
The namepscomes from «status process». Its main function is to read the kernel process table and present the data in a readable format. Depending on the options provided, you can show from a basic summary to a comprehensive detail of each thread and associated resources. It is one of the oldest utilities of Unix systems and remains relevant thanks to its simplicity and power.
Basic syntax
The simplest way to invokepsis without arguments, which shows the processes associated with the current terminal:
ps
For a wider view, options that change output behavior are usually added. The options can be combined without additional scripts, although it is also possible to use the GNU-style syntax with double script.
Most commonly used options
-a: shows all processes with associated terminal, except session leaders and processes not associated with a terminal.-u: presents the output in user-oriented format, including user name, CPU percentage and memory, and running time.-x: includes processes that do not have a controlling terminal, useful to see demons and processes in the background.-e(or-A): lists all system processes, not filtered by terminal.-f: generates a full format that shows the father-child relationship (PPID), the start time and the complete command with its arguments.-l: long format, with more fields such as priority (PRI), number of nice (NI) and resident memory size (RSS).
Practical examples
ps aux: combines-a,-uand-xto view all system processes in user-oriented format; it is one of the most frequent commands for diagnosis.ps -ef: equivalent tops -e -f, shows all processes in full format, ideal for seeing PPID relationships.ps -L -p 1234: list all the light-weight processes of the process with PID 1234.ps -eo pid,ppid,user,%cpu,%mem,comm --sort=-%cpu: shows a subset of columns ordered by descending CPU consumption.
Filtering and sorting
In addition to standard options,pscan filter results by selecting processes by PID, command name, user or any other field. For example:
ps -C httpd: shows only the processes whose exact name ishttpd.ps -u www-data: list all processes executed by the userwww-data.ps -p 1,2,3: shows the processes with the specified PID.
To order the output, the option is used--sortfollowed by the field and optionally a sign-for descending order or+for ascending. Common fields to order include%cpu, %mem, pidandstart_time.
Custom output format
When the default format does not meet our needs, we can define our own columns using the option-o(or--format). Each field is specified by its short name, aspid, ppid, user, %cpu, %mem, vsz, rss, tty, stat, start, timeandcomm. A typical example is:
ps -eo pid,user,%cpu,%mem,comm,args --sort=-%cpu | head -10
This command shows the ten processes that most consume CPU, including the complete command and its arguments.
Combinepswith other tools
The real power ofpsis revealed when used in combination with other command line utilities using pipes. Some common patterns are:
ps aux | grep apache: filters the list to show only the processes that contain the word «apache».ps -eo pid,ppid,user,comm | sort -k3 -n: orders output by user name usingsort.ps -eo pid,etime | awk '$2 > "00:10:00" {print $1}': identifies processes that have been running for more than ten minutes.
These combinations allow you to create custom monitors, alerts and resource consumption reports.
Tips and good practices
- Always specify the output format with
-owhen you are going to process the information in a script; so you avoid surprises if the default format changes between versions. - Use
--no-headersif you need to remove the header row to facilitate processing withawkorcut. - Remember that some options are specific to implementation (BSD vs GNU). In most modern Linux distributions the GNU variant predominates, but it is useful to consult
man psto confirm the exact syntax. - For continuous monitoring, consider using
watchwithps(e.g.,watch -n 5 'ps -eo pid,user,%cpu,%mem,comm --sort=-%cpu | head -5') to get an updated view every few seconds.
Conclusion
The commandpsis an essential tool for anyone working with Linux. Its ability to list, filter and format information on the running processes makes it essential for both problem resolution and system performance optimization. Domain your options and know how to combine it with other terminal utilities will allow you to obtain accurate and timely information about your machine's status, thus improving your efficiency as an administrator or developer.


