Operating System - System Calls in Operating Systems
System calls are interfaces between a user program and the operating system kernel. They allow user-level processes to request services from the OS like file operations, memory management, and process control.
Below are 5 important types of system calls:
1. File Management System Calls
These system calls allow programs to create, delete, read, write, or modify files and directories.
Examples:
-
open()– Open a file -
read()– Read data from a file -
write()– Write data to a file -
close()– Close an open file
Use Case: When a program wants to save user data into a file or read from a configuration file.
2. Process Control System Calls
These manage process creation, termination, and execution control.
Examples:
-
fork()– Create a new process -
exec()– Replace current process image with a new one -
exit()– Terminate a process -
wait()– Wait for a child process to finish
Use Case: When launching a new program (e.g., opening a browser from a terminal).
3. Memory Management System Calls
Used to allocate and deallocate memory during program execution.
Examples:
-
malloc()(in C library, internally usesbrk()ormmap()) -
mmap()– Map files or devices into memory -
shmget()– Get shared memory segment
Use Case: When a program needs to reserve space in memory for variables, buffers, or data structures.
4. Communication System Calls
Support inter-process communication (IPC), both within a single system and over networks.
Examples:
-
pipe()– Create a communication channel between processes -
send(),recv()– Send or receive messages -
socket()– Create a network socket -
connect()– Connect to a remote server
Use Case: Used in chat applications, client-server models, and networking tools.
5. Device Management System Calls
Allow interaction with I/O devices, like reading from or writing to a device.
Examples:
-
ioctl()– Control device behavior -
read()– Read from a device (like a keyboard) -
write()– Write to a device (like a printer) -
open()/close()– Used for device files too
Use Case: When a program accesses hardware like reading input from a mouse or sending output to a display.