0% found this document useful (0 votes)
12 views25 pages

OS SLIDES SUMMARY

An Operating System (OS) serves as a bridge between users and hardware, managing resources such as CPU, memory, and storage across various devices. It facilitates user interaction through interfaces like CLI and GUI, and provides essential services including program execution, I/O operations, and file management. Different types of operating systems exist, including single-user, multiprogrammed, and real-time systems, each designed to meet specific user and application needs.

Uploaded by

aaima8447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views25 pages

OS SLIDES SUMMARY

An Operating System (OS) serves as a bridge between users and hardware, managing resources such as CPU, memory, and storage across various devices. It facilitates user interaction through interfaces like CLI and GUI, and provides essential services including program execution, I/O operations, and file management. Different types of operating systems exist, including single-user, multiprogrammed, and real-time systems, each designed to meet specific user and application needs.

Uploaded by

aaima8447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

LECTURE 1

What is an Operating System?

An Operating System (OS) is a program that:

 Acts as a bridge between user and hardware.

 Exists in all smart devices: laptops, tablets, smartphones, routers, etc.

🔧 Role of an OS (Technical View)

 OS is a resource manager.

 Manages:

o CPU

o Memory

o Storage

o Input/Output Devices

o Files

🧠 Computer System Organization

 A system has:

o One or more CPUs

o Device controllers (for disk, audio, video, etc.)

o Shared memory and common bus

Startup process:

1. Bootstrap program (in ROM/EEPROM) runs.

2. Sets up system.

3. Loads the OS kernel into memory.

🔁 System Boot & Interrupts

 After loading, kernel starts system processes (daemons).

 On UNIX, it starts with init process.

 System then waits for events (interrupts):


o Hardware interrupts (via bus)

o Software interrupts (system calls)

 CPU:

1. Pauses

2. Goes to Interrupt Service Routine (ISR)

3. Handles it, then returns to previous task

 Return address saved on system stack

 If CPU state changes, it's saved & restored for smooth continuation

💾 Storage Structure

 CPU executes from main memory (RAM), usually DRAM

 ROM/EEPROM hold static code (e.g., bootstrap)

 Memory = bytes with unique addresses

 CPU uses load/store instructions to move data

Execution cycle:
Fetch ➝ Decode ➝ Execute ➝ Store result

Main Memory:

 Limited & volatile

 Needs Secondary storage (like hard disks)

Storage Hierarchy (fastest to slowest):

 Registers → Cache → RAM → Disk → Tape

 Faster = more expensive and volatile

 SSDs are faster & nonvolatile

 Flash is slower than DRAM

 NVRAM uses batteries for backup

🔌 I/O Structure

 Devices managed by:


o Device controllers (control data transfer to local buffer)

o Device drivers (interface with OS)

How I/O works:

1. Driver sets up the controller

2. Controller transfers data

3. Signals completion via interrupt

✅ For large data: DMA (Direct Memory Access) handles block transfers with less CPU work

🧩 Components of a Computer System

1. Hardware:

o CPU, memory, I/O devices

2. Operating System:

o Coordinates hardware

3. Application Programs:

o Web browsers, games, databases, etc.

4. Users:

o People, other machines

🧮 Basic CPU Components

Component Function

PC Holds address of next instruction

IR Holds current instruction

Registers Temporary data & variables

ALU Performs arithmetic & logic

SP Points to stack (stores procedure data)

PSW Control bits incl. mode bit

MAR Holds address to access memory

MDR Holds data to store/load


Component Function

👥 Two Views of the OS

1. User View

 Designed for single-user convenience

 Focus: Ease of use, performance

 Not focused on resource sharing

2. System View

 OS = resource manager

 Manages hardware/software resources

 Decides between tasks & manages execution

🤔 What Do Operating Systems Do?

It depends on the system:

 Personal devices: Focus on usability, not efficiency

 Mainframes: Must manage many users

 Workstations: Dedicated, but still share servers

 Handheld devices: Limited resources, must save battery

 Embedded systems: Often no user interface

LECTURE 2&3

🧠 Types of Operating Systems

 Single User System

 Batch System

 Multiprogrammed System

 Time Sharing System

 Real-Time System
👤 Single User Systems

 Only one person can use it at a time.

 Example: Early personal computers

 It's interactive – you can directly use the software.

 Main goal: Convenience and responsiveness

o Easy to use

o Friendly interface (graphics)

🔸 Types of Single User Systems

1. Single User, Single Task

o Handles one application for one user at a time.

o Example: Older mobile phones

2. Single User, Multiple Tasks

o Designed for one user but can run multiple applications.

o Example: Using internet, downloading, and listening to music at once

