Unit 2: CPU management and IPC
Operating Systems notes · PTU syllabus (BSIT303/BSBC403)
On this page
Unit summary
The CPU scheduler decides which process runs next, and IPC lets processes cooperate. This unit covers preemptive vs non-preemptive scheduling, context switching, scheduling schemes, multiprocessor and thread scheduling, message passing and shared memory IPC models, pipes, FIFOs and sockets.
After this unit you can
- Distinguish preemptive and non-preemptive scheduling and explain context switching
- Apply CPU scheduling algorithms
- Explain multiprocessor and thread scheduling
- Explain IPC models, pipes, FIFOs and sockets
PTU syllabus topics
- Preemptive vs non-preemptive scheduling
- context switching
- scheduling schemes
- multi-processor and thread scheduling
- message passing and shared memory IPC models
- pipes
- FIFO and sockets
FCFS
No
Simple; convoy effect
SJF
Either
Lowest average waiting time
Priority
Either
Risk of starvation; use ageing
Round robin
Yes
Time quantum; fair for time-sharing
Topic 1
Preemptive vs non-preemptive scheduling
When CPU is taken away
Only when the process blocks or ends
Also on interrupts or arrival of higher-priority work
Examples
FCFS, non-preemptive SJF and priority
Round Robin, SRTF, preemptive priority
Response time
Poorer for interactive work
Better
Overhead
Lower
Higher — more context switches
Topic 2
Context switching
- Context switch: saving the state (registers, PC, PCB data) of the running process and loading the state of the next one — pure overhead, so frequent switches reduce efficiency.
Topic 3
Scheduling objectives and criteria
- CPU utilisation
- Keep the CPU as busy as possible (maximise)
- Throughput
- Processes completed per unit time (maximise)
- Turnaround time
- Completion time − arrival time (minimise)
- Waiting time
- Turnaround time − burst time (minimise)
- Response time
- Time from submission to first response (minimise)
Preemptive scheduling can take the CPU away from a running process; non-preemptive lets it run until it finishes or blocks.
Topic 4
Scheduling schemes: FCFS, SJF, priority and Round Robin
FCFS
First come, first served; non-preemptive
Simple; convoy effect behind long jobs
SJF
Shortest burst first; preemptive version is SRTF
Minimum average waiting time; may starve long jobs
Round Robin
Each process gets a time quantum in turn; preemptive
Fair and good for time-sharing; quantum size matters
Example
Processes P1 = 24, P2 = 3, P3 = 3 ms, all arriving at 0. FCFS (P1, P2, P3): waiting times 0, 24, 27 → average 17 ms. SJF (P2, P3, P1): waiting times 6, 0, 3 → average 3 ms.
Example
Round Robin with quantum 4 for the same jobs: P1 runs 0–4, P2 4–7, P3 7–10, then P1 10–30. Waiting: P1 = 6, P2 = 4, P3 = 7 → average 5.67 ms.
Exam tip
Always draw a Gantt chart first, then compute completion, turnaround and waiting times in a table. Examiners give marks for each step.
Topic 5
Multiprocessor and thread scheduling
- Multiprocessor scheduling: asymmetric (one master processor schedules) vs symmetric (each processor self-schedules); processor affinity keeps a process on the same CPU for cache benefits; load balancing (push and pull migration).
- Thread scheduling: kernel schedules kernel-level threads; user-level threads are mapped by the thread library (many-to-one, one-to-one, many-to-many).
- Real-time scheduling: rate-monotonic and earliest-deadline-first.
Topic 6
Interprocess communication models
Mechanism
Processes read and write a common memory region
Processes exchange messages via the kernel (send, receive)
Speed
Fast after set-up
Slower — system calls per message
Synchronisation
Programmer must synchronise
Built into send and receive
Suits
Large data on the same machine
Small messages, distributed systems
Topic 7
Pipes, FIFOs and sockets
- Pipe (anonymous): one-way byte stream between related processes (parent and child) — pipe() system call; shell example: ls | grep txt.
- FIFO (named pipe): a pipe with a name in the file system — unrelated processes can communicate (mkfifo).
- Socket: endpoint for communication between processes on the same or different machines, identified by IP address and port — TCP (stream) and UDP (datagram) sockets; client–server model.
Key terms
- Preemption
- Taking the CPU from a running process
- Context switch
- Saving and loading process state
- Processor affinity
- Preference to run a process on the same CPU
- Pipe
- One-way channel between related processes
- Socket
- Network communication endpoint
Quick revision
- Preemptive vs non-preemptive; context switch overhead.
- Criteria: CPU utilisation, throughput, turnaround, waiting, response time.
- FCFS, SJF/SRTF, priority, RR; Gantt charts; averages.
- Multiprocessor: asymmetric vs symmetric, affinity, load balancing; thread models.
- Shared memory vs message passing; pipes, FIFOs, sockets.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Distinguish preemptive and non-preemptive scheduling.
- Q2.What is a context switch?
- Q3.Define turnaround time and waiting time.
- Q4.What is processor affinity?
- Q5.Distinguish shared memory and message passing.
- Q6.Distinguish a pipe and a FIFO.
Long-answer questions
- Q1.Explain CPU scheduling criteria and preemptive and non-preemptive scheduling.
- Q2.Solve a scheduling problem using FCFS, SJF and Round Robin (numerical).
- Q3.Explain multiprocessor and thread scheduling.
- Q4.Explain IPC models, pipes, FIFOs and sockets.
Stuck on this unit?
Message SBS on WhatsApp for help with Operating Systems, or to ask about studying B.Sc IT at Synetic.
