System Calls and Their Execution
System Calls: Overview and Mechanism
Definition of System Calls
System calls are the primary mechanism through which a user process interacts with the operating system (OS) to request services or access hardware resources.
Execution Context
The execution context must shift from user mode to kernel mode to perform a system call.
This transition involves several key actions, including:
Control Transfer: Control is passed from the user process to the OS, which operates in privileged mode.
Argument Passing: Arguments necessary for the system call are passed from the user process to the kernel.
Memory Jump: The execution instruction sequence for the specified system call is located in the kernel's memory.
Diagram Trace of Control and Data Exchange
Initialization
Start with the executing user process needing hardware access.
The user process initiates a system call to request access or service from the OS.
Control Transfer to Kernel
On invoking a system call:
Control is handed over to the kernel, running in privileged mode.
The OS performs the requested operation as specified by the system call.
This is a critical transition as the user process has limited access and permissions.
Completion of System Call
After executing the requested operation, the OS returns results back to the user process:
Control Return: Control is transferred back to the calling user process.
The operating context changes back from kernel mode to user mode.
Argument Passing Back: Any results or argument data are passed back into the user address space.
The execution resumes at the exact point where the system call was invoked.
Process of Making a System Call
Step-by-Step Breakdown:
A user application must:
Write the necessary arguments for the system call at a defined memory location.
Save all relevant data appropriately.
Make the actual system call using a specific system call number.
Understanding the defined location is crucial for the OS to determine the number and location of arguments to retrieve during execution.
Argument Passing
Arguments can be passed in two ways:
Directly: Arguments are sent directly between the user program and the OS.
Indirectly: Arguments are passed by providing their memory address, allowing the OS to access them.
Synchronous vs Asynchronous System Calls
Synchronous System Calls
In synchronous mode, the calling process waits until the system call completes before continuing its execution.
Asynchronous System Calls
An alternative method (to be discussed later) allows non-blocking behavior, enabling processes to continue executing while waiting for the system call to complete.