PROCESS
PRAISE THE LORD
1
Introduction
•Computers perform operations concurrently
– For example, compiling a program, sending a file to a printer, rendering
a Web page, playing music and receiving e-mail
• Processes enable systems to perform and track simultaneous activities
•Processes transition between process states
• Operating systems perform operations on processes such as creating,
destroying, suspending, resuming and waking
2
Addressing Space in
Process consist of
Text region - Stores the code that the
processor executes
Data region- Stores variables and dynamically
Process-Definition allocated memory
A program in execution
Stack region-Stores instructions and local variables
for active procedure calls
3
Addressing Space in
Process consist of
Text region - Stores the code that the
processor executes
Data region- Stores variables and dynamically
Process-Definition allocated memory
A program in execution
Stack region-Stores instructions and local variables
for active procedure calls
4
.
Running state - The process is
executing on a processor
Ready state - The process could
Process States execute on a processor if one were
available
Blocked state - The process is waiting for
some event to happen before it can
proceed
The OS maintains a ready list and a blocked list to store references to processes not running 5
PROCESS MANAGEMENT
•Operating systems provide fundamental services to processes including:
Destroying Resuming
processes processes
Suspending
Creating
processes
processes
Blocking Dispatching
processes processes
Changing a Waking up
process’s processes
priority
Interprocess communication (IPC) 6
Process States and State transitions
• Process states
– The act of assigning a processor to the first process on the
ready list is called dispatching
– The OS may use an interval timer to allow a process to run for
a specific time interval or quantum
– Cooperative multitasking lets each process run to completion
• State Transitions
– At this point, there are four possible state transitions
[Link] a process is dispatched, it transitions from ready to
running
[Link] the quantum expires, it transitions from running to
ready
[Link] a process blocks, it transitions from running to blocked
[Link] the event occurs, it transitions from blocked to ready
7
Process Control Block
8
Process Control Block
PCBs maintain information that the OS needs to manage the process
– Include information such as
Process • Scheduling Pointers to the process’s
child processes
identification priority
• Pointers to locate the
number (PID) • Credentials
process’s data and
• Process state • A pointer to the
instructions in memory
• Program process’s parent
• Pointers to allocated
counter process
resources
9
Process Operations
•A process may spawn a new process
•Parent process - The creating process
Stack region-Stores instructions and local variables
•Child process - The created process
for active procedure calls
•When a parent process is destroyed, operating
systems typically respond in one of two ways:
1. Destroy all child processes of that parent
2. Allow child processes to proceed independently of
their parents
1
0
SUSPEND AND RESUME
9
Context Switching
• Performed by the OS to stop
executing a running process and begin
executing a previously ready process
• Save the execution context of the
running process to its PCB
• Load the ready process’s execution
context from its PCB
• Require the processor to not perform
any “useful” computation
•OS must therefore minimize
context-switching time. 1
2
Interrupts
Interrupt Polling Interrupts in an operating system are signals that
interrupt the normal execution of a program to handle
1. Interrupts are signals 1. Polling involves important events.
generated by hardware continuously checking
The operating system may specify a set of instructions, called
or software indicating the status of a device or
an interrupt handler, to be executed in response to each type
that an event needs condition at regular of interrupt.
immediate attention. intervals.
2. Eliminates the need 2. Increases overhead A processor may generate an interrupt as a result of
executing a process's instructions (in which case it is often
for a processor to when complexity of
called a trap and is said to be synchronous with the
repeatedly poll devices system increases
operation of the process).
•Processor to repeatedly request the status of the device- Polling.
1
3
Interrupt Processing
•After receiving an interrupt, the processor completes execution of the
current instruction, then pauses the current process.
•The processor will then execute one of the kernel’s interrupt handling
functions
– The interrupt handler determines how the system should respond
– Interrupt handlers are stored in an array of pointers called the interrupt
vector
– After the interrupt handler completes, the interrupted process is
restored and executed or the next process is executed.
1
4
Interrupt Processing
•Interrupt line- Electrical connection between mainboard and [Link] becomes
active and informs processor when an event has occurred.
•Interrupt controller –Orders interrupts according to their priority so that important
interrupts are serviced first.
•IL after it is active the process completes the execution of the current instruction then
pauses the execution of the current process.
•To pause process execution, the processor must save enough information so that the
process can be resumed at the correct place and with the correct register information.
•The processor then passes control to the appropriate interrupt handler. Each type of
interrupt is assigned a unique value that the processor uses as an index into the interrupt
vector, which is an array of pointers to interrupt handlers.
1
• The Interrupt handler performs appropriate actions based on the type of interrupt. 5
INTERRUPT HANDLING
1
6
Interrupt Processing
Consider how the operating system and hardware interact in response to clock interrupts in
figure in previous slide.
At each timer interval, the interrupting clock generates an interrupt that allows the operating
system to execute to perform system management operations such as process scheduling.
In this case, the processor is executing process P1 (1) when the clock issues an interrupt (2).
Upon receiving the interrupt, the processor accesses the interrupt vector entry that corresponds
to the timer interrupt (3).
The processor then saves the process's execution context to memory (4) so that the P1's
execution context is not lost when the interrupt handler executes.
The processor then executes the interrupt handler, which determines how to respond to the
interrupt (5).
The interrupt handler may then restore the state of the previously executing process (P1) or call
the operating system processor scheduler to determine the "next“ process to run. In this case,
the handler calls the process scheduler, which decides that process P2, the highest-priority
waiting process, should obtain the processor (6).
1
The context for process P2 is then loaded from its PCB in main memory, and process P1's 5
execution context is saved to its PCB in main memory.
Interrupt & Exceptions classes
Interrupts Exceptions
Notify the processor that an event has occurred or that an external Indicate that an error has occurred, either the hardware or as
device’s status has changed a result of a software instruction
Generated by devices external to a processor Classified as faults, traps or aborts.
I/O - Signals sent to the CPU by I/O devices (like keyboard, mouse, Fault -Occurs when the CPU detects an error while
disk, printer, etc.) to get its attention when they are ready for data executing an instruction—but the error is recoverable. The
transfer or need CPU intervention CPU can often correct the problem or notify the operating
Timer -Generated by a hardware timer inside the CPU or system, then resume execution. Faults are synchronous
microcontroller. It tells the CPU that a specific amount of time has (they happen right at the time of instruction execution)
passed, so it can do time-based tasks. Trap - Allows user programs to switch to kernel mode to
Interprocessor – Allows one processor to send a message to another perform restricted operations, like reading a file or accessing
in multiprocessor system hardware.
Abort -triggered by serious, unrecoverable errors—usually
related to hardware or critical memory issues. Unlike
faults (which can be corrected) or traps (which are
intentional), aborts are fatal: the system cannot safely
continue execution.
Inter process communication
•Many operating systems provide mechanisms for inter
process communication (IPC)
•Processes must communicate with one another in
multi-programmed and networked environments
•For example, a Web browser retrieving data from a distant
server
•Essential for processes that must coordinate activities to
achieve a common goal.
Signals
• Signals are software interrupts that notify a process that an event has occurred.
• Signals do not allow processes to specify data to exchange with other processes.
• A system's signals depend on the OS and the software-generated interrupts
supported by a particular processor.
• When a signal occurs, the OS first determines which process should receive the signal
and how that process will respond to the signal.
• Processes may catch, ignore or mask a signal
i) Catching a signal involves specifying a routine that the OS calls when it
delivers the signal
ii) Ignoring a signal relies on the OS default action to handle the signal. A
common default action is to abort which causes the process to exit immediately.
Another common default action is called a memory dump, which is similar to aborting
iii) Masking a signal instructs the OS to not deliver signals of that type until the
process clears the signal mask
Message Passing
- Messages can be passed in one direction at a time
• One process is the sender and the other is the receiver
- Message passing can be bidirectional
• Each process can act as either a sender or a receiver
- Messages can be blocking or non blocking
• Blocking requires the receiver to notify the sender when the message is received
• Non blocking enables the sender to continue with other processing popular implementation is a
pipe
• Pipe - region of memory protected by the OS that serves as a buffer, allowing two or more
processes to exchange data.
• The OS synchronizes access to the buffer after a writer completes writing to the buffer (possibly
filling it), the OS pauses the writer's execution and allows a reader to read data from the buffer.
….contd
• In IPC in distributed systems transmitted messages can be flawed or lost
• Acknowledgement protocols confirm that transmissions have been properly received
• Timeout mechanisms retransmit messages if acknowledgements are not received.
• Message passing systems with retransmission capabilities can identify each new
message with a sequence number.
• The receiver can examine these numbers to be sure that it has received every message
and to re sequence out- of sequence messages.
• If an acknowledgment message is lost and the sender decides to retransmit, it assigns
the same sequence number to the retransmitted message as to the originally
transmitted one.
• The receiver detecting several messages with the same sequence number knows to
keep only one of them.
• Unambiguously named processes lead to incorrect message referencing
• Messages are passed between computers using numbered ports on which processes
listen, avoiding this problem
• Security is a significant problem so ensuring authentication is mandatory.