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