0% found this document useful (0 votes)
13 views41 pages

ch3 - Process

Chapter 3 of 'Operating System Concepts' introduces the concept of processes, which are programs in execution, and discusses their scheduling, creation, communication, and termination. It explains the different states a process can be in, the role of the Process Control Block (PCB), and the mechanisms for inter-process communication. Additionally, it covers process creation using system calls, the importance of process termination, and the distinction between independent and cooperating processes.

Uploaded by

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

ch3 - Process

Chapter 3 of 'Operating System Concepts' introduces the concept of processes, which are programs in execution, and discusses their scheduling, creation, communication, and termination. It explains the different states a process can be in, the role of the Process Control Block (PCB), and the mechanisms for inter-process communication. Additionally, it covers process creation using system calls, the importance of process termination, and the distinction between independent and cooperating processes.

Uploaded by

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

Chapter 3: Processes

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Objecti
ves
 To introduce the notion of a
process -- a program in execution,
which forms the basis of all
computation
 including
To describescheduling,
the variouscreation
features of
processes, and communication
and
termination,
 To describe
communication in client-
server systems

Operating System Concepts – 3. Silberschatz, Galvin and


Introduct
 ion
Process Manager Introduction:
• https://www.youtube.com/watch?v=bS3QuOQgUu8&list=
PLmbPuZ0NsyGS8ef6zaHd2qYylzsHxL63x&index=3

• https://www.youtube.com/watch?v=7FRW4iGjLrc&list=P
LmbPuZ0NsyGS8ef6zaHd2qYylzsHxL63x&index=4

 Early computer systems:


 Allowed only one program to be executed at a time
This program had a complete control over the system
and its resources
 Today:
 Multiple programs can be loaded into memory and
executed concurrently
Requires firmer control
Operating System Concepts – 3. Silberschatz, Galvin and
Process
Concept
 Textbook uses the terms job
interchangeably
and process almost
 An operating system executes a variety
of programs:
 Batch system – jobs
 Time-shared systems – user programs or
tasks
 Running processes are either:
 Operating system processes executing system
code
 User processes executing user code
 Process – a program in execution;
 Program (executable) – passive entity in the
disk
 Process – active entity
 Process execution must
Operating System Concepts – 3.
progress in Silberschatz, Galvin and
Process in
Memory
Usually temporary data
(such as function
parameters, return
 A process block addresses, and local
variables) – stored for a
short amount of time in
includes: memory
 Stack, heap, Text
and data section
Dynamically allocated
during
process run-time

Global variables

Compiled code of the


program

Operating System Concepts – 3.5 Silberschatz, Galvin and


Example: Memory Layout of a C
Program
Program and
 Two processesProcess
may be associated with the same
program: (Open multiple
windows of same web browser)
 Two separate execution sequences
 Text sections are equivalent, however data, heap
and stack sectionsProgram
vary (change from each other)

Difference
in size and
content

Difference in
size and
content

Difference
content program
counter
Operating System Concepts – program 3.7 Silberschatz, Galvin and
Process
State
 As a process executes, it
changes state
 new: The process is being
created
momentary

 running: Instructions
states

are being executed


 waiting: Theprocess is waiting
for some event to occur (e.g.,
I/O completion)
 ready: Theprocess is waiting
to be assigned to a
processor
How many processes can we have in
each status? The process has finished
 terminated:
Operating System Concepts – 3.8 Silberschatz, Galvin and
Diagram of
Process State

Operating System Concepts – 3.9 Silberschatz, Galvin and


Process Control
Block (PCB)
It is store in a Text Section. Contains various information
associated with each process
 Process state
 Program counter – address of next instruction
 CPU registers
 CPU scheduling
information –e.g., process
priority, pointers to scheduling queues
 Memory-management
information – value
of
base and limit registers, page or
segment tables
 Accounting information – need
