process
process
com
The process
Part 1
Objectives:
→Hence a process has a momentary life (from its creation until its
termination; it passes from one state to the other before its end of
execution.
States of a process
ready
unblocking
The role of an operating system in process management
➢ It is the OS which must ensure complete management of the creation, destruction and
state transitions of a process.
➢ It is always up to the OS to allocate the memory space necessary for the residence of each
process.
➢ this process is the ancestor (the father) of all processes launched on the Linux
system;
→All processes running on a Linux system are organized in the form of a tree.
Processes in Linux
• The shell process (bash) is the child of the login process (the
process that is waiting for a command to interpret it):
✓ In the case of an internal command, it will not launch a new process (since it is
internal to the shell).
✓ In the case of an external command, the shell process launches a new process(execution of the
program linked to the command launched).
Remark:
Built-in (internal) commands are integrated directly into the shell and are executed more quickly
(cd, echo,pwd), while external commands are separate programs that require the creation of a
separate process for their execution (ls,grep,sed). Both types of commands are essential in the
use of Linux, and each has its own advantages and specific use cases.
Example
$pstree
init├
│- - -
├login---bash+
│pstree (it's an external command)
Process control:
The ps command
Syntax: ps [options]
Some options:
• -a : Shows processes associated with a terminal,
• -A: Shows all processes on the system, including those without a terminal.
• x: show processes that do not have a controlling terminalt ttyn: list of processes on the ttyn
terminal
• u: show the processes running under the specified user,
• f: option adds additional columns to the output, including the parent process ID (PPID),
the controlling terminal (TTY)
Example 1
$ps
PID TTY TIME CMD
2726 tty1 00:00:00 bash
2758 tty1 00:00:02 gedit
2770 tty1 00:00:00 p.s.
bash
bash
As you can see, ps -A lists processes like nginx and cron, which aren't
associated with a terminal, while ps -a excludes them.
Example 2
•This option allows you to show processes belonging to a specific user.
•You can provide the username or the user ID (UID).
State of
Time of
% of
process creation of
owner calculation time consumption
process
of the process in % RAM
Example 3
Default Behavior: If run without additional options, ps -f shows only processes