Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions docs/books/admin_guide/08-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Process Management

# Process Management

In this chapter you will learn how to work with processes.
In this chapter, you will learn how to work with processes.

****

Expand All @@ -25,9 +25,9 @@ In this chapter you will learn how to work with processes.

## Generalities

An operating system consists of processes. These processes are executed in a specific order and are related to each other. There are two categories of processes, those focused on the user environment and those focused on the hardware environment.
An operating system consists of processes. These processes are executed in a specific order and are related. There are two categories of processes, those focused on the user environment and those focused on the hardware environment.

When a program runs, the system will create a process by placing the program data and code in memory and creating a **runtime stack**. A process is therefore an instance of a program with an associated processor environment (ordinal counter, registers, etc...) and memory environment.
When a program runs, the system will create a process by placing the program data and code in memory and creating a **runtime stack**. A process is an instance of a program with an associated processor environment (ordinal counter, registers, etc...) and memory environment.

Each process has:

Expand All @@ -36,18 +36,18 @@ Each process has:

By successive filiations, the `init` process is the father of all processes.

* A process is always created by a parent process
* A parent process always creates a process
* A parent process can have multiple child processes

There is a parent/child relationship between processes. A child process is the result of the parent process calling the _fork()_ primitive and duplicating its own code to create a child. The _PID_ of the child is returned to the parent process so that it can talk to it. Each child has its parent's identifier, the _PPID_.
There is a parent/child relationship between processes. A child process results from the parent calling the _fork()_ primitive and duplicating its code to create a child. The _PID_ of the child is returned to the parent process so that it can talk to it. Each child has its parent's identifier, the _PPID_.

The _PID_ number represents the process at the time of execution. When the process finishes, the number is available again for another process. Running the same command several times will produce a different _PID_ each time.

<!-- TODO ![Parent/child relationship between processes](images/FON-050-001.png) -->

!!! Note

Processes are not to be confused with _threads_. Each process has its own memory context (resources and address space), while _threads_ from the same process share this same context.
Processes are not to be confused with _threads_. Each process has its memory context (resources and address space), while _threads_ from the same process share this context.

## Viewing processes

Expand Down Expand Up @@ -77,12 +77,12 @@ Some additional options:
| `-H` | Displays the information in a tree structure. |
| `-I` | Displays additional information. |
| `--sort COL` | Sort the result according to a column. |
| `--headers` | Displays the header on each page of the terminal. |
| `--headers` | Displays the header on each terminal page. |
| `--format "%a %b %c"` | Customize the output display format. |

Without an option specified, the `ps` command only displays processes running from the current terminal.

The result is displayed in columns:
The result is displayed in the following columns:

```
# ps -ef
Expand All @@ -101,7 +101,7 @@ root 1 0 0 Jan01 ? 00:00/03 /sbin/init
| `TIME` | Processing duration. |
| `CMD` | Command executed. |

The behaviour of the control can be fully customized:
The behavior of the control can be fully customized:

```
# ps -e --format "%P %p %c %n" --sort ppid --headers
Expand All @@ -126,17 +126,17 @@ The user process:
The system process (_daemon_):

* is started by the system
* is not associated with any terminal, and is owned by a system user (often `root`)
* is not associated with any terminal and is owned by a system user (often `root`)
* is loaded at boot time, resides in memory, and is waiting for a call
* is usually identified by the letter `d` associated with the process name

System processes are therefore called daemons (_**D**isk **A**nd **E**xecution **MON**itor_).

## Permissions and rights

When a command is executed, the user's credentials are passed to the created process.
The user's credentials are passed to the created process when a command is executed.

By default, the actual `UID` and `GID` (of the process) are therefore identical to the **actual** `UID` and `GID` (the `UID` and `GID` of the user who executed the command).
By default, the process's actual `UID` and `GID` (of the process) are identical to the **actual** `UID` and `GID` (the `UID` and `GID` of the user who executed the command).

When a `SUID` (and/or `SGID`) is set on a command, the actual `UID` (and/or `GID`) becomes that of the owner (and/or owner group) of the command and no longer that of the user or user group that issued the command. Effective and real **UIDs** are therefore **different**.

Expand All @@ -146,7 +146,7 @@ Each time a file is accessed, the system checks the rights of the process accord

A process cannot be run indefinitely, as this would be to the detriment of other running processes and would prevent multitasking.

The total processing time available is therefore divided into small ranges, and each process (with a priority) accesses the processor in a sequenced manner. The process will take several states during its life among the states:
Therefore, the total processing time available is divided into small ranges, and each process (with a priority) accesses the processor sequentially. The process will take several states during its life among the states:

