Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

option is -e, which lists all processes running on the system. Another is aux,
which provides a more detailed list of all the processes. You should also know
that ps works not by polling memory but through the interrogation of the
Linux /proc, or process file system.


The /proc directory contains many files, some of which include constantly
updated hardware information (such as battery power levels). Linux
administrators often pipe the output of ps through grep to display
information about a specific program, like this:


Click here to view code image
matthew@seymour:~$ ps aux | grep bash
matthew 9656 0.0 0.1 21660 4460 pts/0 Ss 11:39 0:00
bash


This example returns the owner (the user who launched the program) and the
PID, along with other information such as the percentage of CPU and
memory usage, the size of the command (code, data, and stack), the time (or
date) the command was launched, and the name of the command for any
process that includes the match bash. Processes can also be queried by PID
as follows:


Click here to view code image
matthew@seymour:~$ ps 9656
PID TTY STAT TIME COMMAND
9656 pts/0 S 0:00 gedit


You can use the PID to stop a running process by using the shell’s built-in
kill command. This command asks the kernel to stop a running process and
reclaim system memory. For example, to stop gedit in the preceding
example, use the kill command like this:


Click here to view code image
matthew@seymour:~$ kill 9656


After you press Enter and then press Enter again, the shell reports the
following:


Click here to view code image
[1]+ Terminated gedit


Note that users can kill only their own processes, but root can kill all users’
processes. Controlling any other running process requires root permission,
which you should use judiciously (especially when forcing a kill by using the
-9 option); by inadvertently killing the wrong process through a typo in the
command, you could bring down an active system.

Free download pdf