parajulirajesh.com.np

Unit 1: Introduction to Operating Systems

An Operating System (OS) is the most important system software that acts as an interface between the user and computer hardware. It manages computer resources and provides services to application programs.

An Operating System is a software that controls and coordinates the use of hardware among various application programs and users.

Examples of Operating Systems

  • Microsoft Windows
  • Linux
  • macOS
  • Android
  • iOS

1.1 What Operating Systems Do?

The Operating System serves as an intermediary between the user and computer hardware.

Main Objectives of an Operating System

1. Convenience

Makes the computer easier to use.

Example: Opening a file by double-clicking instead of writing machine instructions.

2. Efficiency

Uses hardware resources efficiently.

Example: Managing CPU time among multiple programs.

3. Ability to Evolve

Allows new features and hardware to be added without affecting existing services.


Functions of Operating System

Process Management

  • Creates and deletes processes.
  • Schedules CPU tasks.
  • Provides synchronization among processes.

Memory Management

  • Keeps track of memory usage.
  • Allocates and deallocates memory.
  • Protects memory from unauthorized access.

File Management

  • Creates, deletes, and manages files.
  • Organizes files into directories/folders.

Device Management

  • Controls input/output devices.
  • Allocates devices to processes.

Security and Protection

  • User authentication.
  • Access control.
  • Data protection.

User Interface

Provides:

  1. Command Line Interface (CLI)
  2. Graphical User Interface (GUI)

Operating System = Resource Manager + Control Program

1.2 Operating System Operations

Operating systems perform various operations to manage computer resources effectively.

A. Interrupt Handling

What is an Interrupt?

An interrupt is a signal sent to the CPU indicating that an event needs immediate attention.

Types of Interrupts

Hardware Interrupt

Generated by hardware devices.

Examples:

  • Keyboard input
  • Mouse click
  • Printer completion

Software Interrupt

Generated by software or programs.

Examples:

  • Division by zero
  • System call request

Interrupt Handling Process

  1. Device sends interrupt.
  2. CPU stops current task.
  3. OS saves current state.
  4. Interrupt Service Routine (ISR) executes.
  5. CPU resumes previous task.

B. Dual-Mode Operation

To protect the system, CPUs operate in two modes.

1. User Mode

  • Runs application programs.
  • Limited access to hardware.

2. Kernel Mode

  • Runs operating system code.
  • Full access to hardware.

Advantages

  • Security
  • System protection
  • Prevents accidental damage

C. Timer

A timer prevents programs from running forever.

Working

  • OS sets timer.
  • Timer generates interrupt after specified time.
  • CPU returns control to OS.

Benefit

Supports multitasking and fairness.

1.3 Operating System Services

Operating systems provide services to users and programs.

1. User Interface (UI)

Allows communication between user and computer.

Types

  • GUI (Windows, icons, menus)
  • CLI (Command line)

2. Program Execution

  • Loads program into memory.
  • Executes program.
  • Terminates program after completion.

3. I/O Operations

Manages:

  • Keyboard
  • Mouse
  • Printer
  • Monitor
  • Disk drives

4. File-System Manipulation

Allows:

  • Create files
  • Delete files
  • Read files
  • Write files
  • Rename files

5. Communications

Supports communication between processes.

Methods

  • Shared Memory
  • Message Passing

6. Error Detection

Detects:

  • Hardware errors
  • Memory errors
  • Software errors

7. Resource Allocation

Allocates:

  • CPU
  • Memory
  • Devices
  • Files

8. Accounting

Tracks:

  • CPU usage
  • Memory usage
  • User activities

Useful in multi-user systems.


9. Protection and Security

Provides:

  • Login authentication
  • Password protection
  • Access permissions
 

OS Services

ServicePurpose
User InterfaceInteraction with user
Program ExecutionRun programs
I/O OperationsHandle devices
File ManagementManage files
CommunicationProcess interaction
Error DetectionDetect faults
Resource AllocationAllocate resources
AccountingTrack resource use
SecurityProtect system

1.4 Operating System Structures

Operating systems can be organized in different structural designs.


1. Simple Structure

Characteristics

  • No clear separation between components.
  • All functions mixed together.