🔁 Multiprogrammed System

 Runs multiple programs at the same time

 All programs stay in main memory

 OS picks one job, runs it

 If a job needs I/O (input/output), CPU switches to another job

 CPU is never idle—always doing something

📦 Batch Processing System

 No direct user interaction

 Users prepare their job off-line (e.g., punch cards)

 Job given to operator, not directly to computer

 OS treats job as a unit: has instructions, data, etc.

🔹 How It Works:
 Multiple jobs stored in memory

 Run in First Come First Served order

 After job ends:

o Memory is freed

o Output goes to a file or printer (spool)

Time Sharing System

 Advanced version of multiprogramming

 CPU switches quickly between jobs

 Each process gets a small amount of CPU time = Time Slice

 This way, multiple users/programs can work at once

⚙️Real-Time Operating System (RTOS)

 Designed for real-time applications

 Processes data immediately as it arrives—no delays

 Used in:

o Scientific labs

o Medical systems

o Industrial machines

o Displays

🚨 If output isn’t on time → It becomes useless

LECTURE 4

🎯 Goals of an Operating System (OS)

The OS is designed to manage computer resources and ensure smooth functioning. Key
functions include:

1. Memory Management

2. Processor Management
3. Device Management

4. File Management

5. Security

🧠 Memory Management

 Keeps track of which part of RAM is in use and by which process.

 In multiprogramming, decides:

o Which process gets memory

o How much memory it gets

 Allocates memory when needed.

 Frees memory when it's no longer in use.

Processor Management

 Monitors the CPU and the status of all processes.

 Managed by a program called the Traffic Controller.

 Assigns CPU to processes as needed.

 Releases the CPU when it's no longer needed by a process.

💽 Device Management

 Keeps track of all hardware devices (printers, disks, etc.).

 Managed by the I/O Controller.

 Determines:

o Which process gets access to which device

o For how long

 Allocates and deallocates devices efficiently.

📁 File Management

 Manages data files: their location, usage, and status.

 These services together form the File System.

 Controls who gets file access.


 Allocates and deallocates file-related resources.

🔐 Other Key Activities

 Security: Protects data and programs using passwords or other methods.

 System Performance Control: Tracks response times for system services.

 Job Accounting: Logs how much time and resources each job/user consumes.

 Error Detection:

o Produces error messages, logs (dumps), and traces.

 Software Coordination:

o Coordinates tools like compilers and assemblers for different users.

LECTURE 5

Operating System Services

The OS provides various services to both users and programs.

💬 1. User Interface (UI)

Allows users to interact with the OS.

 Command-Line Interface (CLI):


Type commands (e.g., using a terminal).

 Graphical User Interface (GUI):


Use mouse/keyboard to interact with windows, icons, menus.

 Batch Interface:
Commands are written in a file and run automatically.
Example: A backup.bat file copies documents to a folder daily without user action.

⚙️2. Program Execution

 OS loads programs into memory and runs them.

 It handles normal and abnormal (error) terminations.

3. I/O Operations

 Programs need to read/write data or use hardware (like printers).


 Users can’t directly access hardware – OS handles all I/O. Example: When printing, OS
formats and sends data to the printer properly.

📂 4. File System Manipulation

 Programs can:

o Create, delete, read, write files

o Search for and view file info

 OS manages file permissions to protect data. Example: Set a file so only you can open it.

🔄 5. Communications

 Programs share info through:

o Shared Memory: Access same memory.

o Message Passing: Send/receive messages via OS. Example: WhatsApp messages


go through servers between devices.

❗ 6. Error Detection

 OS constantly checks for:

o Hardware issues (e.g., power loss)

o I/O problems (e.g., printer out of paper)

o Software bugs (e.g., high memory use)

 Takes actions like showing error messages or stopping faulty programs. Example: If a
printer runs out of paper, OS alerts the user.

Other Important Functions

⚖️Resource Allocation

 OS shares CPU, memory, storage, devices fairly among users/programs.

 Uses techniques like CPU scheduling. Example: Running Word and Spotify at the same
time – OS balances both.

📊 Accounting

 Tracks resource usage per user/program.

o Used for billing or analyzing usage. Example: In a shared system, OS logs who
used how much CPU/storage.
🔐 Protection and Security

 Protection: Prevents programs/users from accessing each other’s data.

 Security: Defends against external threats (e.g., hackers). Example: OS uses passwords
and monitors for suspicious activity.

LECTURE 6A

🧑‍💻 User and Operating-System Interface

How Users Interact with the OS

Users can interact with the OS in two main ways:

 CLI (Command-Line Interface)


