Professional Documents
Culture Documents
1
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018
Chapter Outline
1.2
▪ Process Definition
▪ Scheduling Processes
▪ What Do Processes Do?
▪ Inter-process Communication
2
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.3
Chapter Objectives
▪ Identify the separate components of a process and
illustrate how they are represented and scheduled
in an operating system.
▪ Describe how processes are created and
terminated in an operating system, including
developing programs using the appropriate system
calls that perform these operations.
▪ Describe and contrast interprocess communication
using shared memory and message passing.
▪ Design programs that uses pipes and POSIX
shared memory to perform interprocess
communication
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.4
Process
A process is :
• An instance of a program in execution
• An asynchronous activity
• The “animated spirit” of a procedure
• The “locus of control” of a procedure in execution
• The “dispatch able” unit
• An unit of work individually schedulable by an operating system.
Formally, we can define a process is an executing program, including
the current values of the program counter, registers, and variables. The
subtle difference between a process and a program is that the program is a
group of instructions whereas the process is the activity.
A program is passive; a process is active.
4
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.5
Process States
▪ Let us start with these states:
• The Running state
The process that is executing on the CPU is in the Running state
6
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
7
1.7
8
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.9
11
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
12
1.12
Scheduling Components
PROCESSES Context Switch
The act of Scheduling a process means changing the active
PCB pointed to by the CPU. Also called a context switch.
• save entire context into PCB, load new context from other PCB,
update process state.
Schedulers
Long-term scheduler (or Job scheduler) –
Schedulers (Cont.)
▪Short-term scheduler is invoked very frequently (milliseconds)
(must be fast)
Process Creation
• A process may create several new processes, via a create-process system call,
during execution.
• Parent process creates children processes, which, in turn create other processes,
forming a tree of processes.
• Resource sharing, such as CPU time, memory, files, I/O devices …
22
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.23
• UNIX examples
– fork system call creates new process
– execve system call used after a fork to replace the process
memory space with a new program.
23
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.24 Process Creation
int main()
{
pid_t pid; /* C Program Forking Separate Process
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}
24
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.25
25
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.26
Process Termination
▪ Process executes last statement and asks the operating system to
delete it (exit)
• Output data from child to parent (via wait)
• Process’ resources are de-allocated by operating system
▪ Parent may terminate execution of children processes (abort)
—Child has exceeded allocated resources
—Task assigned to child is no longer required
• If parent is exiting
Some operating system do not allow child to continue if its parent terminates
26
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.27
Threads
▪Process creation is heavy-weight while thread creation is light-weight
– Threads run within application
▪ Multiple tasks with the application can be implemented by separate threads
❑Update display
❑Fetch data
❑Spell checking
❑Answer a network request
▪ Can simplify code, increase efficiency
▪ Kernels are generally multithreaded.
• A traditional or heavyweight process is equal to a task with one thread.
27
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.28
Benefits
Responsiveness
Resource Sharing
Economy
Scalability
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.29
Cooperating Processes
▪ Independent process cannot affect or be
affected by the execution of another process
▪ Cooperating process can affect or be
affected by the execution of another process
▪ Advantages of process cooperation
• Information sharing
• Computation speed-up
• Modularity
• Convenience
29
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.30
Synchronization
▪ Message passing may be either blocking or non-blocking
▪ Blocking is considered synchronous
• Blocking send has the sender block until the message
is received
• Blocking receive has the receiver block until a
message is available
▪ Non-blocking is considered asynchronous
• Non-blocking send has the sender send the message
and continue
• Non-blocking receive has the receiver receive a valid
message or null
30
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.31
Interproces Communication
Mechanism for processes to communicate and to
synchronize their actions.
• IPC is best provided by message-passing systems.
• IPC facility provides two operations:
– send(message) – message size fixed or variable
– receive(message)
• If P and Q wish to communicate, they need to:
– establish a communication link between them
– exchange messages via send/receive
• Processes can communicate in two ways:
– Direct communication
– Indirect communication
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.32
Direct Communication
Processes must name each other explicitly:
– send (P, message) – send a message to process P
– receive(Q, message) – receive a message from process Q
• Properties of communication link
– Links are established automatically.
– A link is associated with exactly one pair (two processes)
of communicating processes.
– Between each pair there exists exactly one link.
– The link may be unidirectional, but is usually
bidirectional
Disadvantage of Direct Communication:
The names of processes must be known - they can't be easily
changed since they are explicitly named in the send and receive.
32
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.33 Indirect Communication
Messages are directed and received from mailboxes (also referred
to as ports).
– Each mailbox has a unique id.
– Processes can communicate only if they share a mailbox.
• Properties of communication link:
– Link established only if processes share a common mailbox
– A link may be associated with many processes.
– Each pair of processes may share several communication
links.
– Link may be unidirectional or bi-directional.
• The O.S. provides a mechanism that allows a process:
– create a new mailbox
– send and receive messages through mailbox
– destroy a mailbox
33
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.34 Indirect Communication (Continued)
Example: Mailbox sharing
– P1, P2, and P3 share mailbox A.
– P1, sends; P2 and P3 receive.
– Who gets the message?
• Solutions:
– 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
34
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.35
Q&A
Thank You
35
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.36
Buffering
Queue of messages attached to the link;
implemented in one of three ways.
1. Zero capacity – 0 messages.
Sender must wait for receiver (rendezvous).
2. Bounded capacity – finite length of n messages.
Sender must wait if link full.
3. Unbounded capacity – infinite length.
Sender never waits.
36
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.37
QA
1.Process is
a)program in High level language kept on disk
b)contents of main memory
c) A program in execution d) Job in secondary memory
2. Which of the following is not the state of a process ?
a) New b) Old c) Waiting d) Running
3.What is the ready state of a process?
a) when process is scheduled to run after some execution
b) when process is unable to run until some task has been
completed
c) when process is using the CPU
d) none of the mentioned
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.38 QA
4.What is interprocess communication?
a) communication within the process
b)communication between two process
c) communication between two threads of same process
d) none mentioned
5.The address of the next instruction to be executed by the
current process is provided by the
a) CPU registers b) program counter
c) process stack d) pipe
6.In Unix, Which system call creates the new process?
a) fork b) create c) new d) none of the mentioned
38
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.39
QA
7. A Process Control Block(PCB) does not contain which
of the following :
a) Code b) Stack c) Program Counter
d) bootstrap program
8. The Process Control Block is :
a) Process type variable b) Data Structure
c) a secondary storage section d) a Block in memory
9. The degree of multi-programming is :
a) No. of processes executed per unit time
b) No. of processes in the ready queue
c) No. of processes in the I/O queue
d) No. of processes in memory
QA
10. The child process completes execution, but the parent
keeps executing, then the child process is known as :
a) Orphan b) Zombie c) Body d) Dead
11. Context switch is involved in
a) Switching computer on b) Switching CPU from one
process to another
c) Switching a process on d) None of these
12. Scheduling a process from Ready Queue to CPU is done
by
a) Short term scheduler b) Midlle term Scheduler
c) Long-Term Scheduler d) Dispatcher
QA
41
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning