2018-11-13 08:54:50 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: intermediate
|
2018-11-16 12:47:48 +00:00
|
|
|
category-title: Intermediate commands
|
|
|
|
tags: process status
|
2018-11-13 08:54:50 +00:00
|
|
|
author: Andrea Brites Marto
|
|
|
|
title: ps
|
|
|
|
---
|
|
|
|
|
|
|
|
<p>
|
2018-11-15 16:19:19 +00:00
|
|
|
The <i>ps</i> command stands for "process status" and it is used to provide
|
2018-11-14 21:15:38 +00:00
|
|
|
various information about the currently running processes.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Every process is an executing instance of a program which is assigned a unique PID
|
2018-11-15 08:05:41 +00:00
|
|
|
(process identification numbers) by the system.</p>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
The basic syntax of <i>ps</i> is:
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
ps [options]
|
2018-11-14 21:15:38 +00:00
|
|
|
</pre>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-15 08:05:41 +00:00
|
|
|
<p>
|
2018-11-14 21:15:38 +00:00
|
|
|
This command can be used without any option and by doing this you will get the standard output,
|
|
|
|
which is the display monitor by default with four items of information for at least two
|
|
|
|
processes currently on the system: the shell and ps.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Since we have already saw PID before, the TTY information that stands for terminal type
|
|
|
|
(originally teletype) is the console (or terminal) in which the user logged into.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
TIME is very simple: is the amount of CPU time in minutes and seconds that the process
|
|
|
|
has been running. CMD is simply the name of the command that launched the process.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Here you will find some common option combinations
|
2018-11-15 08:05:41 +00:00
|
|
|
</p>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
ps aux | less
|
2018-11-14 21:15:38 +00:00
|
|
|
</pre>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<ul>
|
|
|
|
<li>The -a option is used to list the processes of all users on the system.</li>
|
|
|
|
<li>The -u option tells ps to provide detailed information about each process.</li>
|
|
|
|
<li>The -x option adds to the list, processes that have no controlling terminal
|
|
|
|
(programs launched during booting).
|
|
|
|
</li>
|
|
|
|
</ul>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-15 08:05:41 +00:00
|
|
|
<p>
|
2018-11-15 16:19:19 +00:00
|
|
|
This can be piped to the less command (see our section pipe), which let us to
|
2018-11-14 21:15:38 +00:00
|
|
|
view all processes in one screenfull at a time.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Another way to view all processes running on the system is:
|
2018-11-15 08:05:41 +00:00
|
|
|
</p>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
ps ef | less
|
2018-11-14 21:15:38 +00:00
|
|
|
</pre>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Where:
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<ul>
|
|
|
|
<li>The -e option is used to generate a list of information about every process
|
|
|
|
(currently running).
|
|
|
|
</li>
|
2018-11-15 08:05:41 +00:00
|
|
|
<li>The -f option provides a list that contains some information for each process.</li>
|
2018-11-14 21:15:38 +00:00
|
|
|
</ul>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
2018-11-15 08:05:41 +00:00
|
|
|
<p>
|
2018-11-14 21:15:38 +00:00
|
|
|
This is very useful, it can be used for example to control UID information (username of
|
|
|
|
the account that owns the process) and STIME to know when the process started, or
|
|
|
|
the starting date.<br>
|
2018-11-13 08:54:50 +00:00
|
|
|
|
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
In the end the <i>ps</i> is very powerful if we know how to use it.
|
2018-11-14 21:15:38 +00:00
|
|
|
If you need to kill a process you can list all process in various ways
|
|
|
|
and search for the process you need to kill by reading its PID or by UID for example.
|
|
|
|
</p>
|