Lecture 4 - Processes Flashcards
Why are processes useful?
Makes full utilisation of the CPU
If processes with multiprogramming didn’t exist then each job would have sole control of the computer until it terminated
What is a process?
The OS’s abstraction for execution, i.e. a process is a program being executed
What is a sequential process?
An address space (abstraction of memory) being executed by a single thread of execution (abstraction of cpu)
The unit of execution, the unit of scheduling, the dynamic execution context vs the static program
What 3 basic things does a process consist of?
Address space - instructions, data
CPU State - program counter, stack pointer, registers
OS Resources - open files, network connections..
What are the 4 areas of a process’s address space
Stack (dynamic mem)
Heap (dynamic mem)
Static data (data segment)
Code (text segment)
What data structure does the OS maintain to keep track of a process’s state?
Process Control Block (PCB) or process descriptor
What sort of information does a Process Control Block include?
Process ID, Parent ID, execution state, Program counter, Stack pointer, registers etc.
What is the first process created when a UNIX system starts up?
init
How are new processes created in UNIX?
fork() system call
How does the fork() syscall work?
creates and initialises new PCB (and kernel resources the same as the parent)
Initialises program counter, stack pointer to be the same
Copies the address space of parent to child.
i.e. duplicates the process
returns the child’s PID to the parent
returns 0 to the child
How can a different process be started?
First fork then exec()
What does exec() syscall do?
stops current process
loads program in arg0 into address space (overwrites existing image)
Initialises hardware context and args for new program
Place pcb onto ready queue
How does a process exit?
once finished executing, calls exit()
What does the exit() syscall do?
releases all resources
gets rid of most OS structures supporting the process
checks if parent is alive
if os, enters “zombie” state
otherwise dies
How does a parent process arrange to get the return value of a child
wait() syscall
How does the wait() syscall work?
Puts the parent to sleep until the child exits
When child calls exit(), OS wakes parent and returns value, and gets rid of the zombies
What are the 3 process execution states?
ready: waiting to be assigned to a cpu (could run, but another process has the cpu)
running: executing on a cpu
waiting: aka blocked, waiting for event such as I/O completion or message from another process
What are the state transitions in and out of the running state?
In: dispatch/schedule from ready state
Out: interrupt to ready state
terminate to terminated state
trap or exception to blocked state
What are the state transitions in and out of ready state?
in: create process
interrupt from blocked state (e.g. I/O complete)
interrupt from running state (cpu scheduling)
out: dispatch/schedule to running state
What are the state transitions in and out of blocked state?
in: trap or exception from running state
out: interrupt (event completed e.g. I/O)
Draw the process state transitions

What is a context switch?
When the cpu switches from executing one process to another
What is involved in a context switch?
CPU saves old PCB
and loads new PCB
What is the problem with context swtiches?
While CPU is performing them no useful stuff can happen
100% overhead