ps

From LinuxReviews
Jump to navigationJump to search

Crawlergo

Konsole.svg

ps is the ultimate shell tool for listing active processes on Linux and BSD systems. It may not appear that way because of the limited information you get if you just type ps terminal, but there is much more to it thanks to a rather huge number of command line options.

ps is done and exists after making a list of the currently running processes you ask it to list, it is not a process monitor you can use to watch processes come and go. See htop, top and Comparison Of System Monitoring Programs if that is what you are looking for.

ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top instead.

HOWTO list all active processes[edit]

The -e option can be used to make ps list all the active processes on a machine. There is an identical -A option for it (-e and -A are the exact same switch functionality-wise).

The long list of processes -e produces can be made a bit more readable by making the output be shown as a process hierarchy. There are two output format options available that let you do that: -H for hierarchy and f or --forest. Who processes belong to are not shown by default, so you will likely want u as well.

Snubbelrisk.jpg
Warning: ps has a annoyingly large and confusing set of similar options where -option differs from option.
  • -e selects all processes.
  • e adds information about the environment after commands in the process list

ps -e and ps e produce vastly different results.

You can group options that require a - dash together and you have to separate options without a - dash from them.

ps -e f prints all processes (-e) as a forest f).

ps -ef prints all processes (-e) in full-format listing (-f). The output is equal to ps -e -f

A process tree with all processes and the users they belong to can be shown with:

ps -e uf

Listing User Processes[edit]

All processes created by a single user can be selected with -U followed by a user-ID in either the form of a username or a numeric ID. Your user-id is always available in the special $UID variable. Thus; ps -U $UID will list all of your own processes. You can add f before or after to get a process tree. Notice that f is not an argument with a - dash; ps f -U $UID and ps -U $UID f will show a process tree, ps -fU $UID will not.

Killing Processes[edit]

See Bash Guide for Beginners Chapter 12, Signals to your Bash shell if you want to know how to eradicate potentially unwanted processes in your process list.

Installation[edit]

ps is as good as always installed a Linux or BSD machine. It will either be part of a package called procps or procps-ng. You would only have to install it if you or a systems administrator deleted it accidentally or intentionally.

Links[edit]

The ps.1 manual page is very long. ps has a really long list of options beyond those mentioned on this page; you can look those up on the manual page.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.