Type-based. User writes commands manually (e.g., rm file.txt).

 GUI (Graphical User Interface)


Visual interface using mouse/touchscreen (icons, windows, etc.).

🐚 Command Interpreter (Shell)

 Lets users run commands.

 Could be built into the kernel or run as a separate program.

 In UNIX/Linux, shells include:

o Bourne Shell

o C Shell

o Korn Shell

✅ Most commands are external programs, not part of the shell itself.

💡 Example:
When you type rm file.txt, the shell:

1. Finds the rm program

2. Loads it into memory

3. Runs it with file.txt as input

🛠 This setup lets users add new commands easily by writing new programs.
Graphical User Interface (GUI)

 Easier and more visual interaction.

 First popular on Apple Macintosh (1980s) and Windows (MS-DOS with GUI).

 Touchscreen GUIs used on mobile devices.

 Modern UNIX/Linux supports GUIs like:

o CDE

o X-Windows

o KDE

o GNOME (all open-source)

👩‍💻 CLI is preferred by:

 System admins & advanced users

 Faster, powerful, supports automation via scripts

👨‍🎓 GUI is better for:

 General users who prefer visual navigation

📌 Note: UI is separate from the OS's core – making the interface "user-friendly" is not the OS's
primary job.

⚙️System Calls

System calls = The way programs request services from the OS.

🧑‍💻 Written mostly in C/C++, sometimes Assembly.

📄 Example: Copying One File to Another

Involves several system calls:

1. Get file names (ask user or open file menu)

2. Open input file

3. Create output file (ask if file already exists)

4. Read & write between files (with error checks)

5. Close both files


6. Display completion message

7. Terminate program

🧰 APIs (Application Programming Interfaces)

APIs simplify system call usage. Examples:

 Windows API

 POSIX API (for UNIX/Linux/macOS)

 Java API

📦 Example:
CreateProcess() (Windows API) → Internally calls NTCreateProcess() in the kernel.

❓ Why Use APIs Instead of Direct System Calls?

 🔁 Portability – Code runs on different systems if the API is supported.

 ✅ Simplicity – Easier for developers.

 📏 Standardization – APIs are easier to maintain and understand.

🔄 How APIs Work

 Run-time libraries link API functions to system calls.

 System-call interface maps API calls to the correct system call using a unique ID.

📤 How Parameters Are Passed to the OS

System calls often need details like:

 File name

 Memory address

 Buffer size

📦 These can be passed in 3 ways:

1. Registers

o Fast, but limited space.

2. Memory block/table

o Store all data in memory, then pass a pointer to the OS.


o Common in Linux & Solaris.

3. Stack

o Push all details onto the stack, no space limit.

LECTURE 6B

🧠 What is a System Call in OS?

A system call is a programmatic way for a program to request a service from the operating
system’s kernel.

 Acts as a bridge between a user program and the OS.

 Exposes OS functionalities through APIs (Application Programming Interfaces).

 It's the only way to enter kernel mode.

📄 Example of System Call

Imagine a program that copies data from one file to another:

1. Display a message on screen → System call for output

2. Read input from keyboard (file names) → System call for input

3. Open input file

4. Create output file

5. Read → Write loop

6. Close both files

👉 All of these steps involve system calls.

How System Calls Work (Architecture)

1. 🔁 Program runs in user mode

2. 📞 A system call is made → Triggers kernel mode

3. 🛠 OS does the requested task (e.g., file read)

4. 🔚 Returns control back to user mode and resumes program

❓ Why Do We Need System Calls?


System calls are essential for:

 🔁 Reading/writing files

 📁 Creating/deleting files

 👶 Creating/managing processes

 🌐 Network communications

 Accessing hardware (printer, scanner, etc.)

🧩 Types of System Calls

1️⃣ Process Control

Manage processes.

Functions:

 create, terminate process

 load, execute program

 wait, signal

 allocate, free memory

 end, abort

2️⃣ File Management

Work with files.

Functions:

 Create/delete/open/close file

 Read/write/reposition

 Get/set file attributes

3️⃣ Device Management

Handle hardware devices.

Functions:

 Request/release device

 Attach/detach device
 Get/set device attributes

4️⃣ Information Maintenance

Exchange info between OS and programs.

Functions:

 Get/set date and time

 Get/set process/device attributes

5️⃣ Communication

Inter-process communication (IPC).

Functions:

 Create/delete communication links

 Send/receive messages

 Transfer status info

 Attach/detach remote devices

📥 Rules for Passing Parameters to System Calls

1. Parameters can be passed through:

o Registers

o Stacks

o Memory blocks (address passed in register)

2. OS handles popping/pushing if using stack.

🔧 Important System Calls

