man2 - System calls

INTRO(2) Linux Programmer's Manual INTRO(2)

intro - introduction to system calls

Section 2 of the manual describes the Linux system calls. A system call is an entry point into the Linux kernel. Usually, system calls are not invoked directly: instead, most system calls have corresponding C library wrapper functions which perform the steps required (e.g., trapping to kernel mode) in order to invoke the system call. Thus, making a system call looks the same as invoking a normal library function.

In many cases, the C library wrapper function does nothing more than:

  • copying arguments and the unique system call number to the registers where the kernel expects them;
  • trapping to kernel mode, at which point the kernel does the real work of the system call;
  • setting errno if the system call returns an error number when the kernel returns the CPU to user mode.

However, in a few cases, a wrapper function may do rather more than this, for example, performing some preprocessing of the arguments before trapping to kernel mode, or postprocessing of values returned by the system call. Where this is the case, the manual pages in Section 2 generally try to note the details of both the (usually GNU) C library API interface and the raw system call. Most commonly, the main DESCRIPTION will focus on the C library interface, and differences for the system call are covered in the NOTES section.

For a list of the Linux system calls, see syscalls(2).

On error, most system calls return a negative error number (i.e., the negated value of one of the constants described in errno(3)). The C library wrapper hides this detail from the caller: when a system call returns a negative value, the wrapper copies the absolute value into the errno variable, and returns -1 as the return value of the wrapper.

The value returned by a successful system call depends on the call. Many system calls return 0 on success, but some can return nonzero values from a successful call. The details are described in the individual manual pages.

In some cases, the programmer must define a feature test macro in order to obtain the declaration of a system call from the header file specified in the man page SYNOPSIS section. (Where required, these feature test macros must be defined before including any header files.) In such cases, the required macro is described in the man page. For further information on feature test macros, see feature_test_macros(7).

Certain terms and abbreviations are used to indicate UNIX variants and standards to which calls in this section conform. See standards(7).

In most cases, it is unnecessary to invoke a system call directly, but there are times when the Standard C library does not implement a nice wrapper function for you. In this case, the programmer must manually invoke the system call using syscall(2). Historically, this was also possible using one of the _syscall macros described in _syscall(2).

Look at the header of the manual page source for the author(s) and copyright conditions. Note that these can be different from page to page!

_syscall(2), syscall(2), syscalls(2), errno(3), intro(3), capabilities(7), credentials(7), feature_test_macros(7), mq_overview(7), path_resolution(7), pipe(7), pty(7), sem_overview(7), shm_overview(7), signal(7), socket(7), standards(7), svipc(7), symlink(7), time(7)

This page is part of release 4.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.

2014-02-20 Linux

Pages:

