2. Introduction to Operating Systems
● An operating system (OS) is system software that
manages computer hardware and software
resources
● Key functions of an OS:
- Process Management
- Memory Management
- File System Management
- I/O Management
● Modern OS examples: Windows, Linux, macOS,
Android, iOS
3. What is a Process?
● A process is an independent program in execution
● Each process has its own:
- Memory space (Code, Data, Stack, Heap)
- CPU registers
- Process Control Block (PCB)
- I/O resources
● Examples: Web browser, text editor, music player
● Processes communicate through Inter-Process
Communication (IPC) mechanisms
4. Process States
● New: Process is being created
● Ready: Process is waiting to be assigned to a processor
● Running: Instructions are being executed
● Waiting/Blocked: Process is waiting for some event to
occur
● Terminated: Process has finished execution
5. Process Control Block (PCB)
● PCB is a data structure maintained by the OS for
each process
● Contains all information needed to manage the
process:
- Process ID (PID)
- Process State
- Program Counter
- CPU Registers
- Memory Management Information
6. What is a Thread?
● A thread is a lightweight execution unit within a
process
● Threads share memory and resources with other
threads in the same process
● Enables concurrent execution within a process
7. Thread Attributes
- Thread ID: Unique identifier for each thread.
- Program Counter: Tracks the next instruction.
- Register Set: Stores working variables.
8. Example usage of threads
Output:
This example demonstrates:
1.Creation of two threads using pthread_create()
2.Each thread executes the print_message function with
a different argument
3.The main thread waits for both threads to complete
using pthread_join()
4.Threads share the same code but have different
execution paths
9. Process vs Thread
Aspect Process Thread
Definition Independent program
in execution
Lightweight execution
unit within a process
Memory Separate memory
space
Shared memory
space
Communication Inter-Process
Communication (IPC)
Direct through shared
memory
Creation Overhead High Low
Context Switch Expensive Less expensive
10. Multi-threading: Benefits and Applications
Benefits of Multi-threading:
- Improved responsiveness
- Resource sharing
- Economy (less overhead than multiple processes)
- Scalability (better utilization of multiprocessor architectures)
11. Types of Threads
● User-Level Threads:
- Managed by user libraries
- Faster but blocks entire process
● Kernel-Level Threads:
- Managed by OS kernel
- Slower but more robust
12. User-Level Threads
Implemented by user-level thread libraries
● Advantages:
- Fast thread switching
- Can be implemented on any OS
● Disadvantages:
- Entire process blocks if one thread makes a blocking system call
13. Kernel-Level Threads
Implemented and managed by the OS kernel
● Advantages:
- Can utilize multiprocessor architectures
- If one thread blocks, others can still run
● Disadvantages:
- Higher overhead for thread management
14. Thread Implementation Examples
● POSIX Threads (Pthreads):
- Standard API for creating and manipulating threads
● Java Threads:
- Built into Java language
● Windows Threads:
- Part of the Win32 API
15. Practical Applications
● Web Browsers:
- Separate threads for rendering, JavaScript
execution, network I/O
● Server Applications:
- Thread pool for handling multiple client
connections
● Mobile Applications:
- Background threads for data synchronization
● Video Editing Software:
- Parallel processing of video frames