Session 1.3: System Calls & Virtualization
Understanding system calls, their types, and virtualization concepts
Learning Objectives
By the end of this session, you will be able to:
- Define system calls and their purpose
- Explain how system calls work
- Classify the six types of system calls
- Understand mode transitions and parameter passing
- Analyze communication models in system calls
Key Concept
System calls serve as the interface through which user programs request services from the operating system, providing controlled access to privileged functions and hardware resources.
What are System Calls?
A system call serves as the interface through which a user program requests a service from the operating system. These are tasks that user programs are not permitted to perform directly due to security and protection mechanisms.
Primary Purpose
Allow user applications to access the operating system's privileged functions and hardware resources in a controlled and safe manner.
Why System Calls are Needed:
- User programs cannot directly control hardware
- Security and protection mechanisms prevent direct access
- OS manages resources on behalf of applications
- Provides standardized interface for system services
Common Examples:
- I/O Operations: Reading files, writing to screen
- Memory Management: Allocating/deallocating memory
- Process Control: Creating/terminating processes
- File Operations: Opening, closing, deleting files
How System Calls Work
API as Abstraction Layer
Most developers don't interact with raw system calls directly. Instead, they use Application Programming Interfaces (APIs):
System Call Execution Flow:
Mode Transition (User to Kernel Mode)
Restricted access
Full hardware access
System calls trigger a software interrupt (trap) that automatically switches from user mode to kernel mode.
Parameter Passing Methods:
Registers
Parameters passed directly in CPU registers (fastest method)
Memory Block
Parameters stored in memory block, address passed in register
Stack
Parameters pushed onto stack by program, popped by OS
1. Process Control System Calls
These system calls deal with the creation, management, and termination of processes.
Creating and Terminating Processes
Windows: CreateProcess(), ExitProcess()
Loading and Executing Programs
Calls to load and execute programs, allowing a new program to run within a process's context.
Process Attributes
set_process_attributes()
Retrieve or modify properties like priority and time limits
Concurrency Control
allocate(), free()
2. File Management System Calls
These calls manage files and directories within the file system.
File Creation and Deletion
delete_file()
Accessing Files
Windows: CreateFile(), CloseHandle(),
ReadFile(), WriteFile()
File Attributes
set_file_attributes()
Inquire about or modify file properties:
- File name and type
- Protection codes
- Creation/modification dates
- Size and location
3. Device Management System Calls
These system calls control I/O devices and ensure proper resource allocation.
Device Allocation
release_device()
Ensure exclusive use of a device
Device I/O
write()
reposition()
Similar to file operations
Device Attributes
set_device_attributes()
Device configuration and status
UNIX Approach
Many operating systems, like UNIX, merge I/O device and file management into a combined file-device structure, treating devices as special files.
4. Information Maintenance System Calls
These calls transfer information between the user program and the operating system.
Time and Date
set_time_or_date()
System time management
System Data
set_system_data()
OS version, free memory/disk space
Attributes
set_attributes()
Process, file, or device attributes
5. Communications System Calls
These system calls facilitate communication between processes, potentially across networks.
Connection Management
delete_communication_connection()
Message Exchange
receive_messages()
Status Transfer
IPC Models:
Message-Passing Model
- Direct: Explicitly naming sender/receiver
- Indirect: Via shared mailbox/port
- Synchronous: Blocking communication
- Asynchronous: Non-blocking communication
Shared-Memory Model
- Processes create shared memory regions
- Direct reading/writing in shared areas
- Fast communication method
- Requires synchronization
Communication Mechanisms:
Pipes
Traditional UNIX mechanism for one-way communication between related processes
Named Pipes
Bidirectional communication, no parent-child relationship required
Sockets
Network communication endpoints using IP address and port
RPCs
Remote Procedure Calls for distributed system communication
6. Protection System Calls
These system calls control access to system resources and manage security permissions.
Permissions
get_permission()
Manipulate permission settings for resources like files and disks
User Access
deny_user()
Specify which users can or cannot access certain resources
Protection vs Security
- Protection: Controls access to resources within the system
- Security: Defends against external threats and attacks
- Both work together to ensure system integrity
Session Summary
Key Takeaways:
- System calls provide controlled interface between user programs and OS
- APIs abstract system calls for easier programming
- Mode transitions ensure security through user/kernel mode separation
- Six categories of system calls cover all major OS services
- Communication models enable inter-process communication
- Protection mechanisms control resource access
System Call Categories Summary:
| Category | Purpose | Key Examples |
|---|---|---|
| Process Control | Manage process lifecycle | fork(), exit(), CreateProcess() |
| File Management | File system operations | open(), close(), read(), write() |
| Device Management | I/O device control | request_device(), release_device() |
| Information | System data transfer | get_time(), get_system_data() |
| Communications | Inter-process communication | send_message(), pipe(), socket() |
| Protection | Access control | set_permission(), allow_user() |
Next Module
Module 2: Process and Threads
Process fundamentals, scheduling, operations, and threading concepts
Study Tips:
- Practice identifying system call categories in real applications
- Understand the security implications of mode transitions
- Compare different IPC models and their use cases
- Review the relationship between APIs and system calls