← Back to Home

CITS2002 - Lecture 8
Processes - Slides

Introduction to Processes

  • Process = a program that is currently running
  • Each process has:
    • A process ID (PID)
    • A parent process → the process that created it

At boot, system creates the “first” process → init (PID = 1)
Every other process is a child of something else
If a process’s parent dies, the child is “adopted” by init

  • Processes are either in the Running or Ready state
    • Finished processes are considered terminated
  • Up to operating system to manage processes between the two states

Process Creation

  • OS must allocate resources for both process and itself
    • Process needs memory when it initially is created
    • But also needs memory for execution stack and heap
    • OS needs memory to support process stage transitions
  • Different OS support process creation differently
    • Linux and macOS → fork() to duplicate existing processes
    • Windows → instantiating a process’s image from named location using CreateProcess()

Process Termination

  • Many reasons why a process may terminate:
    • Execution time-limit exceeded
    • Resource request unavailable
    • Arithmetic error (divide by zero)
    • Memory access violation
    • Parent process terminated
  • Process termination may be request when a process is either Running or Ready → OS needs to handle both cases
  • If process is a math function, its return result is generally made available to other processes

Timer Interrupts

  • When to shift states? → OS has two goals to ensure fairness
  • First goal is simple to achieve:
    • Enable each process to execute for predetermined period before moving Running process to Ready state
    • Max time allowed to run is known as time quantum
    • Hardware timer generates interrupt periodically
  • Processes that continually execute to the end of their time quanta are known as computer-bound processes

Blocking Processes

  • Not all processes are computer-bound processes
    • What happens when they make an I/O request?
  • The process must be placed into a new state called Blocked
    • Here, the process waits until the I/O is fulfilled
  • Then, it is moved back to Ready state afterwards

5-State Model of Process Execution

  • Two new states:
    • New new processes which aren’t yet admitted to Ready state
    • Exit terminated processes whose result may be required for other processes
  • Each state likely to hold more than one process except for Running

Suspension of Processes

  • To suspend a process → move it out of RAM & into secondary storage
    • Saves memory so that we can run more processes
  • Processes blocked waiting for I/O can be suspended

Swapping of Processes

  • This can be further applied to suspending Ready processes when we run out of main memory
  • This adds two more states:
    • Ready/Suspend
    • Blocked/Suspend

Processes can be freely moved around depending on whether memory is needed to be freed up, I/O requests are received or we are ready to handle suspended processes.


CITS2002 - Lecture 10