0% found this document useful (0 votes)
4 views

CH 5

Uploaded by

Amina Chikhaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CH 5

Uploaded by

Amina Chikhaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 5 – Processes

Operating System

A. Chikhaoui

2023-2024
Définition

A process is a running program.


Examples:
▶ a launched terminal is a process
▶ an executed command is a process
▶ an open directory is a process
▶ an open file is a process
▶ open browser Firefox or chrome is a process
▶ , etc.
Unix is a "multi-tasking" operating system. This means that it can run many processes
simultaneously

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: The -f parameter is used to get more information.

$ 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

▶ UID: User ID, user name


▶ PPID: Parent Process ID.
▶ C: The percentage of the CPU time used by the process.
▶ STIME: The start time of the process..

5 14
ps command

ps -ef: The -e parameter gives information about all running processes.

$ps -ef | head -n 6


UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:20 ? 00:00:06 /sbin/init splash
root 2 0 0 10:20 ? 00:00:00 [kthreadd]
root 4 2 0 10:20 ? 00:00:00 [kworker/0:0H]
root 6 2 0 10:20 ? 00:00:00 [mm_percpu_wq]
root 7 2 0 10:20 ? 00:00:00 [ksoftirqd/0]
Some other interesting options:
▶ -u allows you to specify a list of one or more users separated by a comma
▶ -g to specify groups
▶ -t to specify terminals

6 14
pstree command

pstree: The pstree command gives a good illustration of the process hierarchy.

7 14
pstree command

pstree -p The -p option allows to display the PIDs.

8 14
top command

top: allows to display process information in real time. Information is refreshed every 03
seconds

9 14
htop command

htop: This is an improvement of top.

10 14
kill command

kill command in Unix-like operating systems is used to terminate or send signals to


processes. It allows to stop or interrupt processes running on your system.
kill -l: -l option allows to display the list of signals.
Some signals:
▶ SIGTERM
Meaning: Terminate. This signal asks the process to terminate gracefully.
▶ SIGKILL
Meaning: Kill. This signal forcefully terminates a process.
▶ SIGINT
Meaning: Interrupt. This signal is to interrupt a process.
By default, kill sends the SIGTERM(15) signal, which asks the process to terminate
gracefully.

$ kill 2023 $ kill -SIGKILL 2023

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

$ cp file.mp4 /tmp/mp4/ &


If the file is very large, then copying it takes a long time and we cannot run other commands;
It is better to run the process in the background to recover the shell in order to run other
commands.

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

You might also like