Call Function

wait() Suspends current process until a child process finishes.

fork() Creates a new process (child) identical to the parent.

exec() Replaces current process code with a new program.

kill() Sends a signal to a process (not always termination).

exit() Terminates process and frees resources.


Call Function

LECTURE 9

PROCESS

 A process is a running program.

 When you write a program (like in a text file) and then run it—that running version is
the process.

 It performs all tasks written in the program.

PROCESS LIFE CYCLE

A process goes through 5 main states:

1. Start – When the process is first created.

2. Ready – Waiting to be assigned to the CPU.

3. Running – Actively being executed by the CPU.

4. Waiting – Waiting for some resource (e.g., user input or file access).

5. Terminated – Finished execution and stopped.

THREAD

 A thread is the smallest part of a process that can run.

 A process can have multiple threads (like mini-processes within it).

 Multitasking: running multiple processes at once.

 Multithreading: running multiple threads (sub-tasks) at once inside a process.

Example:

 Watching a video while it's still downloading – both actions happen together using
threads.

 Used heavily in animation and media applications.

PROCESS CONTROL BLOCK (PCB)


The PCB is a special structure the operating system uses to keep track of each process.
It stores all info about a process, such as:

Key Information in a PCB:

1. Process State – e.g., Ready, Running, Waiting.

2. Privileges – What system resources it can use.

3. Process ID (PID) – Unique ID for each process.

4. Pointer – Link to its parent process.

5. Program Counter – Points to the next instruction to execute.

6. CPU Registers – Stores current data needed to keep process running.

7. Scheduling Info – Process priority, etc.

8. Memory Info – Page tables, memory usage, etc.

9. Accounting Info – CPU time used, time limits, execution ID.

10. I/O Info – List of input/output devices used.

LECTURE 10

1. What is a Process?

 A process = a program in execution.

 It includes:

o Text Section: The actual code.

o Program Counter & CPU Registers: Show the current activity.

o Process Stack: Temporary data like parameters and return addresses.

o Data Section: Global variables.

2. Process ≠ Program

 Program = passive (stored on disk).

 Process = active (executing).

3. Example:
 Two users running the same web browser = two separate processes.

4. Process States

 New: Being created.

 Ready: Waiting for CPU.

 Running: Instructions are executing.

 Waiting: Waiting for an event (e.g., I/O).

 Terminated: Finished executing.

5. Process Control Block (PCB)

Holds all info about a process:

 State

 Program Counter

 CPU Registers

 Scheduling Info (e.g., priority)

 Memory Management Info (page tables, etc.)

 Accounting Info (CPU time used)

 I/O Info (open files, devices)

6. Threads

 Smallest execution unit.

 A process can have multiple threads (lightweight processes).

 Used to improve performance through parallelism.

7. Process Scheduling

 Goal: Maximize CPU use and responsiveness.

 Scheduler chooses which process runs next.

Types of Scheduling Queues:

 Job Queue: All system processes.

 Ready Queue: Loaded in memory, ready to run.


 Device Queue: Waiting for I/O devices.

8. Schedulers

 Long-Term Scheduler (Job Scheduler):


Picks jobs from storage to load into memory. Controls multiprogramming.

 Short-Term Scheduler (CPU Scheduler):


Picks one process from the ready queue to run next.

9. Context Switch

 Happens when CPU switches from one process to another.

 Saves the state of the current process in its PCB and loads the next one.

 Takes a few milliseconds but doesn't do actual "work" — it's overhead.

10. Process Operations

 Creation: Parent creates a child process (tree-like structure).

 Termination: Child or parent process finishes.

11. Interprocess Communication (IPC)

 Needed when processes share data or collaborate.

 Independent Process: Doesn’t affect others.

 Cooperating Process: Can be affected or affect others.

Reasons for IPC:

 Information sharing

 Speedup via parallelism

 Modularity

 User convenience

IPC Models:

 Shared Memory: Processes read/write in the same memory region.

 Message Passing: Processes send/receive messages.

Message vs Shared Memory:

 Shared memory is faster but more complex.


 Message passing is easier in distributed systems.

12. Producer-Consumer Problem

 Common example of cooperating processes.

 One process produces data (producer), another uses it (consumer).

 Requires a buffer and synchronization.

Buffer Types:

 Unbounded: Infinite size, only consumer waits.

 Bounded: Fixed size, both may need to wait.

LECTURE 11

Process Synchronization – Overview

What is it?

 It's about managing access to shared resources when multiple processes run at the
same time.

 Prevents data inconsistency when two or more processes access shared data.

 Ensures that cooperating processes run in a synchronized way.

