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
- 1. New: Being created
- 2. Ready: Waiting for CPU
- 3. Running: Executing
- 4. Waiting: Blocked on I/O
- 5. Terminated: Finished
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).
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).
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.
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
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.
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).
Topic 7
Process control block, scheduling queues and schedulers
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
Topic 8
Context 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 |
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
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.
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.