Example

Early versions of MS-DOS

Advantages

  • Easy to design.
  • Fast execution.

Disadvantages

  • Difficult to maintain.
  • Poor security.

2. Layered Structure

OS is divided into layers.

Working

Layer 0 → Hardware

Layer 1 → Basic Hardware Services

Layer 2 → Memory Management

Layer 3 → Process Management

Layer N → User Interface

Each layer uses services of lower layers.

Advantages

  • Easy debugging
  • Easy maintenance
  • Better modularity

Disadvantages

  • Slower performance due to layer overhead

3. Microkernel Structure

Only essential functions remain in kernel.

Kernel Includes

  • Process management
  • Memory management
  • Communication

Other services run in user space.

Examples

MINIX

Advantages

  • More reliable
  • More secure
  • Easy to extend

Disadvantages

  • Communication overhead

4. Modular Structure

OS divided into modules.

Characteristics

  • Modules can be loaded dynamically.
  • Modules communicate through interfaces.

Example

Linux

Advantages

  • Flexible
  • Easy maintenance
  • Good performance

5. Hybrid Structure

Combination of:

  • Monolithic
  • Layered
  • Microkernel approaches

Examples

Microsoft Windows
and macOS

Advantages

  • Better performance
  • Better flexibility

POINTS TO KNOW

StructureAdvantageDisadvantage
SimpleFastPoor security
LayeredEasy maintenanceOverhead
MicrokernelReliableSlower IPC
ModularFlexibleComplex design
HybridBalanced performanceMore complex

1.5 System Calls

A System Call is a mechanism through which a user program requests a service from the operating system kernel.

System calls act as a bridge between user programs and the operating system.


Why System Calls Are Needed?

Applications cannot directly access hardware.

Instead they request services from OS using system calls.

Example

When saving a file:

Application → System Call → OS → Disk


How System Calls Work?

  1. User program requests service.
  2. System call is invoked.
  3. CPU switches from User Mode to Kernel Mode.
  4. OS performs requested service.
  5. Control returns to user program.

Types of System Calls

1. Process Control

Used to:

  • Create process
  • Terminate process
  • Load programs
  • Execute programs

Examples:

  • fork()
  • exec()
  • exit()

2. File Management

Used to:

  • Create files
  • Delete files
  • Read files
  • Write files

Examples:

  • open()
  • close()
  • read()
  • write()

3. Device Management

Used to:

  • Request devices
  • Release devices
  • Read device data

4. Information Maintenance

Used to:

  • Get system time
  • Get process information
  • Set system data

5. Communications

Used for:

  • Message passing
  • Shared memory
  • Network communication

6. Protection

Used to:

  • Set permissions
  • Check user access rights

Real-Life Examples of System Calls

ActivitySystem Call Used
Open a fileopen()
Read a fileread()
Save a filewrite()
Close a fileclose()
Create processfork()
End processexit()

1 Unit Summarize

Operating System

  • Interface between user and hardware.
  • Resource manager and control program.

Main Functions

  • Process management
  • Memory management
  • File management
  • Device management
  • Security

Operating System Services

  • User interface
  • Program execution
  • I/O operations
  • File management
  • Communication
  • Error detection
  • Resource allocation
  • Accounting
  • Protection

Operating System Structures

  • Simple
  • Layered
  • Microkernel
  • Modular
  • Hybrid

System Call

  • Request made by program to OS kernel.
  • Switches CPU from User Mode to Kernel Mode.
  • Provides access to OS services.

Assignments Questions (Student Work)

  1. Define Operating System with examples.
  2. Explain major functions of an Operating System.
  3. What are OS services? Explain any five.
  4. Explain dual-mode operation.
  5. What is an interrupt? Explain interrupt handling.
  6. Explain layered OS structure with advantages and disadvantages.
  7. What is a microkernel?
  8. Define System Call and explain its working.
  9. Explain types of System Calls with examples.
  10. Differentiate User Mode and Kernel Mode.

Unit 2: Process Management

A process is a program that is currently running in the computer’s memory. It is an active program that uses CPU time, memory, files, and other system resources.