man_EXIT(2) _Exit manCLONE(2) __clone2 man_EXIT(2) _exit manLLSEEK(2) _llseek manSELECT(2) _newselect man_SYSCALL(2) _syscall manSYSCTL(2) _sysctl manACCEPT(2) accept manACCEPT(2) accept4 manACCESS(2) access manACCT(2) acct manADD_KEY(2) add_key manADJTIMEX(2) adjtimex manUNIMPLEMENTED(2) afs_syscall manALARM(2) alarm manALLOC_HUGEPAGES(2) alloc_hugepages manARCH_PRCTL(2) arch_prctl manPOSIX_FADVISE(2) arm_fadvise manPOSIX_FADVISE(2) arm_fadvise64_64 manSYNC_FILE_RANGE(2) arm_sync_file_range manBDFLUSH(2) bdflush manBIND(2) bind manBPF(2) bpf manUNIMPLEMENTED(2) break manBRK(2) brk manCACHEFLUSH(2) cacheflush manCAPGET(2) capget manCAPGET(2) capset manCHDIR(2) chdir manCHMOD(2) chmod manCHOWN(2) chown manCHOWN(2) chown32 manCHROOT(2) chroot manCLOCK_GETRES(2) clock_getres manCLOCK_GETRES(2) clock_gettime manCLOCK_NANOSLEEP(2) clock_nanosleep manCLOCK_GETRES(2) clock_settime manCLONE(2) clone manCLONE(2) clone2 manCLOSE(2) close manCONNECT(2) connect manCOPY(2) copy_file_range manOPEN(2) creat manCREATE_MODULE(2) create_module manDELETE_MODULE(2) delete_module manDUP(2) dup manDUP(2) dup2 manDUP(2) dup3 manEPOLL_CREATE(2) epoll_create manEPOLL_CREATE(2) epoll_create1 manEPOLL_CTL(2) epoll_ctl manEPOLL_WAIT(2) epoll_pwait manEPOLL_WAIT(2) epoll_wait manEVENTFD(2) eventfd manEVENTFD(2) eventfd2 manEXECVE(2) execve manEXECVEAT(2) execveat man_EXIT(2) exit manEXIT_GROUP(2) exit_group manACCESS(2) faccessat manPOSIX_FADVISE(2) fadvise64 manPOSIX_FADVISE(2) fadvise64_64 manFALLOCATE(2) fallocate manFANOTIFY_INIT(2) fanotify_init manFANOTIFY_MARK(2) fanotify_mark manUNIMPLEMENTED(2) fattach manCHDIR(2) fchdir manCHMOD(2) fchmod manCHMOD(2) fchmodat manCHOWN(2) fchown manCHOWN(2) fchown32 manCHOWN(2) fchownat manFCNTL(2) fcntl manFCNTL(2) fcntl64 manFSYNC(2) fdatasync manUNIMPLEMENTED(2) fdetach manGETXATTR(2) fgetxattr manINIT_MODULE(2) finit_module manLISTXATTR(2) flistxattr manFLOCK(2) flock manFORK(2) fork manALLOC_HUGEPAGES(2) free_hugepages manREMOVEXATTR(2) fremovexattr manSETXATTR(2) fsetxattr manSTAT(2) fstat manSTAT(2) fstat64 manSTAT(2) fstatat manSTAT(2) fstatat64 manSTATFS(2) fstatfs manSTATFS(2) fstatfs64 manSTATVFS(3) fstatvfs manFSYNC(2) fsync manTRUNCATE(2) ftruncate manTRUNCATE(2) ftruncate64 manFUTEX(2) futex manFUTIMESAT(2) futimesat manGET_KERNEL_SYMS(2) get_kernel_syms manGET_MEMPOLICY(2) get_mempolicy manGET_ROBUST_LIST(2) get_robust_list manSET_THREAD_AREA(2) get_thread_area manGETCONTEXT(3) getcontext manGETCPU(2) getcpu manGETCWD(3) getcwd manGETDENTS(2) getdents manGETDENTS(2) getdents64 manGETDOMAINNAME(2) getdomainname man() getdtablesize manGETGID(2) getegid manGETGID(2) getegid32 manGETUID(2) geteuid manGETUID(2) geteuid32 manGETGID(2) getgid manGETGID(2) getgid32 manGETGROUPS(2) getgroups manGETGROUPS(2) getgroups32 manGETHOSTID(3) gethostid manGETHOSTNAME(2) gethostname manGETITIMER(2) getitimer manUNIMPLEMENTED(2) getmsg manGETPAGESIZE(2) getpagesize manGETPEERNAME(2) getpeername manSETPGID(2) getpgid manSETPGID(2) getpgrp manGETPID(2) getpid manUNIMPLEMENTED(2) getpmsg manGETPID(2) getppid manGETPRIORITY(2) getpriority manGETRANDOM(2) getrandom manGETRESUID(2) getresgid manGETRESUID(2) getresgid32 manGETRESUID(2) getresuid manGETRESUID(2) getresuid32 manGETRLIMIT(2) getrlimit manGETRUSAGE(2) getrusage manGETSID(2) getsid manGETSOCKNAME(2) getsockname manGETSOCKOPT(2) getsockopt manGETTID(2) gettid manGETTIMEOFDAY(2) gettimeofday manGETUID(2) getuid manGETUID(2) getuid32 manGETUNWIND(2) getunwind manGETXATTR(2) getxattr manUNIMPLEMENTED(2) gtty manIDLE(2) idle manOUTB(2) inb manOUTB(2) inb_p manINIT_MODULE(2) init_module manOUTB(2) inl manOUTB(2) inl_p manINOTIFY_ADD_WATCH(2) inotify_add_watch manINOTIFY_INIT(2) inotify_init manINOTIFY_INIT(2) inotify_init1 manINOTIFY_RM_WATCH(2) inotify_rm_watch manOUTB(2) insb manOUTB(2) insl manOUTB(2) insw manINTRO(2) intro manOUTB(2) inw manOUTB(2) inw_p manIO_CANCEL(2) io_cancel manIO_DESTROY(2) io_destroy manIO_GETEVENTS(2) io_getevents manIO_SETUP(2) io_setup manIO_SUBMIT(2) io_submit manIOCTL(2) ioctl manIOCTl-FAT(2) ioctl_fat manIOCTL_LIST(2) ioctl_list manIOPERM(2) ioperm manIOPL(2) iopl manIOPRIO_SET(2) ioprio_get manIOPRIO_SET(2) ioprio_set manIPC(2) ipc manUNIMPLEMENTED(2) isastream manKCMP(2) kcmp manKEXEC_LOAD(2) kexec_file_load manKEXEC_LOAD(2) kexec_load manKEYCTL(2) keyctl manKILL(2) kill manKILLPG(2) killpg manCHOWN(2) lchown manCHOWN(2) lchown32 manGETXATTR(2) lgetxattr manLINK(2) link manLINK(2) linkat manLISTEN(2) listen manLISTXATTR(2) listxattr manLISTXATTR(2) llistxattr manLLSEEK(2) llseek manUNIMPLEMENTED(2) lock manLOOKUP_DCOOKIE(2) lookup_dcookie manREMOVEXATTR(2) lremovexattr manLSEEK(2) lseek manSETXATTR(2) lsetxattr manSTAT(2) lstat manSTAT(2) lstat64 manMADVISE(2) madvise manUNIMPLEMENTED(2) madvise1 manMBIND(2) mbind manMEMBARRIER(2) membarrier manMEMFD_CREATE(2) memfd_create manMIGRATE_PAGES(2) migrate_pages manMINCORE(2) mincore manMKDIR(2) mkdir manMKDIR(2) mkdirat manMKNOD(2) mknod manMKNOD(2) mknodat manMLOCK(2) mlock manMLOCK(2) mlock2 manMLOCK(2) mlockall manMMAP(2) mmap manMMAP2(2) mmap2 manMODIFY_LDT(2) modify_ldt manMOUNT(2) mount manMOVE_PAGES(2) move_pages manMPROTECT(2) mprotect manUNIMPLEMENTED(2) mpx manMQ_GETSETATTR(2) mq_getsetattr manMQ_NOTIFY(3) mq_notify manMQ_OPEN(3) mq_open manMQ_RECEIVE(3) mq_timedreceive manMQ_SEND(3) mq_timedsend manMQ_UNLINK(3) mq_unlink manMREMAP(2) mremap manMSGCTL(2) msgctl manMSGGET(2) msgget manMSGOP(2) msgop manMSGOP(2) msgrcv manMSGOP(2) msgsnd manMSYNC(2) msync manMLOCK(2) munlock manMLOCK(2) munlockall manMMAP(2) munmap manOPEN_BY_HANDLE_AT(2) name_to_handle_at manNANOSLEEP(2) nanosleep manSTAT(2) newfstatat manNFSSERVCTL(2) nfsservctl manNICE(2) nice manSTAT(2) oldfstat manSTAT(2) oldlstat manUNAME(2) oldolduname manSTAT(2) oldstat manUNAME(2) olduname manOPEN(2) open manOPEN_BY_HANDLE_AT(2) open_by_handle_at manOPEN(2) openat manOUTB(2) outb manOUTB(2) outb_p manOUTB(2) outl manOUTB(2) outl_p manOUTB(2) outsb manOUTB(2) outsl manOUTB(2) outsw manOUTB(2) outw manOUTB(2) outw_p manPAUSE(2) pause manPCICONFIG_READ(2) pciconfig_iobase manPCICONFIG_READ(2) pciconfig_read manPCICONFIG_READ(2) pciconfig_write manPERF_EVENT_OPEN(2) perf_event_open manPERFMONCTL(2) perfmonctl manPERSONALITY(2) personality manUNIMPLEMENTED(2) phys manPIPE(2) pipe manPIPE(2) pipe2 manPIVOT_ROOT(2) pivot_root manPOLL(2) poll manPOSIX_FADVISE(2) posix_fadvise manPOLL(2) ppoll manPRCTL(2) prctl manPREAD(2) pread manPREAD(2) pread64 manREADV(2) preadv manGETRLIMIT(2) prlimit manGETRLIMIT(2) prlimit64 manPROCESS_VM_READV(2) process_vm_readv manPROCESS_VM_READV(2) process_vm_writev manUNIMPLEMENTED(2) prof manSELECT(2) pselect manSELECT(2) pselect6 manPTRACE(2) ptrace manUNIMPLEMENTED(2) putmsg manUNIMPLEMENTED(2) putpmsg manPREAD(2) pwrite manPREAD(2) pwrite64 manREADV(2) pwritev manQUERY_MODULE(2) query_module manQUOTACTL(2) quotactl manREAD(2) read manREADAHEAD(2) readahead manREADDIR(2) readdir manREADLINK(2) readlink manREADLINK(2) readlinkat manREADV(2) readv manREBOOT(2) reboot manRECV(2) recv manRECV(2) recvfrom manRECVMMSG(2) recvmmsg manRECV(2) recvmsg manREMAP_FILE_PAGES(2) remap_file_pages manREMOVEXATTR(2) removexattr manRENAME(2) rename manRENAME(2) renameat manRENAME(2) renameat2 manREQUEST_KEY(2) request_key manRESTART_SYSCALL(2) restart_syscall manRMDIR(2) rmdir manSIGACTION(2) rt_sigaction manSIGPENDING(2) rt_sigpending manSIGPROCMASK(2) rt_sigprocmask manRT_SIGQUEUEINFO(2) rt_sigqueueinfo manSIGRETURN(2) rt_sigreturn manSIGSUSPEND(2) rt_sigsuspend manSIGWAITINFO(2) rt_sigtimedwait manRT_SIGQUEUEINFO(2) rt_tgsigqueueinfo manS390_PCI_MMIO_WRITE(2) s390_pci_mmio_read manS390_PCI_MMIO_WRITE(2) s390_pci_mmio_write manS390_RUNTIME_INSTR(2) s390_runtime_instr manBRK(2) sbrk manSCHED_GET_PRIORITY_MAX(2) sched_get_priority_max manSCHED_GET_PRIORITY_MAX(2) sched_get_priority_min manSCHED_SETAFFINITY(2) sched_getaffinity manSCHED_SETATTR(2) sched_getattr manSCHED_SETPARAM(2) sched_getparam manSCHED_SETSCHEDULER(2) sched_getscheduler manSCHED_RR_GET_INTERVAL(2) sched_rr_get_interval manSCHED_SETAFFINITY(2) sched_setaffinity manSCHED_SETATTR(2) sched_setattr manSCHED_SETPARAM(2) sched_setparam manSCHED_SETSCHEDULER(2) sched_setscheduler manSCHED_YIELD(2) sched_yield manSECCOMP(2) seccomp manUNIMPLEMENTED(2) security manSELECT(2) select manSELECT_TUT(2) select_tut manSEMCTL(2) semctl manSEMGET(2) semget manSEMOP(2) semop manSEMOP(2) semtimedop manSEND(2) send manSENDFILE(2) sendfile manSENDFILE(2) sendfile64 manSENDMMSG(2) sendmmsg manSEND(2) sendmsg manSEND(2) sendto manSET_MEMPOLICY(2) set_mempolicy manGET_ROBUST_LIST(2) set_robust_list manSET_THREAD_AREA(2) set_thread_area manSET_TID_ADDRESS(2) set_tid_address manGETCONTEXT(3) setcontext manGETDOMAINNAME(2) setdomainname manSETEUID(2) setegid manSETEUID(2) seteuid manSETFSGID(2) setfsgid manSETFSGID(2) setfsgid32 manSETFSUID(2) setfsuid manSETFSUID(2) setfsuid32 manSETGID(2) setgid manSETGID(2) setgid32 manGETGROUPS(2) setgroups manGETGROUPS(2) setgroups32 manGETHOSTID(3) sethostid manGETHOSTNAME(2) sethostname manGETITIMER(2) setitimer manSETNS(2) setns manSETPGID(2) setpgid manSETPGID(2) setpgrp manGETPRIORITY(2) setpriority manSETREUID(2) setregid manSETREUID(2) setregid32 manSETRESUID(2) setresgid manSETRESUID(2) setresgid32 manSETRESUID(2) setresuid manSETRESUID(2) setresuid32 manSETREUID(2) setreuid manSETREUID(2) setreuid32 manGETRLIMIT(2) setrlimit manSETSID(2) setsid manGETSOCKOPT(2) setsockopt manGETTIMEOFDAY(2) settimeofday manSETUID(2) setuid manSETUID(2) setuid32 manSETUP(2) setup manSETXATTR(2) setxattr manSGETMASK(2) sgetmask manSHMOP(2) shmat manSHMCTL(2) shmctl manSHMOP(2) shmdt manSHMGET(2) shmget manSHMOP(2) shmop manSHUTDOWN(2) shutdown manSIGACTION(2) sigaction manSIGALTSTACK(2) sigaltstack manSIGNAL(2) signal manSIGNALFD(2) signalfd manSIGNALFD(2) signalfd4 manSIGPENDING(2) sigpending manSIGPROCMASK(2) sigprocmask manSIGQUEUE(3) sigqueue manSIGRETURN(2) sigreturn manSIGSUSPEND(2) sigsuspend manSIGWAITINFO(2) sigtimedwait manSIGWAITINFO(2) sigwaitinfo manSOCKET(2) socket manSOCKETCALL(2) socketcall manSOCKETPAIR(2) socketpair manSPLICE(2) splice manSPU_CREATE(2) spu_create manSPU_RUN(2) spu_run manSGETMASK(2) ssetmask manSTAT(2) stat manSTAT(2) stat64 manSTATFS(2) statfs manSTATFS(2) statfs64 manSTATVFS(3) statvfs manSTIME(2) stime manUNIMPLEMENTED(2) stty manSUBPAGE_PROT(2) subpage_prot manSWAPON(2) swapoff manSWAPON(2) swapon manSYMLINK(2) symlink manSYMLINK(2) symlinkat manSYNC(2) sync manSYNC_FILE_RANGE(2) sync_file_range manSYNC_FILE_RANGE(2) sync_file_range2 manSYNC(2) syncfs manSYSCALL(2) syscall manSYSCALLS(2) syscalls manSYSCTL(2) sysctl manSYSFS(2) sysfs manSYSINFO(2) sysinfo manSYSLOG(2) syslog manTEE(2) tee manTKILL(2) tgkill manTIME(2) time manTIMER_CREATE(2) timer_create manTIMER_DELETE(2) timer_delete manTIMER_GETOVERRUN(2) timer_getoverrun manTIMER_SETTIME(2) timer_gettime manTIMER_SETTIME(2) timer_settime manTIMERFD_CREATE(2) timerfd_create manTIMERFD_CREATE(2) timerfd_gettime manTIMERFD_CREATE(2) timerfd_settime manTIMES(2) times manTKILL(2) tkill manTRUNCATE(2) truncate manTRUNCATE(2) truncate64 manUNIMPLEMENTED(2) tuxcall manGETRLIMIT(2) ugetrlimit manUMASK(2) umask manUMOUNT(2) umount manUMOUNT(2) umount2 manUNAME(2) uname manUNIMPLEMENTED(2) unimplemented manUNLINK(2) unlink manUNLINK(2) unlinkat manUNSHARE(2) unshare manUSELIB(2) uselib manUSTAT(2) ustat manUTIME(2) utime manUTIMENSAT(2) utimensat manUTIME(2) utimes manVFORK(2) vfork manVHANGUP(2) vhangup manVM86(2) vm86 manVM86(2) vm86old manVMSPLICE(2) vmsplice manUNIMPLEMENTED(2) vserver manWAIT(2) wait manWAIT4(2) wait3 manWAIT4(2) wait4 manWAIT(2) waitid manWAIT(2) waitpid manWRITE(2) write manREADV(2) writev

Different Versions of this Section: