Author DP

Prateek Singh

1+ of articles published

About

Prateek Singh is a highly-skilled at building front-end interfaces. He loves JavaScript ecosystem and have designed & developed multiple products in his career. He has worked in Fintech, E-Commerce, Healthcare & Semi-conductor industries. Prateek enjoys conversation on Programming, Sports, Art, and Space Science. He is fascinated about origin of the universe, the existential reality & the design around us.

Published

Most Popular

System Calls in OS: Different types explained
Blogs
Views Icon

5021

System Calls in OS: Different types explained

Ever wondered how your computer knows to save a file or display a webpage when you click a button? All thanks to system calls – the secret messengers between your apps and your computer’s core. They’re like the backstage crew, quietly making sure everything runs smoothly.  In this article, we’re taking a closer look at system calls – those essential links that help software and your computer’s brain (the kernel) communicate. We’ll break down what they do and why they matter, keeping things simple and easy to understand. So, let’s dive in and uncover the magic behind how your computer really works.  What is a System Call in OS?   System Calls in programs can ask the operating system (OS) for services through a system call. Puting it more simply, it’s a means via which a program can communicate with the underlying system, for example, by gaining access to hardware resources or by using privileged commands.  A program can request a service from the OS by executing a specified instruction, which sets off a transition to kernel mode and initiates a system call. After handling the request and carrying out the required actions, the OS sends the outcome back to the program.  System calls is the connection through which the process communicates with the system calls. Computer operates two types of modes: User Mode and the Kernel Mode. The process runs in a user mode, and when the system call is performed, the mode changes to kernel mode. Once the system call is done, control is returned to the process in user mode.  Example of System Calls in OS  System calls for Windows and Unix come in many different forms. These are listed system calls in OS example in the table below as follows:  Process  Windows  Quiz  Process Control  CreateProcess()  ExitProcess()  WaitForSingleObject()  Fork()  Exit()  Wait()  File manipulation  CreateFile()  ReadFile()  WriteFile()  Open()  Read()  Write()  Close()  Device Management  SetConsoleMode()  ReadConsole()  WriteConsole()  Ioctl()  Read()  Write()  Information Maintenance  GetCurrentProcessID()  SetTimer()  Sleep()  Getpid()  Alarm()  Sleep()  Communication  CreatePipe()  CreateFileMapping()  MapViewOfFile()  Pipe()  Shmget()  Mmap()  Protection  SetFileSecurity()  InitializeSecurityDescriptor()  SetSecurityDescriptorgroup()  Chmod()   Umask()  Chown()  How are System Calls Made?  When computer software wants to access the kernel of the operating system, it makes a system call. The system call in operating system employs an API to make the operating system’s services available to user programs. It is the only way to reach the kernel system. All applications or processes that require resources to run must use system calls, which act as a link between the operating system and user programs.  Here are some examples of how a system call differs from a user function.  A system call function can generate and use kernel processes to perform asynchronous processing.  A system call has more authority than a regular subroutine. A system call with kernel-mode privilege runs in the kernel protection domain.  System calls are not allowed to use shared libraries or symbols that are not part of the kernel protection domain.  The code and data for system calls are kept in global kernel memory.   Looking to enhance your software engineering skills? UpGrad’s Software Development Certification Online offers a comprehensive curriculum designed by industry experts. With hands-on projects and personalized mentorship, it’s the perfect opportunity to advance your career in tech.  Below is the diagram showing the types of system calls in OS – file system, process control, memory management, inter process communication and device management.  Importance of System Calls in Operating System   open(): The open() system call allows you to access a file on a filesystem. It provides the necessary file resources and a handle for the process to use. A file can be opened by numerous processes at the same time, or only one. Everything is built upon the structure and file system.  read(): It is used to get data from a file stored on the file system. Generally, it accepts three arguments.:  A description of a file.  A buffer for read data storage.  wait(): In some systems, a process may have to wait for another process to finish before advancing. When a parent process creates a child process, its execution is delayed until the child process is completed. The wait() system function terminates the parent process. Once the child process has finished its execution, the parent process takes control.  write(): Data from a user buffer is written to a device, such as a file. This system call allows a program to create data in a single method. Overall, there are three arguments:  A description of a file.  A reference to the buffer where data is stored.  The amount of data that will be written from the buffer in bytes.  fork(): Processes use the system call fork() to create clones of themselves. It is one of the most frequent ways for operating systems to define processes. When a parent process creates a child process, the parent process’s execution is halted until the child process is finished. Once the child process has finished its execution, the parent process takes control.  exit(): To terminate a program, call the system function exit(). In multi-threaded environments, this call indicates that thread execution is complete. After using the exit() system function, the operating system recovers the resources used by the process.  Check out the Master of Science in Computer Science from LJMU, offering a top-tier program tailored to industry needs. Provide you with advanced skills and earn a degree from a prestigious institution – take the next step in your software engineering career today!  Types of System Calls   There are typically five sorts of system calls. They are as follows: Now, you’ll learn about each type of system one by one.  Process Control  Process control is a system call that directs processes. Process control examples include creating, loading, aborting, ending, executing, processing, terminating the process, and so on.  File Management  It is a system call used to manage files. File management examples include creating and deleting files, as well as opening, closing, reading, and writing.  Device Management  It is a system call used to interact with devices. Examples of device management include read, device, write, get device attributes, release device, and so on.  Information Maintenance It is a system call in the operating system that stores information. Some examples of information maintenance include getting system data, setting the time or date, getting system data, and so on.  Communication  It is a system call in OS that facilitates communication. Examples of communication include creating and removing communication connections, as well as sending and receiving messages.  Working on System Calls in OS    Here’s a breakdown of how system calls in OS works:-  Limited Power: Programs sometimes need resources they can’t access directly, like reading files, writing data, interacting with hardware, or requesting memory. Making the Request: Special instructions called “system calls” exist within the program’s code to ask the operating system (OS) for help. OS to the Rescue: When the OS encounters a system call, it recognizes the program’s need and temporarily pauses its execution. Control then shifts to the kernel, a central part of the OS responsible for core operations. Kernel in Action: The kernel takes over, carrying out the requested operation. Imagine the kernel as a powerful assistant handling tasks like reading file content or allocating memory. Back to Business: Once the task is complete, the kernel returns control to the program, allowing it to resume execution with the needed resources or information. I hope this rephrased explanation provides a clearer understanding of how system calls empower programs to interact with the underlying OS in a secure and controlled manner.  Advantages of System Calls    System calls act as a vital bridge between programs and the operating system, enabling a range of crucial functionalities:  Hardware Control: Forget direct hardware access hassles! System calls empower programs to interact with essential components like disk drives, printers, and network devices.  Memory Mastery: System calls grant programs the ability to request and release memory, ensuring efficient resource allocation. They also facilitate access to hardware devices mapped directly into memory for seamless data transfer.  Process Powerhouse: Need to create or terminate processes? System calls are your command centre. They also enable programs to communicate with each other, fostering collaboration within your system.  Security Sentinel: System calls act as gatekeepers, ensuring programs only access resources they’re authorized to. This safeguards your system from unauthorized modifications and risky operations.  Standardized Synergy: No matter the hardware or operating system version, system calls provide a consistent interface for programs to interact with the underlying environment. This promotes compatibility and smooths development across different platforms.  Ready to become a Full Stack Developer? Full Stack Development Course by IIITB offers a comprehensive program to master front-end and back-end technologies.  Conclusion   System calls represent the crucial link between user-level applications and the underlying operating system, enabling access to privileged resources and essential functionalities. They serve as the silent facilitators behind the scenes, ensuring seamless communication and interaction between software programs and the kernel. Understanding the diverse types and functionalities of system calls is paramount for software developers and system administrators alike. These calls empower programs to perform a wide array of operations, ranging from hardware control to process management and file manipulation. By leveraging system calls, developers can create robust and efficient software solutions that interact seamlessly with the underlying operating system. 

by Prateek Singh

Calendor icon

29 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon

Explore Free Courses