0% found this document useful (0 votes)
82 views27 pages

OS Ch03

Uploaded by

Kooky Messi
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)
82 views27 pages

OS Ch03

Uploaded by

Kooky Messi
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/ 27

Operating Systems

Chapter 3: Processes

Dr. Ahmed Hagag


Scientific Computing Department,
Faculty of Computers and Artificial Intelligence
Benha University
2019
Chapter 3: Processes

• Process Concept
• Process Scheduling
• Operations on Processes
• Interprocess Communication

©Ahmed Hagag Operating Systems 2


Process Concept (1/3)

Program vs. Process


• A program is a passive entity such as the file that
contains the list of instructions stored on a disk always
referred to as an executable file.
• A program becomes a process when an executable file is
loaded into the memory and then becomes an active
entity.

©Ahmed Hagag Operating Systems 3


Process Concept (2/3)

• The fundamental task of any operating system is the


process management.
• Processes include not only a text but also include a set of
resources such as open files and pending signals.
Processes also contain internal kernel data, processor
state, an address space, and a data section.

©Ahmed Hagag Operating Systems 4


Process Concept (3/3)

• OS must allocate resources to processes, enable sharing


of information, protect resources, and enable the
synchronization among processes.

©Ahmed Hagag Operating Systems 5


Process Elements (1/2)

• Segments of a process represents the following


components:
➢ Text Section: the program code. This is typically read-only,
and might be shared by a number of processes.
➢ Data Section: containing global variables.
➢ Heap: containing memory dynamically allocated during run
time.
➢ Stack: containing temporary data.
• Function parameters, return addresses, local variables.

©Ahmed Hagag Operating Systems 6


Process Elements (2/2)

• Process in Memory

©Ahmed Hagag Operating Systems 7


Process Control Block (PCB) (1/2)

• For better control of processes,


operating systems need to
consider their dynamic behaviors.
• Each process is represented in the
OS by a Process Control Block
(PCB).

©Ahmed Hagag Operating Systems 8


Process Control Block (PCB) (2/2)

• Process Control Block (PCB) (1/3)


➢ Process identification information
▪ Process identifier: numeric identifiers represent the
unique process identifier
▪ User identifier: the user who is responsible for the job).
▪ Identifier of the parent process that created this process.

©Ahmed Hagag Operating Systems 9


Process Control Block (PCB) (2/2)

• Process Control Block (PCB) (2/3)


➢ Processor state Information
▪ Process state – running, waiting, etc
➢ Program counter
▪ location of instruction to next execute
➢ CPU registers
▪ contents of all process-centric registers

©Ahmed Hagag Operating Systems 10


Process Control Block (PCB) (2/2)

• Process Control Block (PCB) (3/3)


➢ CPU scheduling information
▪ priorities, scheduling queue pointers
➢ Memory-management information
▪ memory allocated to the process
➢ Accounting information
▪ CPU used, clock time elapsed since start, time limits
➢ I/O status information
▪ I/O devices allocated to process, list of open files
©Ahmed Hagag Operating Systems 11
Process State (1/3)

• As a process executes, it changes state


➢ new: The process is being created
➢ running: Instructions are being executed
➢ waiting: The process is waiting for some event to occur
➢ ready: The process is waiting to be assigned to a processor
➢ terminated: The process has finished execution

©Ahmed Hagag Operating Systems 12


Process State (2/3)

• Diagram of Process State

©Ahmed Hagag Operating Systems 13


Process State (3/3)

©Ahmed Hagag Operating Systems 14


Process State (3/3)

©Ahmed Hagag Operating Systems 15


Process State (3/3)

©Ahmed Hagag Operating Systems 16


Process State (3/3)

©Ahmed Hagag Operating Systems 17


Process State (3/3)

©Ahmed Hagag Operating Systems 18


Process State (3/3)

©Ahmed Hagag Operating Systems 19


CPU Switch From Process to Process

©Ahmed Hagag Operating Systems 20


Process Scheduling (1/2)

• Job queue – set of all processes in the system


• Ready queue – set of all processes residing in main memory,
ready and waiting to execute
• Device queues – set of processes waiting for an I/O device
• Processes migrate among the various queues

©Ahmed Hagag Operating Systems 21


Process Scheduling (2/2)

©Ahmed Hagag Operating Systems 22


Schedulers (1/2)

• Short-term scheduler (or CPU scheduler)


➢ Selects which process should be executed next and allocates
CPU.
➢ Invoked frequently (milliseconds) → (must be fast).
• Long-term scheduler (or job scheduler)
➢ Selects which processes should be brought into the ready
queue.
➢ Invoked infrequently (seconds, minutes) → (may be slow).
➢ Controls the degree of multiprogramming.

©Ahmed Hagag Operating Systems 23


Schedulers (2/2)

• Medium-term scheduler
➢ Can be added if degree of multiple programming needs to
decrease
➢ Remove process from memory, store on disk, bring back in
from disk to continue execution: swapping

©Ahmed Hagag Operating Systems 24


Interprocess Communication (1/2)

• Processes within a system may be independent or


cooperating
• Cooperating process can affect or be affected by other
processes, including sharing data.
• Cooperating processes need interprocess communication
(IPC)
• Two models of IPC:
➢ Shared memory
➢ Message passing

©Ahmed Hagag Operating Systems 25


Interprocess Communication (2/2)

(a) Message passing. (b) shared memory.

©Ahmed Hagag Operating Systems 26


Dr. Ahmed Hagag
[email protected]
https://www.youtube.com/channel/UCzYgAyyZTLfnLFjQexOKxbQ

https://www.facebook.com/ahmed.hagag.71/

You might also like