Examples

  • Microsoft Word while typing a document
  • Google Chrome while browsing the internet
  • VLC Media Player while playing a video

Components of a Process

A process contains:

  • Program code (instructions)
  • Data (variables)
  • Program counter (next instruction to execute)
  • CPU registers
  • Stack (temporary data)
  • Heap (dynamic memory)

Characteristics of a Process

  • Has a unique Process ID (PID)
  • Uses system resources
  • Can create child processes
  • Executes independently

Real-Life Example

Think of a process as a student writing an exam. Each student has their own answer sheet and works independently.

A thread is the smallest unit of execution within a process.

A process may contain:

  • Single Thread (one task)
  • Multiple Threads (many tasks at the same time)

Examples

In Google Chrome:

  • One thread loads a webpage.
  • One thread plays a video.
  • One thread downloads files.

Advantages of Threads

  • Faster execution
  • Better CPU utilization
  • Less memory consumption
  • Improves multitasking

Real-Life Example

A restaurant is a process and the workers in the restaurant are threads. Each worker performs different tasks but works for the same restaurant.

Difference Between Process and Thread

ProcessThread
Independent execution unitPart of a process
Requires more memoryRequires less memory
Slower creationFaster creation
Has separate resourcesShares resources
Communication is slowerCommunication is faster

Operations on Processes

The Operating System manages processes through several operations.


1. Process Creation

A new process is created whenever a user starts a program.

Examples

  • Opening MS Word
  • Starting a game
  • Running a calculator

2. Process Scheduling

The operating system decides which process gets CPU time.

Purpose

  • Efficient CPU utilization
  • Fair resource sharing

3. Process Execution

The CPU executes the instructions of a process.

Example

Typing a document after opening Word.

4. Process Waiting (Blocked)

A process waits for an event or resource.

Example

Waiting for:

  • Keyboard input
  • Printer response
  • File download completion

5. Process Termination

A process ends when:

  • Task is completed
  • User closes it
  • An error occurs

Example

Closing a browser window.

2.3 Inter-Process Communication (IPC)

Inter-Process Communication (IPC) is a mechanism that allows processes to communicate and exchange information with each other.

Why IPC is Needed?

  • Share information
  • Coordinate tasks
  • Increase efficiency
  • Avoid duplication of work

Examples

  • Copying data from Word and pasting into PowerPoint
  • Sending a print command from a browser to a printer

Methods of IPC

1. Shared Memory

Two or more processes share a common memory area.

Advantages

  • Fast communication
  • Efficient data sharing

Disadvantages

  • Requires synchronization
  • Risk of data inconsistency

Example

Multiple programs accessing the same database.

2. Message Passing

Processes communicate by sending and receiving messages.

Advantages

  • Easier implementation
  • Better security

Example

Email communication between users.

2.4 Process States

A process changes its state during execution.

1. New State

The process is being created.

Example

Double-clicking a software icon.

2. Ready State

The process is ready and waiting for CPU allocation.

Example

Several applications waiting for execution.

3. Running State

The CPU is executing the process.

Example

Watching a video in VLC.

4. Waiting (Blocked) State

The process waits for an event or resource.

Example

Waiting for a printer to print.

5. Terminated State

The process has completed its task.

Example

Closing Notepad after saving a file.

Process State Transition

New

Ready

Running

Waiting

Ready

Running

Terminated

 

2.5 Process Synchronization

Process Synchronization is a technique used to coordinate multiple processes when they share common resources.

Why Synchronization is Needed?

Without synchronization:

  • Data may become incorrect
  • Race conditions occur
  • Resources may be corrupted.

Example

Suppose two students edit the same online document simultaneously. If both save changes at the same time, some information may be lost.

Critical Section

A critical section is a part of a program where shared resources are accessed. Only one process should enter the critical section at a time.

Critical Section Structure

  1. Entry Section
  2. Critical Section
  3. Exit Section
  4. Remainder Section
Scroll to Top

Rajesh Parajuli

BICTE GMC

LEC.RAJESH PARAJULI

Address: Ghodaghodi Municipality-1 Sukhad kailali

Contact: 9847546279

Ghodaghodi Multiple Campus BICTE