| 1 |
.\" Copyright 2007, Michael Kerrisk <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH intro 2 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
intro \- introduction to system calls |
| 9 |
.SH DESCRIPTION |
| 10 |
Section 2 of the manual describes the Linux system calls. |
| 11 |
A system call is an entry point into the Linux kernel. |
| 12 |
Usually, system calls are not invoked directly: |
| 13 |
instead, most system calls have corresponding C library |
| 14 |
wrapper functions which perform the steps required |
| 15 |
(e.g., trapping to kernel mode) in order to invoke |
| 16 |
the system call. |
| 17 |
Thus, making a system call looks the same as invoking a normal |
| 18 |
library function. |
| 19 |
.P |
| 20 |
In many cases, the C library wrapper function does nothing more than: |
| 21 |
.IP \[bu] 3 |
| 22 |
copying arguments and the unique system call number to the |
| 23 |
registers where the kernel expects them; |
| 24 |
.IP \[bu] |
| 25 |
trapping to kernel mode, |
| 26 |
at which point the kernel does the real work of the system call; |
| 27 |
.IP \[bu] |
| 28 |
setting |
| 29 |
.I errno |
| 30 |
if the system call returns an error number when the kernel returns the |
| 31 |
CPU to user mode. |
| 32 |
.P |
| 33 |
However, in a few cases, a wrapper function may do rather more than this, |
| 34 |
for example, performing some preprocessing |
| 35 |
of the arguments before trapping to kernel mode, |
| 36 |
or postprocessing of values returned by the system call. |
| 37 |
Where this is the case, the manual pages in Section 2 generally |
| 38 |
try to note the details of both the (usually GNU) C library API |
| 39 |
interface and the raw system call. |
| 40 |
Most commonly, the main DESCRIPTION will focus on the C library interface, |
| 41 |
and differences for the system call are covered in the NOTES section. |
| 42 |
.P |
| 43 |
For a list of the Linux system calls, see |
| 44 |
.BR syscalls (2). |
| 45 |
.SH RETURN VALUE |
| 46 |
On error, most system calls return a negative error number |
| 47 |
(i.e., the negated value of one of the constants described in |
| 48 |
.BR errno (3)). |
| 49 |
The C library wrapper hides this detail from the caller: when a |
| 50 |
system call returns a negative value, the wrapper copies the |
| 51 |
absolute value into the |
| 52 |
.I errno |
| 53 |
variable, and returns \-1 as the return value of the wrapper. |
| 54 |
.P |
| 55 |
The value returned by a successful system call depends on the call. |
| 56 |
Many system calls return 0 on success, but some can return nonzero |
| 57 |
values from a successful call. |
| 58 |
The details are described in the individual manual pages. |
| 59 |
.P |
| 60 |
In some cases, |
| 61 |
the programmer must define a feature test macro in order to obtain |
| 62 |
the declaration of a system call from the header file specified |
| 63 |
in the man page SYNOPSIS section. |
| 64 |
(Where required, these feature test macros must be defined before including |
| 65 |
.I any |
| 66 |
header files.) |
| 67 |
In such cases, the required macro is described in the man page. |
| 68 |
For further information on feature test macros, see |
| 69 |
.BR feature_test_macros (7). |
| 70 |
.SH STANDARDS |
| 71 |
Certain terms and abbreviations are used to indicate UNIX variants |
| 72 |
and standards to which calls in this section conform. |
| 73 |
See |
| 74 |
.BR standards (7). |
| 75 |
.SH NOTES |
| 76 |
.SS Calling directly |
| 77 |
In most cases, it is unnecessary to invoke a system call directly, |
| 78 |
but there are times when the Standard C library does not implement |
| 79 |
a nice wrapper function for you. |
| 80 |
In this case, the programmer must manually invoke the system call using |
| 81 |
.BR syscall (2). |
| 82 |
Historically, this was also possible using one of the _syscall macros |
| 83 |
described in |
| 84 |
.BR _syscall (2). |
| 85 |
.SS Authors and copyright conditions |
| 86 |
Look at the header of the manual page source for the author(s) and copyright |
| 87 |
conditions. |
| 88 |
Note that these can be different from page to page! |
| 89 |
.SH SEE ALSO |
| 90 |
.ad l |
| 91 |
.nh |
| 92 |
.BR _syscall (2), |
| 93 |
.BR syscall (2), |
| 94 |
.BR syscalls (2), |
| 95 |
.BR errno (3), |
| 96 |
.BR intro (3), |
| 97 |
.BR capabilities (7), |
| 98 |
.BR credentials (7), |
| 99 |
.BR feature_test_macros (7), |
| 100 |
.BR mq_overview (7), |
| 101 |
.BR path_resolution (7), |
| 102 |
.BR pipe (7), |
| 103 |
.BR pty (7), |
| 104 |
.BR sem_overview (7), |
| 105 |
.BR shm_overview (7), |
| 106 |
.BR signal (7), |
| 107 |
.BR socket (7), |
| 108 |
.BR standards (7), |
| 109 |
.BR symlink (7), |
| 110 |
.BR system_data_types (7), |
| 111 |
.BR sysvipc (7), |
| 112 |
.BR time (7) |