Os Notes
Os Notes
• Process Concept
• Process Scheduling
• Operation on Processes
• Cooperating Processes
• Threads
• First Programming Assignment
Applied Operating System Concepts 1.1 Silberschatz, Galvin, and Gagne 1999
Process Concept
• An operating system executes variety of
programs:
– Batch system – jobs
– Time-shared systems – user programs
• Textbook uses the terms job and process.
• Process – a program in execution; process
execution must progress in sequential fashion.
• A process includes program counter, stack, data
section
Applied Operating System Concepts 1.2 Silberschatz, Galvin, and Gagne 1999
Enter Exit
Not
Running
Running Pause
Pause
Applied Operating System Concepts 1.3 Silberschatz, Galvin, and Gagne 1999
1
Dispatcher
Applied Operating System Concepts 1.4 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.5 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.6 Silberschatz, Galvin, and Gagne 1999
2
OS Control Structures
Memory Tables
Process Image
Memory
I/O Tables User data
I/O User program
System stack
File File Tables PCB
Processes
Primary Table
Process 1
Process 2
…
Process N
Applied Operating System Concepts 1.7 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.8 Silberschatz, Galvin, and Gagne 1999
Memory Tables
Applied Operating System Concepts 1.9 Silberschatz, Galvin, and Gagne 1999
3
I/O Tables
Applied Operating System Concepts 1.10 Silberschatz, Galvin, and Gagne 1999
File Tables
• Existence of files
• Location on secondary memory
• Current Status
• Attributes
• Sometimes this information is maintained by a
file-management system
Applied Operating System Concepts 1.11 Silberschatz, Galvin, and Gagne 1999
Process Table
Applied Operating System Concepts 1.12 Silberschatz, Galvin, and Gagne 1999
4
Process Control Block (PCB)
Information associated with each process.
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Applied Operating System Concepts 1.13 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.14 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.15 Silberschatz, Galvin, and Gagne 1999
5
Process Scheduling Queues
• 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.
• Process migration between the various
queues.
Applied Operating System Concepts 1.16 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.17 Silberschatz, Galvin, and Gagne 1999
Representation of Process
Scheduling
Applied Operating System Concepts 1.18 Silberschatz, Galvin, and Gagne 1999
6
Schedulers
Applied Operating System Concepts 1.19 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.20 Silberschatz, Galvin, and Gagne 1999
Schedulers (Cont.)
• Short-term scheduler invoked frequently (ms)
⇒ (must be fast).
• Long-term scheduler invoked infrequently
(seconds, minutes) ⇒ (may be slow).
• The long-term scheduler controls the degree of
multiprogramming.
• Processes can be described as either:
– I/O-bound process
– CPU-bound process
Applied Operating System Concepts 1.21 Silberschatz, Galvin, and Gagne 1999
7
Context Switch
Applied Operating System Concepts 1.22 Silberschatz, Galvin, and Gagne 1999
Process Creation
• Parents create children; results in a tree of
processes.
• 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 children terminate.
Applied Operating System Concepts 1.23 Silberschatz, Galvin, and Gagne 1999
Applied Operating System Concepts 1.24 Silberschatz, Galvin, and Gagne 1999
8
A Tree of Processes On A Typical
UNIX System
Applied Operating System Concepts 1.25 Silberschatz, Galvin, and Gagne 1999
Process Termination
• Process executes last statement (exit).
– Output data from child to parent (via wait).
– resources 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.
– Parent is exiting.
✴ Operating system does not allow child to continue
✴ Cascading termination.
Applied Operating System Concepts 1.26 Silberschatz, Galvin, and Gagne 1999
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
Applied Operating System Concepts 1.27 Silberschatz, Galvin, and Gagne 1999
9
Producer-Consumer Problem
Applied Operating System Concepts 1.28 Silberschatz, Galvin, and Gagne 1999
Bounded-Buffer – Shared-Memory
Solution
• Shared data
var n;
type item = … ;
var buffer. array [0..n–1] of item;
in, out: 0..n–1;
• Producer process
repeat
…
produce an item in nextp
Applied Operating System Concepts
… 1.29 Silberschatz, Galvin, and Gagne 1999
hil i 1 d d
Bounded-Buffer (Cont.)
• Consumer process
repeat
while in = out do no-op;
nextc := buffer [out];
out := out+1 mod n;
…
consume the item in nextc
Applied Operating System Concepts … 1.30 Silberschatz, Galvin, and Gagne 1999
10
Exception Conditions – Error
Recovery
• Process terminates
• Lost messages
• Scrambled Messages
Applied Operating System Concepts 1.31 Silberschatz, Galvin, and Gagne 1999
Created
Preempted
return
enough not enough memory
to user
memory (swapping system only)
User
Running preempt Ready to Run
swap out
return reschedule Ready to Run Swapped
process in Memory
swap in
system call,
interrupt Kernel
Running
Applied Operating System Concepts 1.32 Silberschatz, Galvin, and Gagne 1999
11