System calls in linux and windows

System Calls in OS (Operating System)

System call is the special function that is used by the process to request action from the operating system which cannot be carried out by normal function. System calls provide the interface between the process and the operating system.

What are System Calls in OS?

Professor: Alice can you tell me the two main functions of the operating system (OS)?

Alice: Resource allocation and Providing environment so that process can execute

Professor: Very good Alice, seems like you have your basics clear. So now let’s understand how the process interacts with the OS. What are system calls in OS, Different Types of System calls, and a few examples of system calls as well?

When the process is being run, if the process requires certain actions which need to be carried out by Operating System, the process has to go call the function which can interact with the kernel to complete the actions. This special type of function call is known as System Calls in OS. System calls provide the interface so that the process can communicate with the Operating System.

Note: Kernel is the core component of the Operating System that has complete control of the hardware.

intro system call

Bob: But Professor, How are System Calls in OS made?

Professor: Let’s understand that in detail bob.

How Does the System Call Work?

Professor: Before an understanding of the working of system calls in OS let us understand the important concept of modes of operation.

In our computer system, we have two modes available.

working system

  1. User Mode: In this mode, execution is done on behalf of the user.
  2. Monitor/Kernel-Mode: In this mode, execution is done on behalf of OS.
  • So when the process is under execution process executes under user mode, but when the process requires some os resources to complete the task, the process makes a system call.
  • System calls in OS are executed in kernel mode on a priority basis.
  • On completion of the system call, the control is passed to process in user mode.
  • The process continues the execution in user mode.

Alice: Professor, for any type of access, do we have a specific type of system call?

Professor: Yes Alice, we have different types of system calls, which we will see in the next section.

Types of System Calls in OS

There are mainly 5 types of system calls available:

Types of System Calls

  • Process Control
  • File Management
  • Device Management
  • Information Maintenance
  • Communication
  1. Process Control: It handles the system calls for process creation, deletion, etc. Examples for process control system calls are: Load , Execute , Abort , Wait Signal events for process .
  2. File Management: File manipulation events like Creating , Deleting , Reading Writing etc are being classified under file management system calls.
  3. Device Management: Device Management system calls are being used to request the device , release the device , logically attach and detach the device .
  4. Information Maintenance: This type of system call is used to maintain the information about the system like time and date .
  5. Communications: In order to have interprocess communications like send or receive the message , create or delete the communication connections , to transfer status information etc communication system calls are used.
Читайте также:  Installing java runtime on linux

Professor: I know this is a bit theoretical, so let’s see some real-world system calls.

Example of System Calls in Windows and Unix

Types of System Calls Windows Linux
CreateProcess() fork()
Process Control ExitProcess() exit()
WaitForSingleObject() wait()
CreateFile() open()
ReadFile() read()
File Management WriteFile() write()
CloseHandle() close()
SetConsoleMode() ioctl()
Device Management ReadConsole() read()
WriteConsole() write()
GetCurrentProcessID() getpid()
Information Maintenance SetTimer() alarm()
Sleep() sleep()
CreatePipe() pipe()
Communication CreateFileMapping() shmget()
MapViewOfFile() mmap()

system call dispatch

Professor: As we can’t see each and every system call in detail, let us take read() system call of file management and understand how it works.

  • As we can see in the diagram, initially, the process pushes the parameter onto the stack.
  • After that, the read routine from the library is called, which puts the system call code (unique code for each system call is assigned) into the register.
  • Trap instruction is used which causes the transfer of control from user mode to kernel mode.
  • Kernel reads the system call code present in the register and finds out that the system call is read, so the system call handler executes the read system call.
  • After the execution of the read system call, the transfer is given back to the user mode.
  • The library routine (Library routine is nothing but the line of codes that forms the library and the functions in that can be called by the process so that we don’t need to write the function every time. Eg. max function) in user mode returns the output to the process which called it.
  • On receiving the output, the process continues to execute the next instruction.

Note: Trap is the kind of interrupt that is synchronous to the process for executing the functionality.

Bob: ohh! Never thought that simply reading our computer carries out so many tasks.

Professor: Yes Bob, but do you know what parameters we can pass to the system call?

Bob: No professor, and let me guess! Is this the next topic which we will be studying?

Professor: Smart Bob!

