CH 5
CH 5
Operating System
A. Chikhaoui
2023-2024
Définition
1 14
Process Identification
When a process is created, it is often referred to as the "child" process, and the process
that initiated its creation is the "parent" process.
Each process is identified by:
▶ a PID identity (Process ID)
▶ the identity of its parent PPID (Parent Process ID)
▶ the user
▶ group
▶ the current directory
▶ priority
▶ etc.
A PID is a unique numerical identifier assigned to each running process.
PIDs are used by the operating system kernel to keep track of and manage individual
processes.
2 14
Commands to get information about the processes
There are several commands in Linux/Unix systems, including Ubuntu, that you can use
to gather information about processes. Following are some commonly used commands:
▶ ps
▶ pstree
▶ top
▶ htop
▶ pgrep
▶ , etc.
3 14
ps command
ps (process status) allows to display current processes launched by the user and from
the current terminal.
$ ps
PID TTY TIME CMD
126194 pts/0 00:00:00 bash
169546 pts/0 00:00:00 ps
This invocation of ps shows two processes.The first, bash, is the shell running on this
terminal.The second is the running instance of the ps program itself
▶ PID Process ID, process number
▶ TTY name of the terminal from which the process was launched
▶ TIME process processing time
▶ CMD Command executed
4 14
ps command
$ ps-f
UID PID PPID C STIME TTY TIME CMD
user1 126194 126175 0 09:44 pts/0 00:00:00 bash
user1 280088 126194 0 11:13 pts/0 00:00:00 ps -f
5 14
ps command
6 14
pstree command
pstree: The pstree command gives a good illustration of the process hierarchy.
7 14
pstree command
8 14
top command
top: allows to display process information in real time. Information is refreshed every 03
seconds
9 14
htop command
10 14
kill command
11 14
killall
killall is used to send signals to, and terminate, processes based on their names.
Example
$ killall gedit
12 14
Foreground and Background Tasks
1. A foreground task is a process that is currently executing and has control of the
terminal. This is the default execution mode for commands.
$ ls
▶ In this example, the command ls runs in the foreground.
2. A background task is a process that runs independently of the terminal and does not
block user input.
▶ To run a command in the background, you can append an ampersand (&) at the end of the
command.
▶ The following command runs in the background
13 14
Foreground and Background Tasks
The jobs command: allows you to view the list of background processes;
We can switch the process between background mode and foreground mode:
▶ To make a process in foreground (foreground) we use the command: fg
▶ To make a process in the background (backgrround) we use the command: bg
Example:
$ gedit &
$ xclock &
$ jobs
(1)- Running gedit &
(2)+ Running xclock &
$ fg 1
$ jobs
(2)+ Running xclock &
14 / 14