* ready: waiting for the availability of the process
* in execution: accesses the processor
Expand All @@ -161,13 +161,13 @@ The end-of-process sequencing is as follows:
2. Release of the used memory
3. Sending a signal to the parent and child processes

When a parent process dies, its children are said to be orphans. They are then adopted by the `init` process which will destroy them.
When a parent process dies, their children are said to be orphans. They are then adopted by the `init` process, which will destroy them.

### The priority of a process

The processor works in time sharing with each process occupying a quantity of processor time.
The processor works in time sharing, with each process occupying a quantity of processor time.

The processes are classified by priority whose value varies from **-20** (the highest priority) to **+19** (the lowest priority).
The processes are classified by priority, whose value varies from **-20** (the highest priority) to **+19** (the lowest priority).

The default priority of a process is **0**.

Expand Down Expand Up @@ -236,7 +236,7 @@ $ nohup myprogram.sh 0</dev/null &

!!! Note

`nohup` handles standard output and error, but not standard input, hence the redirection of this input to `/dev/null`.
`nohup` handles standard output and error but not standard input, hence the redirection of this input to `/dev/null`.

### [CTRL] + [Z]

Expand Down Expand Up @@ -318,7 +318,7 @@ Unlike `root`, a standard user can only reduce the priority of a process. Only v

!!! Tip

This last limitation can be lifted on a per-user or per-group basis by modifying the `/etc/security/limits.conf` file.
This last limitation can be lifted per-user or per-group by modifying the `/etc/security/limits.conf` file.

The `renice` command allows you to change the priority of a running process.

Expand All @@ -337,7 +337,7 @@ $ renice +15 -p 1664
| `-p` | `PID` of the process. |
| `-u` | `UID` of the process owner. |

The `renice` command acts on processes already running. It is therefore possible to change the priority of a specific process, but also of several processes belonging to a user or a group.
The `renice` command acts on processes already running. It is therefore possible to change the priority of a specific process and several processes belonging to a user or a group.

!!! Tip

Expand Down Expand Up @@ -368,13 +368,13 @@ PID USER PR NI ... %CPU %MEM TIME+ COMMAND
| `TIME+` | Processor usage time. |
| `COMMAND` | Command executed. |

The `top` command allows control of the processes in real time and in interactive mode.
The `top` command allows control of the processes in real-time and in interactive mode.

### `pgrep` and `pkill` commands

The `pgrep` command searches the running processes for a process name and displays the _PID_ matching the selection criteria on the standard output.

The `pkill` command will send the specified signal (by default _SIGTERM_) to each process.
The `pkill` command will send each process the specified signal (by default _SIGTERM_).

```
pgrep process
Expand All @@ -397,7 +397,7 @@ Examples:

!!! note

Before you decide to kill a process, it's best to know exactly what the process is for, otherwise it can lead to system crashes or other unpredictable problems.
Before you kill a process, it's best to know exactly what the process is for, otherwise it can lead to system crashes or other unpredictable problems.

In addition to sending signals to the relevant processes, the `pkill` command can also end the user's connection session according to the terminal number, such as:

Expand All @@ -423,7 +423,7 @@ $ killall tomcat

### `pstree` command

This command displays the progress in a tree style and its usage is - `pstree [option]`.
This command displays the progress in a tree style, and its usage is - `pstree [option]`.

| Option | Description |
| :--- | :--- |
Expand Down Expand Up @@ -459,9 +459,9 @@ systemd(1)─┬─systemd-journal(595)

### Orphan process and zombie process

**orphan process**: When a parent process dies, its children are said to be orphans. These special state processes are adopted by the init process and status collection is completed until they are destroyed. Conceptually speaking, the orphanage process does not pose any harm.
**orphan process**: When a parent process dies, their children are said to be orphans. The init process adopts these special state processes, and status collection is completed until they are destroyed. Conceptually speaking, the orphanage process does not pose any harm.

**zombie process**: After a child process completes its work and is terminated, its parent process needs to call the signal processing function wait() or waitpid() to obtain the termination status of the child process. If the parent process does not do so, although the child process has already exited, it still retains some exit status information in the system process table, because the parent process cannot obtain the status information of the child process, these processes will continue to occupy resources in the process table. We refer to processes in this state as zombies.
**zombie process**: After a child process completes its work and is terminated, its parent process needs to call the signal processing function wait() or waitpid() to obtain the termination status of the child process. If the parent process does not do so, although the child process has already exited, it still retains some exit status information in the system process table. Because the parent process cannot obtain the status information of the child process, these processes will continue to occupy resources in the process table. We refer to processes in this state as zombies.

Hazard:

Expand Down