Producer-Consumer Problem (Classic Example)

 Problem:

o One process (Producer) puts items into a fixed-size buffer.

o Another process (Consumer) removes items from the buffer to use.

o Rule: They cannot access the buffer at the same time.

 Goal: Make sure Producer doesn't add when the buffer is full, and Consumer doesn’t
remove when it's empty.

Solution Using Shared Memory

 Both processes share a common buffer stored in shared memory.

 They can run at the same time, but must coordinate access:

o Producer can add a new item while Consumer uses another.


o But Consumer must wait if item not yet produced.

Two Types of Buffers

1. Unbounded Buffer

o No size limit.

o Producer can always add items.

o Consumer may have to wait for new data.

2. Bounded Buffer

o Fixed size.

o Producer waits if full.

o Consumer waits if empty.

Synchronizing with a Count Variable

 Use an integer count to track how many items are in the buffer.

 Initially: count = 0

 Producer: increases count after adding.

 Consumer: decreases count after removing.

Race Condition

 When multiple processes access and modify shared data at the same time.

 Outcome depends on the order of access.

 Can lead to incorrect or unpredictable results.

Critical Section Problem

 A critical section is the part of a program where shared resources are accessed.

 Only one process should be in its critical section at a time.

 Other processes must wait.

Requirements for a Good Solution to Critical Section Problem

1. Mutual Exclusion:

o One process at a time in the critical section.


2. Progress:

o If no process is in the critical section, one that wants to enter should not wait
forever.

3. Bounded Waiting:

o A process waiting to enter must eventually get its turn—no infinite waiting.

👉 Assumes each process runs at nonzero speed, but we don’t assume which one is faster.

Peterson’s Solution

 Works for 2 processes only.

 Processes take turns entering the critical section.

 Uses shared variables and assumes atomic (uninterruptible) instructions like LOAD and
STORE.

LECTURE 12

🔐 Mutex Lock

 Mutex = MUTual EXclusion object.

 Used to allow multiple threads to share a resource, but not at the same time.

 How it works:

1. Mutex is created with a unique name.

2. A thread locks the mutex before using the resource.

3. It unlocks when finished so others can access.

🔁 Mutex Lock & Critical Region

 Critical region = Section of code that accesses shared resources.

 Use acquire() to lock the mutex.

 Use release() to unlock it.

⚙️Mutex Logic

 Has a boolean available:

o If true, acquire() locks it and sets it to false.


o If false, the thread waits until it's true again.

🚦 Semaphores (by Dijkstra)

 A synchronization tool for managing concurrent processes.

 Two types:

o Counting Semaphore: Integer value; tracks multiple resources.

o Binary Semaphore: Only 0 or 1; simpler than counting.

🔄 Operations

 WAIT(S): If S > 0, decrement. If S ≤ 0, do nothing.

 SIGNAL(S): Always increments S.

❌ Deadlocks

🧠 Background

 Early OS: one program at a time → no deadlocks.

 Now: multiple programs, dynamic resource requests → potential for deadlocks.

📌 What is Deadlock?

 Several processes are stuck waiting forever on each other for resources.

💾 Examples of Resources:

 Printers, storage, files, database tables.

🔁 Resource Request Cycle

1. Request the resource.

2. Use it.

3. Release it.

🧩 Example

 Program 1 has resource A and wants B.

 Program 2 has B and wants A.

 Both are waiting on each other → deadlock.

🚗 Bridge Example
 One-way bridge → each car = process, each section = resource.

 Cars face each other → deadlock.

 Solution: back up (preempt), but starvation is possible.

🔍 Deadlock Characterization

A deadlock occurs only when all these four conditions are true:

1. Mutual Exclusion – resource held exclusively.

2. Hold and Wait – holding one, waiting for another.

3. No Preemption – resources released voluntarily.

4. Circular Wait – chain of waiting forming a loop.

🔄 Resource Allocation Graph (RAG)

 Purpose: Visual tool to track process-resource relationships.

 Nodes:

o Squares: Resource types (e.g. Printer)

o Circles: Processes

o Dots: Instances of resources (e.g. 2 printers = 2 dots)

🔁 Types of Edges

 Request Edge: From process → resource.

 Assignment Edge: From resource → process.

🔄 Edge Behavior

 A request edge becomes an assignment edge when the resource is granted.

🌀 Deadlock in RAG

 No cycles: No deadlock.

 Cycle + one instance/resource type: Deadlock exists.

 Cycle + multiple instances: Deadlock might exist.

📊 Summary

 No cycles ⇒ No deadlock
 Cycle exists ⇒

o One instance per resource → deadlock

o Multiple instances → possible deadlock

You might also like