Untitled Document
Untitled Document
OS vs. Kernel:
System Calls:
● Definition:
○ System Calls are the programming interface between user
applications and the OS kernel.
○ They enable programs to request services from the OS, such as
hardware access, file management, and process control.
● Types of System Calls:
○ Process Control:
■ Create, execute, and terminate processes.
■ Examples: fork() (create a child process), exec() (execute
a new program), exit() (terminate a process).
○ File Management:
■ Operations on files like creating, reading, writing, and closing.
■ Examples: open() (open a file), read() (read data),
write() (write data), close() (close file).
○ Device Management:
■ Interacts with device drivers and controls devices.
■ Examples: ioctl() (control device operations), read() and
write() (device I/O).
○ Information Maintenance:
■ Gets and sets system information.
■ Examples: getpid() (get process ID), alarm() (set a
timer), sleep() (pause execution).
○ Communication:
■ Facilitates communication between processes.
■ Examples: pipe() (create a communication channel),
shmget() (shared memory), msgget() (message queue).
● Examples of System Calls:
○ Linux: fork(), exec(), open(), read(), write()
○ Windows: CreateProcess(), ReadFile(), WriteFile(),
ExitProcess()
A deadlock in an operating system is a situation where a set of processes are blocked because
each process is holding a resource and waiting for another resource acquired by some other
process. In simpler terms, deadlock occurs when two or more processes wait indefinitely for
each other to release resources.
Examples
Example 1: Circular Wait
● Given:
○ Total resources: A=10, B=5, C=7
○ Available: A=3, B=2, C=2
○ Allocation and Maximum demand for 3 processes are:
P0 010 753
P1 200 322
P2 302 902
Process Need (A B C)
P0 743
P1 122
P2 600
● Check if the system is in a safe state by simulating resource allocation and seeing if all
processes can complete.
Deadlock Recovery Techniques
1. Process Termination:
○ Abort all deadlocked processes or Abort one process at a time until the
deadlock cycle is broken.
○ Criteria for choosing the process:
■ Priority
■ Execution time
■ Number of resources held
2. Resource Preemption:
○ Preempt resources from some processes and allocate them to others.
○ Challenges:
■ Selecting the victim
■ Rollback to a safe state
■ Starvation prevention by ensuring that no process is repeatedly
preempted.