Unit 1 of 4 · M.Sc IT Sem 1

Unit 1: OS fundamentals and process management

Operating System notes · PTU syllabus (PGCA1903)

4 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
CycleProcess states
Process states
1New
2Ready
3Running
4Waiting
5Terminated
  1. 1. New: Being created
  2. 2. Ready: Waiting for CPU
  3. 3. Running: Executing
  4. 4. Waiting: Blocked on I/O
  5. 5. Terminated: Finished
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).

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

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

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.

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

7

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.

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

8

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.

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

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.

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.

WhatsApp us