What are system calls? Give examples.

System calls are the way a program interacts with the operating system. They act as a bridge between user-level programs and the kernel, allowing us to request services like file handling, process control, or memory management. For example, in C, functions like read(), write(), fork(), and exec() are system calls.


In-Depth Explanation

Example
Imagine you are writing a program that needs to open a file and read its contents. Your program alone doesn’t know how to directly interact with the hardware like the hard disk. Instead, it asks the operating system to do it through a system call. For instance, when you use open() in C, it’s not your code that directly opens the file—it’s the kernel that does it on your behalf after you invoke the system call.

Real-Life Analogy
Think of system calls like ordering food at a restaurant. You don’t go into the kitchen to cook yourself; instead, you place an order (system call) with the waiter (the operating system), who then interacts with the kitchen (the hardware and kernel) to bring your meal. You simply make a request, and the operating system ensures it’s executed safely and correctly.

Why It Matters
System calls are critical because they provide controlled access to system resources. Without them, user programs could directly access hardware, which would be unsafe and cause conflicts. By standardizing how programs request services, system calls maintain security, stability, and portability across applications.

Use in Real Projects
In real-world applications, system calls are everywhere, even if we don’t notice them. A web server uses socket() and bind() system calls to establish communication over the internet. An operating system scheduler uses system calls like fork() to create processes. Even when you save a file in a text editor, system calls like write() and close() are quietly working in the background.

In summary, system calls are the fundamental interface that lets applications talk to the operating system, making sure programs can use hardware resources safely and efficiently.