Rules for Passing Parameters in System Call

  1. The floating-point parameters can’t be passed as a parameter in the system call.
  2. Only a limited number of arguments can be passed in the system call.
  3. If there are more arguments, then they should be stored in the block of memory and the address of that memory block is stored in the register.
  4. Parameters can be pushed and popped from the stack only by the operating system.
Читайте также:  Linux get number files directory

Professor: Let’s see some important system calls of our computer system.

Important System Calls Used in OS

  1. wait(): There are scenarios where the current process needs to wait for another process to complete the task. So to wait in this scenario, wait() system call is used.
  2. fork(): This system call creates the copy of the process which has called it. The one which has called fork is called the parent process and the newly created copy is called the child process.
  3. exec(): This system call is called when the running process wants to execute another executable file. The process id remains the same while the other resources used by the process are replaced by the newly created process.
  4. kill(): Sometimes while working, we require to terminate a certain process. So kill system call is called which sends the termination signal to the process.
  5. exit(): When we are actually required to terminate the program, an exit system call is used. The resources which are occupied by the process are released after invoking the exit system call.

Alice: Professor, so kill() system call won’t necessarily terminate the process, right?

Professor: Correct Alice, good you understood that. Most students get confused with that system call. Let’s recall what we learned.

Conclusion

  • System call is the interface through which the process communicates with the system call.
  • Computer system operates in two modes: User Mode and Kernel Mode
  • Process executes in user mode, and when a system call is made, the mode is switched to kernel mode. Once the system call execution is completed, the control is passed back to the process in user mode.
  • System calls in OS are made by sending a trap signal to the kernel, which reads the system call code from the register and executes the system call.
  • Major type of sytem calls are Process Control, File Management, Device Management, Information maintenance and Communicaiton.
  • Rules for parameter passing while making a system call is it should not be a floating number, a limited number of arguments should be passed and if arguments are more, they should be stored in memory block and address of that memory block should be passed, and the push, pop operations from the stack will be made only by the operating system.
  • wait(), fork(), exec(), kill() and exit() are few important system calls of our computer system.

Источник

System Calls in Unix and Windows

The interface between a process and an operating system is provided by system calls. In general, system calls are available as assembly language instructions. They are also included in the manuals used by the assembly level programmers.

Читайте также:  Добавление сетевой папки astra linux

Unix System Calls

System calls in Unix are used for file system control, process control, interprocess communication etc. Access to the Unix kernel is only available through these system calls. Generally, system calls are similar to function calls, the only difference is that they remove the control from the user process.

There are around 80 system calls in the Unix interface currently. Details about some of the important ones are given as follows —

System Call Description
access() This checks if a calling process has access to the required file
chdir() The chdir command changes the current directory of the system
chmod() The mode of a file can be changed using this command
chown() This changes the ownership of a particular file
kill() This system call sends kill signal to one or more processes
link() A new file name is linked to an existing file using link system call.
open() This opens a file for the reading or writing process
pause() The pause call suspends a file until a particular signal occurs.
stime() This system call sets the correct time.
times() Gets the parent and child process times
alarm() The alarm system call sets the alarm clock of a process
fork() A new process is created using this command
chroot() This changes the root directory of a file.
exit() The exit system call is used to exit a process.

Windows System Calls

System calls in Windows are used for file system control, process control, interprocess communication, main memory management, I/O device handling, security etc. The programs interact with the Windows operating system using the system calls. Since system calls are the only way to access the kernel, all the programs requiring resources must use system calls.

Details about some of the important system calls in Windows are given as follows —

System Call Description
CreateProcess() A new process is created using this command
ExitProcess() This system call is used to exit a process.
CreateFile() A file is created or opened using this system call.
ReadFile() Data is read from the file using this system call.
WriteFile() Data is written into the file using this system call.
CloseHandle() This system call closes the file currently in use.
SetTimer() This system call sets the alarm or the timer of a process
CreatePipe() A pipe is created using this system call
SetFileSecurity() This system call sets the security for a particular process
SetConsoleMode() This sets the input mode or output mode of the console’s
input buffer or output screen buffer respectively.
ReadConsole() This reads the characters from the console input buffer.
WriteConsole() This writes the characters into the console output buffer.

Источник

Оцените статью
Adblock
detector