What is the concept of system call mechanism?


System call mechanism is one of the techniques by which a user program requests for services from the kernel. System calls always provide an interface to the services that are available by an operating system.

Let us see the step by step explanation of system call mechanism as given below −

Step 1 − A process that is running a user program in user mode wants to execute a read instruction a file and it has to execute a trap instruction to transfer control to the operating system.

Step 2 − The read operation in system call has three parameters which are as follows −

  • Specifying the file.

  • Pointing to the buffer.

  • Giving the number of bytes to read.

Step 3 − Count = read (fd, buffer, nbytes);

Step 4 − First the parameters are pushed onto the stack.

Step 5 − Library procedures are called in the previous step (step 4).

Step 6 − The library procedure, are written in assembly language, typically place the system call number in a place where the operating system expects it, like a register (step 5)

Step 7 − Then to switch from user mode to kernel mode and start execution at a fixed address within the kernel (step 6), it executes a TRAP instruction

Step 8 − The kernel code starts following the TRAP examines the system-call number and then dispatches to the correct system-call handler, usually via a table of pointers to system-call handlers indexed on system-call number (step 7).

Step 9 − At that point the system-call handler runs (step 8).

Step 10 − Once it has completed its work, control may be returned to the user-space library procedure at the instruction following the TRAP instruction (step 9).

Step 11 − This procedure then returns to the user program in the usual way procedure calls return (step 10).

Given below is the diagram of system call mechanism −

Updated on: 29-Nov-2021

703 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements