Linux/Unix – System Activity
When you run a command, you are starting a process on the system, which is a program that is currently executing. Every process is given a unique number, called its process ID, or “PID.”
Use ps to list processes on the system. Some of the information it can display about a process includes process ID, name of command being run, username running the command, and how long the process has been running. By default, ps outputs 5 columns: process ID, the name of the terminal from which the process was started, the current status of the process (including `S’ for sleeping, meaning that it is on hold at the moment, `R’ meaning that it is running, and `Z’ meaning that it is a zombie process, or a process that has already died), the total amount of time the CPU has spent on the process since the process started, and finally the name of the command being run.
Listing Your Current Processes
Type ps with no arguments to list the processes you have running in your current shell session.
To list the processes in your current shell session, type:
PID TTY STAT TIME COMMAND
193 1 S 0:01 −bash
204 1 S 0:00 ps
In this example, ps shows that two processes are running: the bash and ps commands.
Listing All of a User’s Processes
To list all the processes of a specific user, use ps and give the username to list as an argument to the `−u’ option. While you can’t snoop on the actual activities of other users, you can list the commands they are running at a given moment. To list all the processes that user hst has running on the system, type:
$ ps −u hst
NOTE: This command is useful for listing all of your own processes, across all terminals and shell sessions; give your own username as an argument.
Listing All Processes on the System
To list all processes by all users on the system, use the `aux’ options.
To list all of the processes and give their usernames, type:
$ ps aux
NOTE: There could be a lot of output−−even single−user Linux systems typically have fifty or more processes running at one time−−so you may want to pipe the output of this command through less for perusal.
Additionally, use top to show a display of all processes on the system, sorted by their demand on the system resources. The display is continually updated with current process information; press Q to stop the display and exit the program. This tool also displays the information about system runtime and memory that can be output with the uptime and free commands.
To display a continually updated display of the current system processes, type:
Listing Processes by Name or Number
To list processes whose output contains a name or other text to match, list all processes and pipe the output to grep. This is useful for when you want to see which users are running a particular program or command.
To list all the processes whose commands contain reference to an `sbin’ directory in them, type:
$ ps aux | grep sbin
To list any processes whose process IDs contain a 13 in them, type:
$ ps aux | grep 13
To list the process (if any) which corresponds to a process ID, give that PID as an argument to the`−p’ option.
To list the process whose PID is 344, type:
$ ps −p 344