Unit 1 of 4 · M.Sc IT Sem 1

Unit 1: OS fundamentals and process management

Operating System notes · PTU syllabus (PGCA1903)

6 min read11 topics10 exam questions
On this page
  1. Unit summary
  2. Definition of an operating system
  3. Functions of an operating system
  4. The OS as a resource manager
  5. Kernel and shell
  6. Evolution and types of operating systems
  7. Processes and process states
  8. Process control block, scheduling queues and schedulers
  9. Context switch
  10. Inter-process communication
  11. Threads and multithreading models
  12. Multicore programming and OpenMP
  13. Key terms
  14. Quick revision
  15. 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

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.

HierarchyLayers of a computer system
  1. Users

    People and other computers

  2. Application programs

    Browsers, editors, games

  3. Operating system

    Controls and coordinates hardware use

  4. 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).

2

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.

HierarchyLayers of a computer system
  1. Users

    People and other computers

  2. Application programs

    Browsers, editors, games

  3. Operating system

    Controls and coordinates hardware use

  4. 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.

3

Topic 3

The OS as a resource manager

FrameworkResources managed by the OS
  • 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).

4

Topic 4

Kernel and shell

ComparisonKernel and shell
Kernel
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)

ComparisonKernel designs
Structure
Examples

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.

5

Topic 5

Evolution and types of operating systems

TypeKey ideaDrawback or feature
BatchSimilar jobs grouped and run one after another without user interactionCPU idle during I/O; no interaction
MultiprogrammingSeveral programs in memory; CPU switches when one waits for I/OBetter CPU use
Time-sharing (multitasking)CPU time shared in small slices among many usersQuick response; interactive
Parallel (multiprocessor)Several CPUs share memory and work togetherHigher throughput, reliability
DistributedMany independent computers connected by a network act as one systemResource sharing, fault tolerance
Real-timeResults must arrive within strict time limitsHard (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.

6

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.

CycleProcess state diagram
Process state diagram
1New
2Ready
3Running
4Waiting
5Terminated
  1. 1. New: Being created
  2. 2. Ready: Waiting for the CPU
  3. 3. Running: Executing on the CPU
  4. 4. Waiting: Blocked for I/O or an event
  5. 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.

7

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.

SchedulerChoosesFrequency
Long-term (job)Which jobs enter memory (ready queue)Infrequent
Short-term (CPU)Which ready process runs nextVery frequent
Medium-termWhich processes to swap out and back inIn between
ProcessScheduling queues
  1. 1Job queue

    All processes in the system

  2. 2Ready queue

    Processes in memory waiting for the CPU

  3. 3Device (I/O) queues

    Processes waiting for a device

  4. 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.

8

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.

SchedulerChoosesFrequency
Long-term (job)Which jobs enter memory (ready queue)Infrequent
Short-term (CPU)Which ready process runs nextVery frequent
Medium-termWhich processes to swap out and back inIn 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.

9

Topic 9

Inter-process communication

ComparisonIPC models
Shared memory
Message passing

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.

10

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.

ComparisonMultithreading models
Mapping
Features

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

11

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.
Key termsChallenges of multicore programming
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

  1. Q1.Why is the OS called a resource manager?
  2. Q2.Distinguish kernel and shell.
  3. Q3.Name the states of a process.
  4. Q4.What does a PCB contain?
  5. Q5.Distinguish concurrency and parallelism.
  6. Q6.What does #pragma omp parallel do?

Long-answer questions

  1. Q1.Explain the functions and types of operating systems.
  2. Q2.Explain process states, the PCB and schedulers.
  3. Q3.Explain inter-process communication.
  4. 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.

Planning your M.Sc IT in Ludhiana? See the M.Sc IT at SBS →

WhatsApp us