Session 1.3: System Calls & Virtualization

Understanding system calls, their types, and virtualization concepts

Module 1 1.5 Hours Theory

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):

Windows API
For Windows systems
POSIX API
For UNIX, Linux, macOS
Java API
For JVM programs
System Call Execution Flow:
User Program
API Call
System Call Interface
Kernel
Mode Transition (User to Kernel Mode)
User Mode (Bit = 1)
Restricted access
Kernel Mode (Bit = 0)
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

Process Management

These system calls deal with the creation, management, and termination of processes.

Creating and Terminating Processes
UNIX: fork(), exit()
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
get_process_attributes()
set_process_attributes()

Retrieve or modify properties like priority and time limits

Concurrency Control
wait_event(), signal_event()
allocate(), free()

2. File Management System Calls

File System Operations

These calls manage files and directories within the file system.

File Creation and Deletion
create_file()
delete_file()
Accessing Files
UNIX: open(), close(), read(), write()
Windows: CreateFile(), CloseHandle(),
ReadFile(), WriteFile()
File Attributes
get_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

I/O Device Control

These system calls control I/O devices and ensure proper resource allocation.

Device Allocation
request_device()
release_device()

Ensure exclusive use of a device

Device I/O
read()
write()
reposition()

Similar to file operations

Device Attributes
get_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

System Information Transfer

These calls transfer information between the user program and the operating system.

Time and Date
get_time_or_date()
set_time_or_date()

System time management

System Data
get_system_data()
set_system_data()

OS version, free memory/disk space

Attributes
get_attributes()
set_attributes()

Process, file, or device attributes

5. Communications System Calls

Inter-Process Communication

These system calls facilitate communication between processes, potentially across networks.

Connection Management
create_communication_connection()
delete_communication_connection()
Message Exchange
send_messages()
receive_messages()
Status Transfer
transfer_status_information()
IPC Models:
Message-Passing Model
  • Direct: Explicitly naming sender/receiver
  • Indirect: Via shared mailbox/port
  • Synchronous: Blocking communication
  • Asynchronous: Non-blocking communication
Examples: Mach OS ports, Windows ALPC
Shared-Memory Model
  • Processes create shared memory regions
  • Direct reading/writing in shared areas
  • Fast communication method
  • Requires synchronization
API: POSIX shared memory
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

Access Control

These system calls control access to system resources and manage security permissions.

Permissions
set_permission()
get_permission()

Manipulate permission settings for resources like files and disks

User Access
allow_user()
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