Unit 1: OS fundamentals and process management
Operating System notes · PTU syllabus (PGCA1903)
On this page
- Unit summary
- Definition of an operating system
- Functions of an operating system
- The OS as a resource manager
- Kernel and shell
- Evolution and types of operating systems
- Processes and process states
- Process control block, scheduling queues and schedulers
- Context switch
- Inter-process communication
- Threads and multithreading models
- Multicore programming and OpenMP
- Key terms
- Quick revision
- Important questions
Unit summary
The operating system manages every resource of a computer and runs every program as a process. This unit covers the definition and functions of an OS, the OS as a resource manager, kernel and shell, the evolution and types of operating systems, processes, process states, the PCB, scheduling queues, schedulers, context switching, inter-process communication, threads and multithreading models, and multicore programming with OpenMP.
After this unit you can
- Define an OS and explain its functions, structure and types
- Explain processes, PCBs, queues, schedulers and context switching
- Explain inter-process communication
- Explain threads, multithreading models and multicore programming
PTU syllabus topics
- Definition and functions of an operating system
- OS as resource manager
- kernel and shell structure
- evolution and types of operating systems
- process definition/states/PCB/scheduling queues/schedulers/context switch
- inter-process communication
- threading and multithreading models
- multicore programming and OpenMP basics
Topic 1
Definition of an operating system
An operating system is system software that acts as an interface between the user and the hardware, and as a resource manager that allocates the CPU, memory, files and devices among programs. Examples: Windows, Linux, macOS, Android.
- Users
People and other computers
- Application programs
Browsers, editors, games
- Operating system
Controls and coordinates hardware use
- Hardware
CPU, memory, I/O devices
Goals: convenience (easy to use) and efficiency (good use of resources).
Example
The OS as an intermediary: when you print a document, the application asks the OS, which talks to the printer driver and hardware. Without the OS, every application would need its own code to control every printer model.
Exam tip
Two views: the OS as an extended machine (user view) and as a resource manager (system view).
Topic 2
Functions of an operating system
An operating system is system software that acts as an interface between the user and the hardware, and as a resource manager that allocates the CPU, memory, files and devices among programs. Examples: Windows, Linux, macOS, Android.
- Users
People and other computers
- Application programs
Browsers, editors, games
- Operating system
Controls and coordinates hardware use
- Hardware
CPU, memory, I/O devices
Goals: convenience (easy to use) and efficiency (good use of resources).
Example
The OS at work: while you stream music and edit a document, the OS schedules both on the CPU, gives each its own memory, reads files from disk, sends sound to speakers and stops one program from reading the other's memory.
Exam tip
List the functions — process, memory, file, device and security management — with an example each.
Topic 3
The OS as a resource manager
Processor
Scheduling processes and threads on CPUs
Memory
Allocating and protecting main memory; virtual memory
Devices
Drivers, buffering, spooling, disk scheduling
Information (files)
File system, directories, access control
- Resource manager view: the OS multiplexes resources in time (CPU sharing) and in space (memory partitioning) among competing programs, keeping track of who uses what, granting requests and resolving conflicts.
Example
Sharing the CPU: three users run programs on a server. The OS gives each a time slice in turn, so all appear to run at once, and ensures none can monopolise the CPU or memory.
Exam tip
Resources managed: processor, memory, devices and files (information).
Topic 4
Kernel and shell
Role
Core of the OS; directly controls hardware
Interface that interprets user commands
Runs in
Kernel (privileged) mode
User mode
Functions
Process, memory, device and file management; system calls
Reads commands, runs programs, scripting
Examples
Linux kernel, Windows NT kernel
bash, zsh, PowerShell, Windows Explorer (graphical shell)
Monolithic
All services in one large kernel; fast but large
Linux, traditional Unix
Microkernel
Minimal kernel; services run as user-level servers
QNX, MINIX 3
Hybrid
Microkernel ideas with performance-critical services in the kernel
Windows NT family, macOS XNU
Example
Kernel and shell in Linux: when you type ls in the bash shell, the shell interprets the command and asks the kernel, through system calls, to read the directory. The kernel accesses the disk and returns the list.
Exam tip
Kernel = core that controls hardware; shell = interface that interprets user commands.
Topic 5
Evolution and types of operating systems
| Type | Key idea | Drawback or feature |
|---|---|---|
| Batch | Similar jobs grouped and run one after another without user interaction | CPU idle during I/O; no interaction |
| Multiprogramming | Several programs in memory; CPU switches when one waits for I/O | Better CPU use |
| Time-sharing (multitasking) | CPU time shared in small slices among many users | Quick response; interactive |
| Parallel (multiprocessor) | Several CPUs share memory and work together | Higher throughput, reliability |
| Distributed | Many independent computers connected by a network act as one system | Resource sharing, fault tolerance |
| Real-time | Results must arrive within strict time limits | Hard (missile control) vs soft (video streaming) |
Generations: 1st (1945–55) vacuum tubes, no OS; 2nd (1955–65) transistors and batch systems; 3rd (1965–80) ICs, multiprogramming and time-sharing; 4th (1980–present) personal computers, GUIs, networked and mobile OS.
Example
OS types in use: batch processing for month-end payroll; time-sharing on a university server; real-time OS in a car's anti-lock brakes; distributed OS across a data centre; mobile OS (Android) on phones.
Exam tip
Know one feature and one example for each type.
Topic 6
Processes and process states
A process is a program in execution, with its own code, data, stack and CPU state. A program is passive (a file); a process is active.
- 1. New: Being created
- 2. Ready: Waiting for the CPU
- 3. Running: Executing on the CPU
- 4. Waiting: Blocked for I/O or an event
- 5. Terminated: Finished
Transitions: admit (new → ready), dispatch (ready → running), interrupt/time-out (running → ready), I/O wait (running → waiting), I/O completion (waiting → ready), exit (running → terminated).
Example
State changes: a program starts (new), waits for the CPU (ready), runs (running), requests a file read and waits (waiting), returns to ready when the read completes, runs again, and finishes (terminated).
Exam tip
Draw the five-state diagram with labelled transitions.
Topic 7
Process control block, scheduling queues and schedulers
Processes move between the job queue, ready queue and device queues. The long-term scheduler decides which jobs enter memory, the short-term (CPU) scheduler picks the next process to run, and the medium-term scheduler swaps processes out and in. The Process Control Block (PCB) is the data structure in which the OS stores everything about a process: process ID, state, program counter, CPU registers, scheduling information (priority), memory information, accounting information and I/O status. Context switch: saving the PCB of the running process and loading the PCB of the next one. It is pure overhead.
| Scheduler | Chooses | Frequency |
|---|---|---|
| Long-term (job) | Which jobs enter memory (ready queue) | Infrequent |
| Short-term (CPU) | Which ready process runs next | Very frequent |
| Medium-term | Which processes to swap out and back in | In between |
- 1Job queue
All processes in the system
- 2Ready queue
Processes in memory waiting for the CPU
- 3Device (I/O) queues
Processes waiting for a device
- 4Dispatch
Short-term scheduler picks from the ready queue
Example
Schedulers in action: the long-term scheduler admits 20 jobs into memory; the short-term scheduler picks one to run every few milliseconds; when memory runs short, the medium-term scheduler swaps out an idle process.
Exam tip
Short-term scheduler runs most often; long-term controls the degree of multiprogramming.
Topic 8
Context switch
A context switch saves the state of the running process in its PCB and loads the saved state of the next process. It is pure overhead — no useful work is done during the switch. The Process Control Block (PCB) is the data structure in which the OS stores everything about a process: process ID, state, program counter, CPU registers, scheduling information (priority), memory information, accounting information and I/O status. Context switch: saving the PCB of the running process and loading the PCB of the next one. It is pure overhead.
| Scheduler | Chooses | Frequency |
|---|---|---|
| Long-term (job) | Which jobs enter memory (ready queue) | Infrequent |
| Short-term (CPU) | Which ready process runs next | Very frequent |
| Medium-term | Which processes to swap out and back in | In between |
Example
Overhead in numbers: if each switch takes 0.1 ms and the time quantum is 1 ms, about 9% of CPU time goes to switching. Very small quanta make overhead worse.
Exam tip
Context switch time depends on hardware support, such as multiple register sets.
Topic 9
Inter-process communication
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
Example
Two IPC models: a browser's tabs exchange data through shared memory (fast, but needs synchronisation); a client and server exchange messages through sockets (message passing, works across machines).
Exam tip
Shared memory is faster; message passing is easier and works across systems.
Topic 10
Threads and multithreading models
A thread is a lightweight unit of execution within a process. Threads of the same process share code, data and files but have their own stack and registers.
- Benefits: responsiveness, resource sharing, economy (cheaper than processes) and use of multiple cores.
- Multithreading models: many-to-one, one-to-one and many-to-many (mapping user threads to kernel threads).
Example
A web browser uses one thread to download a page and another to keep the window responsive.
Many-to-one
Many user threads to one kernel thread
One blocking call blocks all; no true parallelism
One-to-one
Each user thread to its own kernel thread
True parallelism; overhead of many kernel threads — Linux, Windows
Many-to-many
Many user threads to an equal or smaller number of kernel threads
Flexible and efficient; complex
Topic 11
Multicore programming and OpenMP
- Multicore: several processing cores on one chip; concurrency means tasks make progress together, parallelism means they run at the same instant on different cores.
- Identifying tasks
- Divide work into independent parts
- Balance
- Give each core equal work
- Data splitting
- Divide data among cores
- Data dependency
- Synchronise dependent tasks
- Testing and debugging
- Many possible interleavings
- Amdahl's law: speedup ≤ 1 ÷ (S + (1 − S) ÷ N), where S is the serial fraction and N the number of cores — with 25% serial code, 4 cores give at most 2.29 times speedup.
- OpenMP: a set of compiler directives and library routines for shared-memory parallel programming in C, C++ and Fortran; a parallel region is executed by a team of threads.
c#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel /* create a team of threads */
printf("Hello from thread %d\n", omp_get_thread_num());
long sum = 0;
#pragma omp parallel for reduction(+:sum)
for (int i = 1; i <= 1000000; i++) sum += i; /* loop split among threads */
printf("Sum = %ld\n", sum);
return 0;
}- Compile with gcc -fopenmp program.c.
Example
OpenMP in C: adding #pragma omp parallel for before a loop that sums one crore numbers splits the iterations across 4 cores, finishing roughly four times faster (minus overhead).
Exam tip
Distinguish concurrency (progress on several tasks) from parallelism (tasks running at the same instant).
Key terms
- Kernel
- Core of the operating system running in privileged mode
- Shell
- Command interpreter between user and kernel
- PCB
- Data structure holding all information about a process
- Context switch
- Saving one process's state and loading another's
- OpenMP
- API for shared-memory parallel programming
Quick revision
- OS definition and functions; resource manager view.
- Kernel vs shell; monolithic, microkernel, hybrid.
- Batch, multiprogramming, time-sharing, distributed, real-time, mobile OS.
- Process states; PCB; job, ready and device queues; long-, short- and medium-term schedulers; context switch.
- IPC: shared memory, message passing; threads; many-to-one, one-to-one, many-to-many; Amdahl's law; OpenMP pragmas.
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.Why is the OS called a resource manager?
- Q2.Distinguish kernel and shell.
- Q3.Name the states of a process.
- Q4.What does a PCB contain?
- Q5.Distinguish concurrency and parallelism.
- Q6.What does #pragma omp parallel do?
Long-answer questions
- Q1.Explain the functions and types of operating systems.
- Q2.Explain process states, the PCB and schedulers.
- Q3.Explain inter-process communication.
- Q4.Explain threads, multithreading models and multicore programming.
Stuck on this unit?
Message SBS on WhatsApp for help with Operating System, or to ask about studying M.Sc IT at Synetic.
