CS170 Lecture notes -- Processes and You
The purpose of this lecture is to make the process abstraction a little
clearer. We'll talk about what the book has to say. These lecture notes are
intended to serve as an outline of the important issues.
Process Makeup
- registers, text, data, stack segments
- file descriptors, I/O ports, etc.
Process Execution State
- scheduler moves process between execution "states"
- a processes state defines what it can do
- states are (roughly)
- new (waiting to be run first time)
- running
- ready (runnable)
- blocked (waiting)
- done
Process Control Block
- an in-memory record that describes the process to the operating system
- with the PCB, the OS can manipulate all parts of a program's state
- PCB contents include
- process execution state (what is the process currently doing?)
- saved program counter (for processes not it running state)
- saved CPU register set (for processes not running)
- scheduling information (what priority, reason for sleep, etc.)
- memory management book-keeping (where is the processes memory?)
- accounting information
- user id
- I/O status
- needed because the OS does not always "pay attention" to a process
from the PCB, the OS can determine what the process is doing, and how it
should respond to some event.
- also needed to allow OS to organize processes
for example: disk I/O
- OS queues processes that want to read the disk
- read operation is issued and the process blocks until the
read completes.
- phases
- process makes read() system call and request
is queued for disk (PCB on queue)
- later, disk driver dequeues the request and
launches disk read (PCB at head of queue)
- when read is complete, disk will interrupt
- the interrupt routine finds PCB so it can
tell where to copy the data
- now that read is complete, process is ready to run
(PCB on ready queue)
- CPU scheduler takes processes off ready queue
and runs them (PCB describes each process)
- the general principle in play is that of a scheduling queue
Memory Scheduling
Unix: memory management is provided
not all of a processes address space is in memory at the same time
OS is responsible for translating process addresses into physical
addresses
when not in memory, processes address space is kept on disk (paging or
swapping)
to run a program, its address space must be brought into memory from
disk before the CPU can run through it
PCB is put on a scheduling queue while the process waits for address
space to be paged or swapped in from disk
most Unix systems take jobs from the memory waiting queue (short wait)
before they take jobs that are waking up after a disk I/O
CPU Scheduling
- CPU is assigned to processes, one-at-a-time
- timesharing == CPU is descheduled and restarted periodically
- timer interrupt triggers OS decision
- priorities determine how much time (relatively) each process will
spend on the CPU
- context switch
- CPU switches between a running process and one that is runnable
(i.e. on the ready queue)
- running process may be giving up CPU for two reasons
- time slice has expired => PCB goes on ready queue
- process makes a blocking call => PCB goes on specified
queue and state is set to blocked
- to run a new process the CPU scheduler must
- initialize any OS global variables that refer to the
"current" process
- set the CPU registers to contain the register values that
the process had when it was last context switched
- make the new process's execution state "running"
- jump to the PC that the process had when it was context
switched
Process Creation
- fork: makes an exact replica of process state except for PID
- process group: forked "child" lives in a family tree
- init: orphaned child becomes a child of init
- zombie: child dies and parent does not wait
Interprocess Communication
- two basic flavors:
- shared memory
- message passing
- shared memory
- SysV shared memory segments
- mapped files (e.g. pmap)
- requires synchronization primitives just like threads
- message passing
- sockets
- MPI
- PVM
- named pipes
- send() and recv() calls implement synchronization
- blocking / non-blocking send
- blocking / non-blocking recv()
Remote Procedure Calls
- use procedure call interface to make programming easier
- bury message-passing details in the call to allow remote
execution
- procedure call semantics: caller blocks until response comes back