System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE) PDF Download

Introduction

A system call is a way for a user program to interface with the operating system. The program requests several services, and the OS responds by invoking a series of system calls to satisfy the request. A system call can be written in assembly language or a high-level language like C or Pascal. System calls are predefined functions that the operating system may directly invoke if a high-level language is used.
In this article, you will learn about the system calls in the operating system and discuss their types and many other things.

What is a System Call?

  • A system call is a method for a computer program to request a service from the kernel of the operating system on which it is running. A system call is a method of interacting with the operating system via programs. A system call is a request from computer software to an operating system's kernel.
  • The Application Program Interface (API) connects the operating system's functions to user programs. It acts as a link between the operating system and a process, allowing user-level programs to request operating system services. The kernel system can only be accessed using system calls. System calls are required for any programs that use resources.

How are system calls made?

When a computer software needs to access the operating system's kernel, it makes a system call. The system call uses an API to expose the operating system's services to user programs. It is the only method to access the kernel system. All programs or processes that require resources for execution must use system calls, as they serve as an interface between the operating system and user programs.

Below are some examples of how a system call varies from a user function.

  • A system call function may create and use kernel processes to execute the asynchronous processing.
  • A system call has greater authority than a standard subroutine. A system call with kernel-mode privilege executes in the kernel protection domain.
  • System calls are not permitted to use shared libraries or any symbols that are not present in the kernel protection domain.
  • The code and data for system calls are stored in global kernel memory.

Question for System Calls
Try yourself:
What is a system call?
View Solution

Why do you need system calls in Operating System?

There are various situations where you must require system calls in the operating system. Following of the situations are as follows:

  • It is must require when a file system wants to create or delete a file.
  • Network connections require the system calls to sending and receiving data packets.
  • If you want to read or write a file, you need to system calls.
  • If you want to access hardware devices, including a printer, scanner, you need a system call.
  • System calls are used to create and manage new processes.

How System Calls Work

  • The Applications run in an area of memory known as user space. A system call connects to the operating system's kernel, which executes in kernel space. When an application creates a system call, it must first obtain permission from the kernel. It achieves this using an interrupt request, which pauses the current process and transfers control to the kernel.
  • If the request is permitted, the kernel performs the requested action, like creating or deleting a file. As input, the application receives the kernel's output. The application resumes the procedure after the input is received. When the operation is finished, the kernel returns the results to the application and then moves data from kernel space to user space in memory.
  • A simple system call may take few nanoseconds to provide the result, like retrieving the system date and time. A more complicated system call, such as connecting to a network device, may take a few seconds. Most operating systems launch a distinct kernel thread for each system call to avoid bottlenecks. Modern operating systems are multi-threaded, which means they can handle various system calls at the same time.

Types of System Calls

There are commonly five types of system calls. These are as follows:


System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

  • Process Control
  • File Management
  • Device Management
  • Information Maintenance
  • Communication

Now, you will learn about all the different types of system calls one-by-one.

  • Process Control
    Process control is the system call that is used to direct the processes. Some process control examples include creating, load, abort, end, execute, process, terminate the process, etc.
  • File Management
    File management is a system call that is used to handle the files. Some file management examples include creating files, delete files, open, close, read, write, etc.
  • Device Management
    Device management is a system call that is used to deal with devices. Some examples of device management include read, device, write, get device attributes, release device, etc.
  • Information Maintenance
    Information maintenance is a system call that is used to maintain information. There are some examples of information maintenance, including getting system data, set time or date, get time or date, set system data, etc.
  • Communication
    Communication is a system call that is used for communication. There are some examples of communication, including create, delete communication connections, send, receive messages, etc.

Question for System Calls
Try yourself:
Why are system calls necessary in an operating system?
View Solution

Examples of Windows and Unix system calls
There are various examples of Windows and Unix system calls. These are as listed below in the table:
System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

Here, you will learn about some methods briefly:

open()
The open() system call allows you to access a file on a file system. It allocates resources to the file and provides a handle that the process may refer to. Many processes can open a file at once or by a single process only. It's all based on the file system and structure.

