Back to Operating Systems

System Calls & API

Interface between user programs and operating system kernel

Key Concepts

System call interface, kernel mode, user mode transitions

Applications

Operating system design, system programming, application development

Exam Focus

System call types, execution mechanism, parameter passing

System Call Categories

File Operations System Calls

open()

Open a file or device

Parameters: pathname, flags, mode
Returns: file descriptor

read()

Read data from file descriptor

Parameters: fd, buffer, count
Returns: bytes read

write()

Write data to file descriptor

Parameters: fd, buffer, count
Returns: bytes written

close()

Close file descriptor

Parameters: fd
Returns: 0 on success

lseek()

Change file position

Parameters: fd, offset, whence
Returns: new position

stat()

Get file information

Parameters: pathname, statbuf
Returns: 0 on success

System Call Execution Mechanism

Execution Steps

1

User Mode Call

Application calls system call wrapper function

Library function prepares arguments and issues software interrupt

2

Mode Switch

CPU switches from user mode to kernel mode

Hardware saves user context and jumps to kernel handler

3

Kernel Handler

Kernel identifies and executes system call

System call number used to index into dispatch table

4

Return to User

Kernel completes operation and returns to user mode

Result returned to application, user context restored

System Call Trace

Click "Trace" on any system call to see execution trace...

Parameter Passing Methods

Registers

  • • Method: Pass parameters in CPU registers
  • • Advantage: Fast access
  • • Limitation: Limited number of registers
  • • Best for: Few parameters

Stack

  • • Method: Push parameters onto stack
  • • Advantage: Unlimited parameters
  • • Limitation: Stack management overhead
  • • Best for: Many parameters

Memory Block

  • • Method: Store parameters in memory block
  • • Advantage: Large data structures
  • • Limitation: Memory management complexity
  • • Best for: Complex data

System Call vs Function Call

AspectFunction CallSystem Call
Execution ModeUser modeKernel mode
Context SwitchNoYes
OverheadLowHigh
Access to ResourcesLimitedFull system access
Error HandlingApplication-levelKernel-level validation

📝 Exam Tips

  • • Understand the difference between user mode and kernel mode
  • • Know the system call execution mechanism steps
  • • Be familiar with different parameter passing methods
  • • Practice identifying appropriate system calls for different operations
  • • Understand the overhead and security implications of system calls