What is the best way to make system calls manually?

We’re not using system calls directly, it is used by glibc wrapper functions. Is there any way to manually make a system call?

You can use syscall() function to make any system call manually. It takes variable length of arguments. You need to give the system call number as the first parameter and others if exists.

You have to use defined names in sys/syscall.h rather than using the numbers directly.

For example to close a file you can use following code snippet:

#include <sys/syscall.h>
...
syscal(SYS_close, fd);

Some of the system calls doesn’t have a corresponding glibc wrapper function. For example, if you want to get PID value of your newly created threads, you have to make gettid system call to get thread identification but there is no glibc wrapper function for this. So, you need to call it manually like this:

pid_t tid = syscall(SYS_gettid);