Sistemet Operative Processes: Lënda
Sistemet Operative Processes: Lënda
Processes
Artan Mazrekaj
Prishtinë, 2023
1
Process definition
2
Process definition (cont.)
Process
Environment
3
Process definition (cont.)
Multiple parts:
Text section (instructions) - also called program code - the executable code.
Heap section- containing memory dynamically allocated during program run time.
local variables.
Process in memory 4
Memory Layout of a C program
5
Process States
6
Life Cycle of a Process
7
Process Control Block (PCB)
9
Process Scheduling
Scheduling queues
10
CPU switch from process to process
▪ A context switch occurs when the CPU switches from one process to
another.
11
Context Switch
▪ When CPU switches to another process, the system must save the
state of the old process and load the saved state for the new process
via a context switch.
12
Context Switch (cont.)
▪ Interrupt handling
- The hardware switches a part of the context when an interrupt
occurs. This happens automatically.
13
Schedulers
14
Schedulers (cont.)
Medium-term Scheduler
• This scheduler is invoked when there is a need to swap out some
blocked processes.
15
Long-term & Medium-term & Short-term Schedulers
16
Long-term & Medium-term & Short-term Schedulers (cont.)
17
Dispatcher
• This operation starts when there is a need to schedule a process from the
ready queue.
• The dispatcher is the module that gives control of the CPU to the process
selected by the short-term scheduler.
18
Operations on Processes
Process creation
Process termination
19
Process Creation
20
Process Creation (cont.)
21
Process Creation (cont.)
There are also two address-space possibilities for the new process:
Child duplicate of parent (it has the same program and data as the
parent).
Child has a program loaded into it.
22
Process Creation (cont.)
▪ UNIX/Linux examples
fork() system call creates new process.
23
Process Hierarchies
▪ When a process creates another process, the parent process and child
process continue to be associated in certain ways.
▪ The child process can itself create more processes, forming a process
hierarchy (tree of processes).
▪ In UNIX, a process and all of its children and further descendants together
form a process group.
▪ When UNIX initializes itself when it is started, just after the computer is
booted, a special process, called init (“parent of all processes”), is present
in the boot image.
▪ When it starts running, it reads a file telling how many terminals there
are.
24
Process Hierarchies (cont.)
▪ Sooner or later the new process will terminate, usually due to one of the
following conditions:
1. Normal exit (voluntary).
2. Error exit (voluntary).
3. Fatal error (involuntary).
4. Killed by another process (involuntary).
26
Process Termination (cont.)
The parent is exiting, and the OS does not allow a child to continue if
▪ Some OSes do not allow child to exists if its parent has terminated.
If a process terminates (either normally or abnormally), then all its
children must also be terminated.
→ This phenomenon, referred to as cascading termination.
▪ The parent process may wait for termination of a child process by using
the wait() system call.
The wait() system call is passed a parameter that allows the parent to
obtain the exit status of the child.
This system call also returns the PID of the terminated child so that
the parent can tell which of its children has terminated:
pid_t pid;
int status;
pid = wait(&status);
28
Process Termination (cont.)
▪ A process that has terminated, but whose parent has not yet called
wait(), is known as a zombie process.
→ All processes transition to this state when they terminate, but
generally they exist as zombies only briefly.
→ Once the parent calls wait(), the PID of the zombie process and its
entry in the process table are released.
29
Process Termination (cont.)
30
The slides are adapted from: Abraham Silberschatz, Peter Baer
Galvin, and Greg Gagne, “Operating System Concepts”, Tenth
Edition
31
Pyetje dhe Diskutime ?
32