Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference fork() and sys_fork()

I seen all system calls (say x) are related with a another call as sys_x(): Ex: fork and sys_fork(),open() and sys_open() etc.

What is significance of these sys_x() calls? Where we can use these calls?

like image 893
my name is GYAN Avatar asked Apr 28 '26 21:04

my name is GYAN


1 Answers

What is significance of these sys_x() calls?

As the name indicates, these are the actual syscalls being executed in kernel mode.

You see, when you call fork(2) or open(2) from your application, you are not invoking a raw syscall directly; instead, you're invoking glibc's wrappers that know how to call the actual syscall. This indirection step is needed because syscall invocation is architecture specific, so the details are hidden in glibc.

Where we can use these calls?

You don't. For one, sys_fork() is Linux-specific; other UNIX variants are not required to (and probably they don't) implement a sys_fork() function. The exact functions inside the kernel that deal with forking are system dependent. It just so happens that Linux has a function called sys_fork(), sys_open(), etc.

For example, in the case of fork(2), in Linux the flow is more or less like:

fork() -> glibc wrapper -> raw syscall invocation -> transition to kernel mode -> syscall lookup -> sys_fork() -> do_fork().

like image 62
Filipe Gonçalves Avatar answered Apr 30 '26 12:04

Filipe Gonçalves