Lecture 5-6 ch3 Precesses
Lecture 5-6 ch3 Precesses
Lecture 5
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 3: Processes
Process Concept
Process Scheduling
Operations on Processes
Interprocess Communication
Examples of IPC Systems
Communication in Client-Server Systems
Operating System Concepts – 9th Edition 3.2 Silberschatz, Galvin and Gagne ©2013
Objectives
To introduce the notion of a process -- a program in
execution, which forms the basis of all computation
To describe the various features of processes, including
scheduling, creation and termination, and communication
To explore interprocess communication using shared memory
and message passing
To describe communication in client-server systems
Operating System Concepts – 9th Edition 3.3 Silberschatz, Galvin and Gagne ©2013
Process
A program in execution
An instance of a program running on a computer
The entity that can be assigned to and executed on a processor
A unit of activity characterized by the execution of a sequence of
instructions, a current state, and an associated set of system instructions
4
Process Management
Program code 7
Process States
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 (such as I/O)
ready: The process is waiting to be assigned to a processor
terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Each process is represented in the OS by PCB. It is data structure called
the process control block (PCB) that holds all this stuff
The PCB is identified by an integer process ID (PID)
Only one PCB active at a time
OS keeps all of a process’s hardware execution state in the PCB when the
process isn’t running
PC, SP, registers, etc.
Process Control Block (PCB)
Information associated with each process
Process state: new, ready, running, waiting, halted.
Program counter: the address of the next instruction to be
executed for this process.
CPU registers: accumulators, Index registers, SP,.. Must be saved
when an interrupt occurs to allow the process to be continued
correctly afterward.
CPU scheduling information : ex. process priority.
Memory-management information : ex. the value of the base and
limit registers.
Accounting information : ex. process number.
I/O status information : ex. List of I/O devices allocated to the
process , list of open files.
CPU Switch From Process to Process
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
The act of switching the CPU from one process to another
is called a context switch.
Context switching is an essential part of a multitasking
operating system features.
CPU Switch From Process to Process
Process Scheduling Queues
The process scheduler selects an available process( from a set of several
available processes) for program execution on the CPU.
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 (each device
has its own device queue)
Processes migrate among the various queues
Representation of Process Scheduling
(queuing diagram)
Schedulers
Long-term scheduler (or job scheduler) – selects which processes
should be brought into the ready queue and load them into memory.
Short-term scheduler (or CPU scheduler) – selects which process should
be executed next and allocates CPU
Medium Term Scheduler( swapping scheduler ) - It removes the
processes from the memory. It reduces the degree of multiprogramming
Short-term scheduler is invoked very frequently (milliseconds) (must
be fast)
Long-term scheduler is invoked very infrequently (seconds, minutes)
(may be slow)
The long-term scheduler controls the degree of multiprogramming (the
number of processes in memory).
Operations on Processes
1-Process Creation
A process may create several new processes, via a create-process system call.
Parent process create children processes, which, in turn create other
processes, forming a tree of processes
Most O.S. identify process and managed via a unique process identifier (pid)
(an integer number).
A process will need resources (CPU time, memory , files,…) to accomplish its
task. When a process creates a subprocess, that subprocess may be able to
obtain its resources directly from O.S. or
Resource sharing
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until some or all children terminate
Process Creation (Cont)
Address space
Child duplicate of parent (it has the same program and data as the parent).
Child has a new program loaded into it
UNIX examples
fork system call creates new process (copy of the address space of the original
process).
exec system call used after a fork to replace the process’ memory space with a
new program
Wait() the parent waits for the child process to complete.
Exit().
A tree of processes on a typical Linux
2- Process Termination
A Process terminates when it finishes executing its last statement and
asks the operating system to delete it by using the (exit) system call.
Return a value from child to parent (via wait)
Process’ resources are deallocated 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
All children terminated - cascading termination
Interprocess Communication
Processes executing concurrently :
Independent :process cannot affect or be affected by the execution of another
process
Cooperating :process can affect or be affected by other processes, including
sharing data
Reasons for cooperating processes:
Information sharing (ex.: shared file)
Computation speedup (break up process into sub tasks to run faster and can be
achieved only if the computer has multiple processing elements – CPUs or I/O
channels)
Modularity (dividing system functions into separate processes or threads)
Convenience (individual user may work on many tasks at the same time could be
editing, printing, and compiling in parallel)
Interprocess Communication
Mechanism for processes to communicate and to synchronize their
actions
Two models of IPC:
1) shared memory
cooperating processes exchange information by reading and writing data
to a shared region of memory.
* allows maximum speed and convenience of communication.
* faster than message passing (system calls only to establish the region. All
accesses are routine memory accesses, no assistance from the kernel).
2) message passing
messages are exchanged between the cooperating processes
* useful for exchanging smaller amounts of data.
* easier to implement than is shared memory for intercomputer communications.
* implemented using system calls (more time, kernel intervention).
Communications Models