read()
It is used to obtain data from a file on the file system. It accepts three arguments in general:

  • A file descriptor.
  • A buffer to store read data.
  • The number of bytes to read from the file.

The file descriptor of the file to be read could be used to identify it and open it using open() before reading.

wait()
In some systems, a process may have to wait for another process to complete its execution before proceeding. When a parent process makes a child process, the parent process execution is suspended until the child process is finished. The wait() system call is used to suspend the parent process. Once the child process has completed its execution, control is returned to the parent process.

write()
It is used to write data from a user buffer to a device like a file. This system call is one way for a program to generate data. It takes three arguments in general:

  • A file descriptor.
  • A pointer to the buffer in which data is saved.
  • The number of bytes to be written from the buffer.

fork()
Processes generate clones of themselves using the fork() system call. It is one of the most common ways to create processes in operating systems. When a parent process spawns a child process, execution of the parent process is interrupted until the child process completes. Once the child process has completed its execution, control is returned to the parent process.

close()
It is used to end file system access. When this system call is invoked, it signifies that the program no longer requires the file, and the buffers are flushed, the file information is altered, and the file resources are de-allocated as a result.

exec()
When an executable file replaces an earlier executable file in an already executing process, this system function is invoked. As a new process is not built, the old process identification stays, but the new process replaces data, stack, data, head, etc.

exit()
The exit() is a system call that is used to end program execution. This call indicates that the thread execution is complete, which is especially useful in multi-threaded environments. The operating system reclaims resources spent by the process following the use of the exit() system function.

The document System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Question Bank for GATE Computer Science Engineering.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
62 videos|7 docs|165 tests

Up next

FAQs on System Calls - Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

1. How are system calls made?
Ans. System calls are made by programs in order to request services from the operating system. This is done by executing a special instruction called a trap or software interrupt, which transfers control from the user program to the operating system. The system call number is passed in a register or as an argument to the trap instruction, and the necessary data for the system call is also passed through registers or memory.
2. How do system calls work?
Ans. When a system call is made, the operating system switches from user mode to kernel mode to fulfill the requested service. The system call handler in the operating system performs the necessary operations, such as accessing files, allocating memory, or managing processes. After the system call completes, the operating system returns control back to the user program.
3. What are some common types of system calls?
Ans. Some common types of system calls include: - File system calls: These are used to create, read, write, and delete files and directories. - Process control calls: These are used to create, terminate, and manage processes. - Memory management calls: These are used to allocate and deallocate memory. - Communication calls: These are used to establish communication between processes, such as through sockets or pipes. - Device I/O calls: These are used to interact with hardware devices, such as reading from or writing to a disk.
4. How are system call parameters passed?
Ans. System call parameters can be passed in different ways depending on the architecture and operating system. Some common methods include: - Passing parameters through registers: In some architectures, system call parameters are passed through specific registers. - Passing parameters through a stack: In this method, the parameters are pushed onto the stack before making the system call, and the system call handler retrieves them from the stack. - Passing parameters through a memory buffer: The parameters can be stored in a memory buffer, and the address of the buffer is passed as a parameter to the system call.
5. What happens if a system call fails?
Ans. If a system call fails, it typically returns an error code to the user program. The program can then check this error code to determine the cause of the failure and take appropriate actions. The error code can indicate reasons such as invalid parameters, insufficient permissions, or resource unavailability. The program can handle the error by retrying the system call, terminating gracefully, or displaying an error message to the user.
62 videos|7 docs|165 tests
Download as PDF

Up next

Explore Courses for Computer Science Engineering (CSE) exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!
Related Searches

System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

,

video lectures

,

Exam

,

Objective type Questions

,

Important questions

,

study material

,

Extra Questions

,

Viva Questions

,

System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

,

mock tests for examination

,

ppt

,

Free

,

past year papers

,

Previous Year Questions with Solutions

,

practice quizzes

,

pdf

,

Sample Paper

,

Summary

,

shortcuts and tricks

,

Semester Notes

,

System Calls | Question Bank for GATE Computer Science Engineering - Computer Science Engineering (CSE)

,

MCQs

;