CPU(real time, time used,
Operating System Concepts – 3. time Silberschatz, Galvin and
CPU Switch From Process
 to ofProcess
The objective time-sharing is to switch the CPU among processes so frequently
that users can interact with each program while it is running

Operating System Concepts – 3. Silberschatz, Galvin and


Process Scheduling
 The goal Queues
of multiprogramming – to have some
process running at all times to maximize CPU
utilization
 To meet this goal we use a process scheduler
 Job queue – set of all processes in the system (this is
where
all processes go upon entering the system)
 Ready queue – set of all processes residing in main
memory, ready and waiting to execute – usually a linked
list (why?)
 Device queues – set of processes waiting for an I/O
device
 Processes migrate among the various queues

Operating System Concepts – 3. Silberschatz, Galvin and


Ready Queue And Various I/O
Device Queues

Operating System Concepts – 3. Silberschatz, Galvin and


Representation of Process
Scheduling
Queuing
Job queue Diagram end

Wait for the child to finish execution

Operating System Concepts – 3. Silberschatz, Galvin and


Schedul
 Long-term ers
scheduler (or
job scheduler) –
selects which processes should be brought into
the ready queue – loads processes from disk to
memory
 Short-term scheduler (or CPU scheduler) –
selects which process should be executed next
(from the ready queue) and allocates CPU

Short-
term
Long-term schedul
scheduler er

Operating System Concepts – 3. Silberschatz, Galvin and


Schedulers
(Cont)
 Short-term scheduler is invoked
very
(milliseconds)frequently
 (must be create
fast, substantial
otherwise overhead) –
simple methods like
priority scheduling FCFS,

 Long-term scheduler is invoked


very infrequently (seconds,
minutes)  (may be slow)

 The long-term scheduler


controls the degree of
multiprogramming (number of processes in
memory)
Operating System Concepts – 3. Silberschatz, Galvin and
Schedulers
 (Cont.)
Processes can be described as either:
 I/O-bound process – spends more time doing I/O than
computations,
many short CPU bursts (e.g., surfing the web, copying large
files)
 CPU-bound process – spends more time doing
computations; few very long CPU bursts (e.g., calculating
Pi, or some mathematical or statistical calculations)
 It is important for the long-term scheduler to
select a good process mix of I/O-bound and
CPU-bound processes
What will happen to the ready
queue and I/O queue: What if we have no
 If all processes are I/O long-
bound? term scheduler?
 If all processes are CPU
bound?
Operating System Concepts – 3.
Context
 When CPU Switchto
switches
another process, the
system must save the state of the old process
and load the saved state (restore the state)
for the new process via a context switch
 Context of a process represented in the PCB

 Context-switch time is overhead because the

system does no useful work while switching.

 Switching speed varies from machine to


machine depending

upon the memory speed, the number of


registers.
Operating System Concepts – 3. Silberschatz, Galvin and
Context
Switch

Explain the context


Operating System Concepts –
switching3. Silberschatz, Galvin and
Process
Creation

What is
fork?

Operating System Concepts – 3. Silberschatz, Galvin and


Process
 Creation
Creating a process – using create process
(fork) system call
 Parent process create children processes,
 which, in turn
Generally, create
process identified and
other processes,
identifier
managed via forming
(pid) a a tree of processes
process
 Resource sharing (cpu time, memory, I/O devices)

Parent and children share all


resources
Children share subset of parent’s
resources
Parent and child share no resources
 One process can overload the system by creating
Operating Systemmany
Concepts processes
– 3. Silberschatz, Galvin and
Process
Creation
Root parent process for all user
processes

Netwo Memo File


rk ry syste
servic mng. m
es mng.

A tree of processes on a
typical Solaris
Operating System Concepts – 3. Silberschatz, Galvin and
Process Creation
 Execution (Cont)
 Parent and children execute concurrently
 Parent waits until children terminate
 Address space
 Child address is duplicate of parent – same program and
data
 Child has a new program loaded into it (different from the
parent’s program)

 UNIX examples
 fork system call creates new process
 Parent’s address space is duplicated
 Both processes resume execution at the instruction
after the fork()
 exec system call used after a fork to replace the process’
memory space with a new program
 Wait() – takes the process out o f the ready queue
Operating System Concepts – 3.
Process
• Creation
Both processes (the parent and the child) continue execution at the instruction after
the fork(), with one difference: the return code for the fork() is zero for the new
(child) process, whereas the (nonzero) process identifier of the child is returned to
the parent.

• The parent can then create more children; or, if it has nothing else to do while
the child runs, it can issue a wait() system call to move itself off the ready
queue until the termination of the child

Operating System Concepts – 3. Silberschatz, Galvin and


Process
Termination
1. When a process executes its last statement, it asks the
operating system to delete it using (exit) system call
 Output data from child to parent (via wait)
 All process’ resources are de-allocated by operating
system

2. Parent may terminate execution of children processes


(abort)
 Reason 1: Child has exceeded the usage of allocated
resources
 Reason 2: Task assigned to child is no
longer required (the browser
example)
 Reason 3: If parent is exiting
 Some operating system do not allow child to continue
if its parent terminates
– All children terminated - cascading
Silberschatz, Galvin and
Operating System Concepts – 3.
Process Termination
 The parent process may wait for termination of a child process by using the
wait()system call. The call returns status information and the pid of the
terminated process
pid = wait(&status);
 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 process identifier of the zombie
process and its entry in the process table are released.

 If a parent terminated without invoking wait(),leaving its child as an orphan.


This child process is called an orphan
 Traditional UNIX systems addressed this scenario by assigning the init (or systemd)
process as the new parent to orphan processes (init serves as the root of the process
hierarchy in UNIX systems.)
 The init process periodically invokes wait(), thereby allowing the exit status of any
orphaned process to be collected and releasing the orphan’s process identifier and
process-table entry.

Operating System Concepts – 10th Edition 3.28 Silberschatz, Galvin and Gagne ©2018
Interprocess
 Communication
Processes within a system may be independent or
cooperating
 Independent processes cannot affect or be affected by other
running processes
 Cooperating processcan affect or be affectedby other
processes, including sharing data

 Reasons for cooperating processes:


 Information sharing – e.g., shared file requires
concurrent access
 Computation speedup – parallel execution (works only
with multi-processor system)
 Modularity – dividing the system into several modules
(processes or threads) that will need to work together
 Convenience – user can work on several applications at
the same time

 Cooperating processes need Inter-Process-


Communication (IPC)
Operating System Concepts – 3.
Communications
Models

• Better for exchanging small • Fast


messages (no conflicts need to er
be avoided)
• Easier to implement

Operating System Concepts – 3. Silberschatz, Galvin and


Communications Models

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

• Faster since message-passing systems are


• Useful for exchanging smaller typically implemented using system calls
amounts of data (no conflicts and thus require the more time-consuming
need to be avoided) task of kernel intervention. In shared-
• Easier to implement in a memory systems, system calls are required
distributed system than shared only to establish shared memory regions.
memory Once shared memory is established, all
accesses are treated as routine memory
accesses, and no assistance from the kernel
is required.
Shared-Memory
 Producer-Consumer Systems
Problem:
o Paradigm for cooperating processes, where a producer
process produces information that is consumed by a
consumer process (e.g., compiler produces assembly code,
consumed by the assembler)

o Shared memory solution:

• unbounded-buffer places no practical limit on the size of the buffer:


 Producer never waits (always produce new items).
 Consumer waits if there is no buffer to consume

• bounded-buffer assumes that there is a fixed buffer size


 Producer must wait if all buffers are full
 Consumer waits if there is no buffer to consume

Operating System Concepts – 3.


IPC– Message Passing
 It is a mechanism for processes to communicate and to
synchronize their actions without sharing the same address
space.
 It is useful in a distributed environment, where the
communicating processes may reside on different
computers connected by a network.
 A message-passing facility provides two operations:
 send(message) – message size can be fixed or variable
 receive(message)

 If P and Q wish to communicate, they need to:


 establish a communication link between them. This
link can be implemented logically by several methods:
 Direct/Indirect communication
 Synchronous / Asynchronous communication
 Automatic / explicit buffering
 exchange messages via send/receive
 Implementation of communication link
 physical (e.g., shared memory,
Operating System Concepts – 3. hardware Silberschatz,
bus) Galvin and
Direct
Communication
 Processes must name each other explicitly during
communication:
 send (P, message) – send a message to process P

receive(Q, message) – receive a message from
process Q
 Properties of this communication link
o Links are established automatically
o The link may be unidirectional, but is usually bi-
directional
o A link is associated with exactly one pair of
communicating processes (2 processes only)
o Between each pair there exists exactly one link

Operating System Concepts – 3. Silberschatz, Galvin and


Direct Communication

 This scheme exhibits symmetry in addressing; that is, both the sender
process and the receiver process must name the other to communicate.

 A variant of this scheme employs asymmetry in addressing. Here, only the


sender names the recipient; the recipient is not required to name the sender.

 The disadvantage in both of these schemes (symmetric and asymmetric) is


the limited modularity of the resulting process definitions.

Operating System Concepts – 10th Edition 3.35 Silberschatz, Galvin and Gagne ©2018
Indirect
 Messages Communication
are sent and received from
mailboxes (also referred to as ports)
 Each mailbox has a unique id
 Processes can communicate only if they share a mailbox

 Primitives are defined as:


 send(A, message) – send a message to mailbox A
 receive(A, message) – receive a message from
mailbox A

 Properties of communication link


 A Link is established only if processes have a shared
mailbox
 Link may be unidirectional or bi-directional
 Each pair of processes may share several
communication
Operating System Concepts – links 3. Silberschatz, Galvin and
Indirect
Communication
 Operations
 create a new mailbox
 send and receive messages
through mailbox
 destroy a mailbox

Operating System Concepts – 3. Silberschatz, Galvin and


Indirect
Communication
 Mailbox sharing
 P1, P2, and P3 share
mailbox A
 P1, sends; P2 and P3
receive
Who gets the
 Solutions
message?
 Allow a link to be associated with at most two processes
 Allow only one process at a time to execute a receive
operation
 Allow the system to select arbitrarily the receiver.
Sender is notified who
the receiver was
Operating System Concepts – 3. Silberschatz, Galvin and
Synchroniza
tion
 Message passing may be either blocking or non-
blocking

 Blocking is considered synchronous


 Blocking send : the sender is blocked until the
message is received
 Blocking receive : the receiver is blocked until a
message is available

 Non-blocking is considered asynchronous


 Non-blocking send : the sender sends the message
andConcepts
Operating System continue
– 3.
Bufferi
ng
 Whether the communication is direct or
indirect, messages must reside in a
temporary queue (buffer). This queue can
be implemented in one of three ways:
1.Zero capacity – no messages can wait in
queue. Sender must block until recipient
receives the message. Sender must wait
for receiver (rendezvous)
2.Bounded capacity – finite length of n
messages.
Sender must wait if the link
(buffer/queue) is full
3.Unbounded capacity – infinite length.
Sender never waits
Operating System Concepts – 3. Silberschatz, Galvin and
End of Chapter 3

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018

You might also like