For enquiries call:

Phone

+1-469-442-0620

April flash sale-mobile

HomeBlogWeb DevelopmentSystem Calls in Operating System: Overview, Types & Examples

System Calls in Operating System: Overview, Types & Examples

Published
03rd Jan, 2024
Views
view count loader
Read it in
16 Mins
In this article
    System Calls in Operating System: Overview, Types & Examples

    A system call is a function that a user program uses to ask the operating system for a particular service. User programmers can communicate with the operating system to request its services using the interface that is created by a system call.

    System calls serve as the interface between an operating system and a process. System calls can typically be found as assembly language instructions. They are also covered in the manuals that the programmers working at the assembly level use. When a process in user mode needs access to a resource, system calls are typically generated. The resource is then requested from the kernel via a system call.

    System calls are always carried out in the operating system's kernel mode. We will talk about what is system call in OS? and how a system call works in this article. Its operation, types, and how to pass parameters to such calls will be covered. If you’re looking to learn full stack development or just need some full stack react project ideas, be sure to check out Full Stack Web Developer Course.

    System Calls in Operating System

    Source: Scalar.com

    What is a System Call in Operating System (OS)?

    A system calls in computing is the programmatic method by which a computer programme asks the kernel of the operating system it is running on for a service. Programs can interact with the operating system by making a system call. When a computer programme requests something from the kernel of the operating system, it performs a system call.

    System call uses Application Programming Interfaces to provide operating system services to user programmes (API). It offers a point of contact between processes and the operating system so that user-level processes can ask for the operating system's assistance. The only ways to access the kernel system are through system calls. System calls are required for all programmes that require resources.

    The following is a diagram that illustrates what is system call in an operating system and how the system call is executed:

    What is System Call in Operating System
    Source: Tutorialspoint.com

    This diagram shows how the processes normally run in user mode until a system call interrupts them. The system call is then carried out in kernel mode according to priority. The control switches back to user mode after the system call has been completed, allowing user processes to continue running.

    Example of System Calls

    Following are the examples of system calls:

    The most common system calls used on Unix system calls, Unix-like, and other POSIX-compliant operating systems are open, read, write, close, wait, exec, fork, exit, and kill. There are hundreds of systems calls in many contemporary operating systems. For instance, Linux and OpenBSD each have over 300 different calls, NetBSD and FreeBSD both have over 500, and Windows has close to 2000 system calls, split between win32k and ntdll.

    Tools like strace, ftrace, and truss allow a process to run from the beginning and report every system call it makes. They can also attach to an already running process and intercept any system call made by that process if the action does not conflict with the user's permissions.

    If we need to copy data from one file into another, we can do so by writing programme code. The names of the two files, the input and output files, are the first piece of data that the programme needs. This kind of programme execution requires some system calls from the OS in an interactive system.

    • Writing a prompting message on the screen comes first.
    • Second, read the characters that define the two files from the keyboard.

    How Does the System Call work?

    The Applications operate in user space, a portion of memory. The operating system's kernel, which runs in kernel space, is reached through a system call. An application must first request permission from the kernel before it can create a system call. It accomplishes this by sending an interrupt request, which pauses the running process and gives the kernel control.

    The kernel carries out the requested action, such as creating or deleting a file, if the request is approved. The output of the kernel is provided to the application as input. Once the input is received, the application continues the process. The kernel transfers data from kernel space to user space in memory after the operation is complete and returns the results to the application.

    A straightforward system call, like getting the system date and time, might only return a result in a few nanoseconds. It might take a few seconds to complete a more complex system call, like connecting to a network device. To prevent bottlenecks, most operating systems start a separate kernel thread for each system call. Because modern operating systems are multi-threaded, they can manage multiple system calls concurrently. Moreover, this is also a great opportunity to gain practical experience while you complete your Web Development Crash Course.

    Types of System Calls in OS

    There are primarily 5 different types of system calls in the operating system:

    1. Process Control

    The following services are provided by Process Control System calls that are used to control a process.

    • To forcefully abort the process, simply end it normally.
    • Execute a process after loading it into the main memory.
    • Terminate the current process before starting a new one.
    • Wait for a process to complete running. Wait until a specific event happens, then announce it once it has.
    • Allocate memory to a process, then release the memory if the process is terminated.

    2. File Management

    The following services are provided by system call for file management:

    • Making and erasing files 
    • Open the file, then close it. 
    • Write to a specific file, read from a specific file. 
    • To obtain a file's attribute and to change a file's attribute 

    3. Device Management

    The following services are offered by a system call that controls I/O devices:

    • Devices might be needed while a process is running. such as access to the file system, I/O devices, main memory, etc.
    • As a result, it can ask for a device and then release it once the task is complete.
    • when a requested device is granted access by the process. It is capable of reading, writing, and repositioning operations.
    • In order to obtain or modify a specific device's attribute.
    • To detach a device from the processor that is currently executing a command, the call can be made.

    4. Information Maintenance

    The system calls for information maintenance call moves data from the user programme to the operating system. Considering this, the services offered by this type of system call are:

    • Obtain the system's time or date. Set the system's time or date.
    • Obtain system-related information. Configure the system data.
    • Obtain the characteristics of a specific operating system process. Alternatively, of a specific file on the system or on any attached devices.
    • Set the characteristics of a specific operating system process. Alternatively, of a specific file on the system or on any attached devices.

    5. Communication

    Such a system call facilitates the system's network connection. The services that these system calls offer are:

    • Open a fresh connection to send the data. After the transmission is finished, disconnect from the connection. 
    • On a particular connection, send a message. Obtain communication from a specific connection.
    • Identify and connect a specific remote device to the network. Remove a specific remote computer or device from the network.

    Example of System Calls in Windows and Unix

    Types of System CallsWindowsLinux
    Process ControlCreateProcess()
    ExitProcess()
    WaitForSingleObject()
    fork()
    exit()
    wait()
    File ManagementCreateFile()
    ReadFile()
    WriteFile()
    CloseHandle()
    open()
    read()
    write()
    close()
    Device ManagementSetConsoleMode()
    ReadConsole()
    WriteConsole()
    ioctl()
    read()
    write()
    Information MaintenanceGetCurrentProcessID()
    SetTimer()
    Sleep()
    getpid()
    alarm()
    sleep()
    CommunicationCreatePipe()
    CreateFileMapping()
    MapViewOfFile()
    pipe()
    shmget()
    mmap()

    Rules for Passing Parameters to the System Call

    Following are the rules for passing parameters to the system call:

    • The system call cannot accept the floating-point parameters as a parameter. 
    • In the system call, a finite number of arguments may be passed. 
    • If there are additional arguments, they should be stored in the memory block, and the register contains the address of that memory block. 
    • Only the operating system has the ability to push parameters and pop them from the stack. 

    Important System Calls Used in OS

    1. wait()

    In certain systems, a process must wait for another process to finish running before continuing. When a parent process creates a child process, the parent process's execution is suspended until the child process has finished running.

    With a wait() system call, the parent process is automatically suspended. Control returns to the parent process once the child process has completed its execution.

    2. fork()

    The fork system call in OS is used by processes to make copies of themselves. By using this system, the Call parent process can create a child process, and the parent process's execution will be halted while the child process runs.

    3. exec()

    When an executable file replaces an earlier executable file within the context of an active process, this system call is executed. The original process identifier is still present even though a new process is not created; instead, the new process replaces the old one's stack, data, head, data, etc.

    4. kill()

    The OS uses the kill() system call to urge processes to terminate by sending them a signal. A kill system call can have different meanings and is not always used to end a process.

    5. exit()

    An exit system call is used when the programme must be stopped. When the exit system call is used, the resources that the process was using were released.

    Why Do You Need System Calls in Operating System?

    The following circumstances involve the use of system calls in OS: 

    • System calls are necessary for reading and writing from files. 
    • System calls are necessary for a file system to add or remove files. 
    • New processes are created and managed using system calls. 
    • System calls are required for packet sending and receiving over network connections. 
    • A system call is required to access hardware devices like scanners and printers. 

    What is the Purpose of System Calls in OS?

    The purpose of system calls serves as the interface between an operating system and a process. System calls can typically be found as assembly language instructions. They are also covered in the manuals that the programmers working at the assembly level use. When a process in user mode needs access to a resource, system calls are typically generated. The resource is then requested from the kernel via a system call. 

    System calls are required in in following circumstances:

    • If a file system needs files to be created or deleted. A system call is also necessary for reading and writing from files.
    • development and administration of new procedures.
    • System calls are also required for network connections. This also applies to packet sending and receiving. 
    • A system call is necessary to access hardware such as a printer, scanner, etc. 

    Looking to master Python programming? Discover the best Python programming course that guarantees to take your skills to the next level. Start coding like a pro today!

    Conclusion

    The interface by which the process interacts with the system call is called a system call. There are two operating modes for computers:  

    • kernel mode 
    • user mode

    When a system call is made, the process transitions from user mode to kernel mode. Once the system call has finished running, the control is returned to the user mode process. Sending the kernel, a trap signal causes it to read the system call code from the register and carry out the system call. Process control, file management system calls in OS, device management, information maintenance, and communication are the main types of system calls in OS. Several crucial system calls used by our computer system include wait(), fork(), exec(), kill(), and exit(). Enrol in KnowledgeHut’s Full Stack Web Developer Course to learn the full stack developer skill set.

    Frequently Asked Questions (FAQs)

    1Which System Call Is Used to Run a New Program?

    In computing, the exec system calls in Unix and executes a file that replaces an earlier executable in the context of an already running process. This action is additionally known as an overlay. 

    2What is the Difference Between System Call and System Program?

    The OS's system call specifies the interface between its services and user processes. The user interface of the operating system is defined by the system program, in contrast. The user program's high-level request is fulfilled by the system programme. It breaks the request down into a number of simple requests. 

    3What are the Process Management System Calls?

    A system is used to fork an existing process, which is a process that has been duplicated. All of the information in the file description and common registers make up the duplicate process. The original procedure is also referred to as the parent procedure, and the copy is known as the child procedure.

    Profile

    Abhresh Sugandhi

    Author

    Abhresh is specialized as a corporate trainer, He has a decade of experience in technical training blended with virtual webinars and instructor-led session created courses, tutorials, and articles for organizations. He is also the founder of Nikasio.com, which offers multiple services in technical training, project consulting, content development, etc.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming Web Development Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon