Each program that runs under the GNU/Linux system consists of one or more processes. Each process allocates a certain portion of the memory and system resources. Let's look at how to handle the processes.
First of all, we have to discover what processes run on our system. The ps command is used for this task; nevertheless, its basic expression just lists the processes we’ve started in the currently opened terminal. To achieve a more detailed list, it’s better to use aux attributes, where a displays all processes started on the terminal, x displays processes disconnected from the terminal and u displays information about the user under which the process was started.
The columns are quite transparent, but let’s focus on the second one. Each running process is assigned a unique numeric identifier we can use to call the process. This identifier is named PID and is listed in the second column of the output.
Just as a matter of interest, or to understand mutual references of the running applications, we can have the system display a tree structure. The pstree tool is used to display it.
All this information is useful primarily when the OS gets into trouble and we want to discover the cause, which often lies in the excessive load some processes put on the system, or we just want to “kill” a process.
There are more ways to handle processes and modify their behaviour (add/remove system resources to/from them, etc.), but the most important one you’ll see most of the time is a requirement to end a process immediately – due to an error, excessive usage of resources or just when debugging an application.
You can use the kill signal, which can be sent to a process using the command of the same name. You just add the identifier (PID) to the command as a parameter and the process should end itself.
$ kill 12345
The kill signal tries to end the process “in a decent manner”; it closes all files, releases the allocated memory, etc. However, if the problems are more serious, the process can remain active. Then you might use a stricter way to kill the process, with the -9 attribute.
$ kill -9 12345
This way the process will be shut down for sure but without the “clean-up”.
We’ll dig into task management in the next section.
Author: Jirka Dvořák