What is the Difference Between System Call and Function Call

The main difference between system call and function call is that a system call is a request for the kernel to access a resource while a function call is a request made by a program to perform a specific task.

Although the two terms are used interchangeably, there is a difference between system call and function call. System calls are used when a program needs to communicate with the kernel while function calls are used to call a specific function within the program.

Key Areas Covered

1. What is System Call
     – Definition, Functionality
2. What is Function Call
     – Definition, Functionality
3. Difference Between System Call and Function Call
     – Comparison of Key Differences

Key Terms

Context Switching, Function Call, Kernel Mode, System Call, User Mode

Difference Between System Call and Function Call - Comparison Summary

What is a System Call

Before learning about system calls, it is first important to know the basic operations of a computer. A computer operates in two modes called kernel mode and user mode. Kernel mode is a privileged mode that allows programs to access memory or any other hardware resource directly. However, in user mode, the programs cannot directly access memory and hardware resources. But, most programs in the operating system execute in the user mode.

When a program needs memory or a resource, it communicates with the kernel via a system call. In other words, a system call is a request sent by the program to the kernel to access a resource. Then the mode changes from user mode to the kernel mode. After completing the task, the mode switches back to the user mode. We call this mode transition as context switching.

Difference Between System Call and Function Call

Two system calls in UNIX systems are fork and exec. The fork() system call creates a new process without destroying the existing process. Then, the existing process becomes the parent process while the new process becomes the child process. Moreover, the exec() is also a system call that creates a new process. It creates a new process and destroys the existing process.

What is Function Call  

A function call is a call that passes control to a function. A function is a set of statements that performs a specific task. Rather than writing all the statements inside the main function, the programmer can call the functions as required. Syntax of a function is as follows.

return_type function_name(parameter list){

            //statements inside the function

}

The return type refers to the data type of the value the function returns. If the function returns an integer, the return type is “int”. However, if the function returns a float, the return type is “float”.  Moreover, if the function does not return anything, it is “void.

The function name is the actual name to identify the function. It is possible to pass parameters to the function to perform the task. The statements of the function are inside the curly braces. When there is a function call in the program, that specific function gets the control and is executed. Furthermore, after executing the function, the control passes back to the main program.

Difference Between System Call and Function Call

Definition

A system call is a function provided by the kernel to enter kernel mode to access a resource while a function call is a request made by a program or script that execute a predetermined function. Thus, this is the main difference between system call and function call.

Context switching

Also, another difference between system call and function call is the context switching. Context switching occurs in system calls; however, there is no context switching occurrence in function calls.

Functionality

System calls allow the program to access memory or a hardware resource from the kernel while function calls help to pass the control to a specific function and to execute the defined task. Hence, this is the functional difference between system call and function call.

Conclusion

In brief, system calls are associated with kernel mode while function calls are associated with user mode. The main difference between system call and function call is that a system call is a request for the kernel to access a resource while a Function Call is a request made by a program to perform a specific task.

References:

1.“Introduction to System Calls.” Studytonight, Available here.
2.”What is a Function Call?” Computer Hope’s Free Computer Help, 26 Apr. 2017, Available here.

Image Courtesy:

1.” System call interface” By system call interface – (CC BY-SA 4.0) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply