CS 31: Intro To Systems Processes: Kevin Webb Swarthmore College April 1, 2014
CS 31: Intro To Systems Processes: Kevin Webb Swarthmore College April 1, 2014
CS 31: Intro To Systems Processes: Kevin Webb Swarthmore College April 1, 2014
Processes
Kevin Webb
Swarthmore College
April 1, 2014
Reading Quiz
Anatomy of a Process
Abstraction of a running program
a dynamic program in execution
Basic operations
Suspend/resume (context switch)
Start (spawn), terminate (kill)
Timesharing
P1
P2
P3
P1
P2
P3
P1
P2
P3
quantum
time
Ready
Running
preempt
wake up
sleep
Blocked
State transitions
Dispatch: allocate the CPU to a process
Preempt: take away CPU from process
Sleep: process gives up CPU to wait for event
Wakeup: event occurred, make process ready
State
Other info
1534
Ready
Saved context,
34
Running
487
Ready
Saved context,
Blocked
Condition to unblock,
Multiprogramming
Given a running process
At some point, it needs a resource, e.g., I/O device
If resource is busy (or slow), process cant proceed
Voluntarily gives up CPU to another process
Context Switching
Allocating CPU from one process to another
First, save context of currently running process
Next, load context of next process to run
Context Switching
Allocating CPU from one process to another
First, save context of currently running process
Next, load context of next process to run
In hardware
Switch from user to kernel mode: amplifies power
Go to fixed kernel location: interrupt/trap handler
Multiprogramming
Given a running process
At some point, it needs a resource, e.g., I/O device
If resource is busy (or slow), process cant proceed
Voluntarily gives up CPU to another process
Common Policies
Details beyond scope of this course (Take OS)
Different classes of processes
Those blessed by administrator (high/low priority)
Everything else
Common Policies
Special class gets special treatment (varies)
Everything else: roughly equal time quantum
Round robin
Give priority boost to processes that frequently
perform I/O
Why?
Linuxs Policy
(Youre not responsible for this.)
Managing Processes
Processes created by calling fork()
Spawning a new process
fork()
System call (function provided by OS kernel)
Creates a duplicate of the requesting process
Process is cloning itself:
CPU context
Memory address space
OS
Text
Data
Heap
OS
Text
Data
Heap
OS
Text
Data
Heap
Stack
Stack
Stack
A.6
B.8
C.12
D.16
E.18
exec()
Family of functions (execl, execlp, execv, ).
Replace the current process with a new one.
Loads program from disk:
Old process is overwritten in memory.
Does not return unless error.
To be continued