diff --git "a/test.txt" "b/test.txt" new file mode 100644--- /dev/null +++ "b/test.txt" @@ -0,0 +1,29984 @@ +.so man3/malloc.3 + +.\" copyright (c) 2008 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th makedev 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +makedev, major, minor \- manage a device number +.sh synopsis +.nf +.b #include +.pp +.bi "dev_t makedev(unsigned int " maj ", unsigned int " min ); +.pp +.bi "unsigned int major(dev_t " dev ); +.bi "unsigned int minor(dev_t " dev ); +.fi +.sh description +a device id consists of two parts: +a major id, identifying the class of the device, +and a minor id, identifying a specific instance of a device in that class. +a device id is represented using the type +.ir dev_t . +.pp +given major and minor device ids, +.br makedev () +combines these to produce a device id, returned as the function result. +this device id can be given to +.br mknod (2), +for example. +.pp +the +.br major () +and +.br minor () +functions perform the converse task: given a device id, +they return, respectively, the major and minor components. +these macros can be useful to, for example, +decompose the device ids in the structure returned by +.br stat (2). +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br makedev (), +.br major (), +.br minor () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +the +.br makedev (), +.br major (), +and +.br minor () +functions are not specified in posix.1, +but are present on many other systems. +.\" the bsds, hp-ux, solaris, aix, irix. +.\" the header location is inconsistent: +.\" could be sys/mkdev.h, sys/sysmacros.h, or sys/types.h. +.sh notes +these interfaces are defined as macros. +since glibc 2.3.3, +they have been aliases for three gnu-specific functions: +.br gnu_dev_makedev (), +.br gnu_dev_major (), +and +.br gnu_dev_minor (). +the latter names are exported, but the traditional names are more portable. +.pp +the bsds expose the definitions for these macros via +.ir . +depending on the version, +glibc also exposes definitions for these macros from that +header file if suitable feature test macros are defined. +however, this behavior was deprecated in glibc 2.25, +.\" glibc commit dbab6577c6684c62bd2521c1c29dc25c3cac966f +and since glibc 2.28, +.\" glibc commit e16deca62e16f645213dffd4ecd1153c37765f17 +.ir +no longer provides these definitions. +.sh see also +.br mknod (2), +.br stat (2) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2003 free software foundation, inc. +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" this file is distributed according to the gnu general public license. +.\" %%%license_end +.\" +.th io_cancel 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +io_cancel \- cancel an outstanding asynchronous i/o operation +.sh synopsis +.nf +.br "#include " " /* definition of needed types */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "int syscall(sys_io_cancel, aio_context_t " ctx_id ", struct iocb *" iocb , +.bi " struct io_event *" result ); +.fi +.sh description +.ir note : +this page describes the raw linux system call interface. +the wrapper function provided by +.i libaio +uses a different type for the +.i ctx_id +argument. +see notes. +.pp +the +.br io_cancel () +system call +attempts to cancel an asynchronous i/o operation previously submitted with +.br io_submit (2). +the +.i iocb +argument describes the operation to be canceled and the +.i ctx_id +argument is the aio context to which the operation was submitted. +if the operation is successfully canceled, the event will be copied into +the memory pointed to by +.i result +without being placed into the +completion queue. +.sh return value +on success, +.br io_cancel () +returns 0. +for the failure return, see notes. +.sh errors +.tp +.b eagain +the \fiiocb\fp specified was not canceled. +.tp +.b efault +one of the data structures points to invalid data. +.tp +.b einval +the aio context specified by \fictx_id\fp is invalid. +.tp +.b enosys +.br io_cancel () +is not implemented on this architecture. +.sh versions +the asynchronous i/o system calls first appeared in linux 2.5. +.sh conforming to +.br io_cancel () +is linux-specific and should not be used +in programs that are intended to be portable. +.sh notes +you probably want to use the +.br io_cancel () +wrapper function provided by +.\" http://git.fedorahosted.org/git/?p=libaio.git +.ir libaio . +.pp +note that the +.i libaio +wrapper function uses a different type +.ri ( io_context_t ) +.\" but glibc is confused, since uses 'io_context_t' to declare +.\" the system call. +for the +.i ctx_id +argument. +note also that the +.i libaio +wrapper does not follow the usual c library conventions for indicating errors: +on error it returns a negated error number +(the negative of one of the values listed in errors). +if the system call is invoked via +.br syscall (2), +then the return value follows the usual conventions for +indicating an error: \-1, with +.i errno +set to a (positive) value that indicates the error. +.sh see also +.br io_destroy (2), +.br io_getevents (2), +.br io_setup (2), +.br io_submit (2), +.br aio (7) +.\" .sh author +.\" kent yoder. +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/drand48_r.3 + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th iswpunct 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +iswpunct \- test for punctuation or symbolic wide character +.sh synopsis +.nf +.b #include +.pp +.bi "int iswpunct(wint_t " wc ); +.fi +.sh description +the +.br iswpunct () +function is the wide-character equivalent of the +.br ispunct (3) +function. +it tests whether +.i wc +is a wide character +belonging to the wide-character class "punct". +.pp +the wide-character class "punct" is a subclass of the wide-character class +"graph", and therefore also a subclass of the wide-character class "print". +.pp +the wide-character class "punct" is disjoint from the wide-character class +"alnum" and therefore also disjoint from its subclasses "alpha", "upper", +"lower", "digit", "xdigit". +.pp +being a subclass of the wide-character class "print", +the wide-character class +"punct" is disjoint from the wide-character class "cntrl". +.pp +being a subclass of the wide-character class "graph", +the wide-character class +"punct" is disjoint from the wide-character class "space" and its subclass +"blank". +.sh return value +the +.br iswpunct () +function returns nonzero +if +.i wc +is a wide-character +belonging to the wide-character class "punct". +otherwise, it returns zero. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br iswpunct () +t} thread safety mt-safe locale +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh notes +the behavior of +.br iswpunct () +depends on the +.b lc_ctype +category of the +current locale. +.pp +this function's name is a misnomer when dealing with unicode characters, +because the wide-character class "punct" contains both punctuation characters +and symbol (math, currency, etc.) characters. +.sh see also +.br ispunct (3), +.br iswctype (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2003 andi kleen +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th arch_prctl 2 2021-08-27 "linux" "linux programmer's manual" +.sh name +arch_prctl \- set architecture-specific thread state +.sh synopsis +.nf +.br "#include " " /* definition of " arch_* " constants */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "int syscall(sys_arch_prctl, int " code ", unsigned long " addr ); +.bi "int syscall(sys_arch_prctl, int " code ", unsigned long *" addr ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br arch_prctl (), +necessitating the use of +.br syscall (2). +.sh description +.br arch_prctl () +sets architecture-specific process or thread state. +.i code +selects a subfunction +and passes argument +.i addr +to it; +.i addr +is interpreted as either an +.i "unsigned long" +for the "set" operations, or as an +.ir "unsigned long\ *" , +for the "get" operations. +.pp +subfunctions for both x86 and x86-64 are: +.tp +.br arch_set_cpuid " (since linux 4.12)" +.\" commit e9ea1e7f53b852147cbd568b0568c7ad97ec21a3 +enable +.ri ( "addr != 0" ) +or disable +.ri ( "addr == 0" ) +the +.i cpuid +instruction for the calling thread. +the instruction is enabled by default. +if disabled, any execution of a +.i cpuid +instruction will instead generate a +.b sigsegv +signal. +this feature can be used to emulate +.i cpuid +results that differ from what the underlying +hardware would have produced (e.g., in a paravirtualization setting). +.ip +the +.br arch_set_cpuid +setting is preserved across +.br fork (2) +and +.br clone (2) +but reset to the default (i.e., +.i cpuid +enabled) on +.br execve (2). +.tp +.br arch_get_cpuid " (since linux 4.12)" +return the setting of the flag manipulated by +.b arch_set_cpuid +as the result of the system call (1 for enabled, 0 for disabled). +.i addr +is ignored. +.tp +subfunctions for x86-64 only are: +.tp +.b arch_set_fs +set the 64-bit base for the +.i fs +register to +.ir addr . +.tp +.b arch_get_fs +return the 64-bit base value for the +.i fs +register of the calling thread in the +.i unsigned long +pointed to by +.ir addr . +.tp +.b arch_set_gs +set the 64-bit base for the +.i gs +register to +.ir addr . +.tp +.b arch_get_gs +return the 64-bit base value for the +.i gs +register of the calling thread in the +.i unsigned long +pointed to by +.ir addr . +.sh return value +on success, +.br arch_prctl () +returns 0; on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b efault +.i addr +points to an unmapped address or is outside the process address space. +.tp +.b einval +.i code +is not a valid subcommand. +.tp +.b enodev +.b arch_set_cpuid +was requested, but the underlying hardware does not support cpuid faulting. +.tp +.b eperm +.i addr +is outside the process address space. +.\" .sh author +.\" man page written by andi kleen. +.sh conforming to +.br arch_prctl () +is a linux/x86-64 extension and should not be used in programs intended +to be portable. +.sh notes +.br arch_prctl () +is supported only on linux/x86-64 for 64-bit programs currently. +.pp +the 64-bit base changes when a new 32-bit segment selector is loaded. +.pp +.b arch_set_gs +is disabled in some kernels. +.pp +context switches for 64-bit segment bases are rather expensive. +as an optimization, if a 32-bit tls base address is used, +.br arch_prctl () +may use a real tls entry as if +.br set_thread_area (2) +had been called, instead of manipulating the segment base register directly. +memory in the first 2\ gb of address space can be allocated by using +.br mmap (2) +with the +.b map_32bit +flag. +.pp +because of the aforementioned optimization, using +.br arch_prctl () +and +.br set_thread_area (2) +in the same thread is dangerous, as they may overwrite each other's +tls entries. +.pp +.i fs +may be already used by the threading library. +programs that use +.b arch_set_fs +directly are very likely to crash. +.sh see also +.br mmap (2), +.br modify_ldt (2), +.br prctl (2), +.br set_thread_area (2) +.pp +amd x86-64 programmer's manual +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/utimensat.2 + +.so man7/system_data_types.7 + +.\" copyright (c) 2000 andries brouwer +.\" and copyright (c) 2007 michael kerrisk +.\" and copyright (c) 2008, linux foundation, written by michael kerrisk +.\" +.\" based on work by rik faith +.\" and mike battersby . +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified 2004-11-19, mtk: +.\" added pointer to sigaction.2 for details of ignoring sigchld +.\" 2007-06-03, mtk: strengthened portability warning, and rewrote +.\" various sections. +.\" 2008-07-11, mtk: rewrote and expanded portability discussion. +.\" +.th signal 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +signal \- ansi c signal handling +.sh synopsis +.nf +.b #include +.pp +.b typedef void (*sighandler_t)(int); +.pp +.bi "sighandler_t signal(int " signum ", sighandler_t " handler ); +.fi +.sh description +.br warning : +the behavior of +.br signal () +varies across unix versions, +and has also varied historically across different versions of linux. +\fbavoid its use\fp: use +.br sigaction (2) +instead. +see \fiportability\fp below. +.pp +.br signal () +sets the disposition of the signal +.i signum +to +.ir handler , +which is either +.br sig_ign , +.br sig_dfl , +or the address of a programmer-defined function (a "signal handler"). +.pp +if the signal +.i signum +is delivered to the process, then one of the following happens: +.tp 3 +* +if the disposition is set to +.br sig_ign , +then the signal is ignored. +.tp +* +if the disposition is set to +.br sig_dfl , +then the default action associated with the signal (see +.br signal (7)) +occurs. +.tp +* +if the disposition is set to a function, +then first either the disposition is reset to +.br sig_dfl , +or the signal is blocked (see \fiportability\fp below), and then +.i handler +is called with argument +.ir signum . +if invocation of the handler caused the signal to be blocked, +then the signal is unblocked upon return from the handler. +.pp +the signals +.b sigkill +and +.b sigstop +cannot be caught or ignored. +.sh return value +.br signal () +returns the previous value of the signal handler +on failure, it returns +.br sig_err , +and +.i errno +is set to indicate the error. +.sh errors +.tp +.b einval +.i signum +is invalid. +.sh conforming to +posix.1-2001, posix.1-2008, c89, c99. +.sh notes +the effects of +.br signal () +in a multithreaded process are unspecified. +.pp +according to posix, the behavior of a process is undefined after it +ignores a +.br sigfpe , +.br sigill , +or +.b sigsegv +signal that was not generated by +.br kill (2) +or +.br raise (3). +integer division by zero has undefined result. +on some architectures it will generate a +.b sigfpe +signal. +(also dividing the most negative integer by \-1 may generate +.br sigfpe .) +ignoring this signal might lead to an endless loop. +.pp +see +.br sigaction (2) +for details on what happens when the disposition +.b sigchld +is set to +.br sig_ign . +.pp +see +.br signal\-safety (7) +for a list of the async-signal-safe functions that can be +safely called from inside a signal handler. +.pp +the use of +.i sighandler_t +is a gnu extension, exposed if +.b _gnu_source +is defined; +.\" libc4 and libc5 define +.\" .ir signalhandler ; +glibc also defines (the bsd-derived) +.i sig_t +if +.b _bsd_source +(glibc 2.19 and earlier) +or +.br _default_source +(glibc 2.19 and later) +is defined. +without use of such a type, the declaration of +.br signal () +is the somewhat harder to read: +.pp +.in +4n +.ex +.bi "void ( *" signal "(int " signum ", void (*" handler ")(int)) ) (int);" +.ee +.in +.ss portability +the only portable use of +.br signal () +is to set a signal's disposition to +.br sig_dfl +or +.br sig_ign . +the semantics when using +.br signal () +to establish a signal handler vary across systems +(and posix.1 explicitly permits this variation); +.b do not use it for this purpose. +.pp +posix.1 solved the portability mess by specifying +.br sigaction (2), +which provides explicit control of the semantics when a +signal handler is invoked; use that interface instead of +.br signal (). +.pp +in the original unix systems, when a handler that was established using +.br signal () +was invoked by the delivery of a signal, +the disposition of the signal would be reset to +.br sig_dfl , +and the system did not block delivery of further instances of the signal. +this is equivalent to calling +.br sigaction (2) +with the following flags: +.pp +.in +4n +.ex +sa.sa_flags = sa_resethand | sa_nodefer; +.ee +.in +.pp +system\ v also provides these semantics for +.br signal (). +this was bad because the signal might be delivered again +before the handler had a chance to reestablish itself. +furthermore, rapid deliveries of the same signal could +result in recursive invocations of the handler. +.pp +bsd improved on this situation, but unfortunately also +changed the semantics of the existing +.br signal () +interface while doing so. +on bsd, when a signal handler is invoked, +the signal disposition is not reset, +and further instances of the signal are blocked from +being delivered while the handler is executing. +furthermore, certain blocking system calls are automatically +restarted if interrupted by a signal handler (see +.br signal (7)). +the bsd semantics are equivalent to calling +.br sigaction (2) +with the following flags: +.pp +.in +4n +.ex +sa.sa_flags = sa_restart; +.ee +.in +.pp +the situation on linux is as follows: +.ip * 2 +the kernel's +.br signal () +system call provides system\ v semantics. +.ip * +by default, in glibc 2 and later, the +.br signal () +wrapper function does not invoke the kernel system call. +instead, it calls +.br sigaction (2) +using flags that supply bsd semantics. +this default behavior is provided as long as a suitable +feature test macro is defined: +.b _bsd_source +on glibc 2.19 and earlier or +.br _default_source +in glibc 2.19 and later. +(by default, these macros are defined; see +.br feature_test_macros (7) +for details.) +if such a feature test macro is not defined, then +.br signal () +provides system\ v semantics. +.\" +.\" system v semantics are also provided if one uses the separate +.\" .br sysv_signal (3) +.\" function. +.\" .ip * +.\" the +.\" .br signal () +.\" function in linux libc4 and libc5 provide system\ v semantics. +.\" if one on a libc5 system includes +.\" .i +.\" instead of +.\" .ir , +.\" then +.\" .br signal () +.\" provides bsd semantics. +.sh see also +.br kill (1), +.br alarm (2), +.br kill (2), +.br pause (2), +.br sigaction (2), +.br signalfd (2), +.br sigpending (2), +.br sigprocmask (2), +.br sigsuspend (2), +.br bsd_signal (3), +.br killpg (3), +.br raise (3), +.br siginterrupt (3), +.br sigqueue (3), +.br sigsetops (3), +.br sigvec (3), +.br sysv_signal (3), +.br signal (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2013, 2014 by michael kerrisk +.\" and copyright (c) 2012, 2014 by eric w. biederman +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" +.th user_namespaces 7 2021-08-27 "linux" "linux programmer's manual" +.sh name +user_namespaces \- overview of linux user namespaces +.sh description +for an overview of namespaces, see +.br namespaces (7). +.pp +user namespaces isolate security-related identifiers and attributes, +in particular, +user ids and group ids (see +.br credentials (7)), +the root directory, +keys (see +.br keyrings (7)), +.\" fixme: this page says very little about the interaction +.\" of user namespaces and keys. add something on this topic. +and capabilities (see +.br capabilities (7)). +a process's user and group ids can be different +inside and outside a user namespace. +in particular, +a process can have a normal unprivileged user id outside a user namespace +while at the same time having a user id of 0 inside the namespace; +in other words, +the process has full privileges for operations inside the user namespace, +but is unprivileged for operations outside the namespace. +.\" +.\" ============================================================ +.\" +.ss nested namespaces, namespace membership +user namespaces can be nested; +that is, each user namespace\(emexcept the initial ("root") +namespace\(emhas a parent user namespace, +and can have zero or more child user namespaces. +the parent user namespace is the user namespace +of the process that creates the user namespace via a call to +.br unshare (2) +or +.br clone (2) +with the +.br clone_newuser +flag. +.pp +the kernel imposes (since version 3.11) a limit of 32 nested levels of +.\" commit 8742f229b635bf1c1c84a3dfe5e47c814c20b5c8 +user namespaces. +.\" fixme explain the rationale for this limit. (what is the rationale?) +calls to +.br unshare (2) +or +.br clone (2) +that would cause this limit to be exceeded fail with the error +.br eusers . +.pp +each process is a member of exactly one user namespace. +a process created via +.br fork (2) +or +.br clone (2) +without the +.br clone_newuser +flag is a member of the same user namespace as its parent. +a single-threaded process can join another user namespace with +.br setns (2) +if it has the +.br cap_sys_admin +in that namespace; +upon doing so, it gains a full set of capabilities in that namespace. +.pp +a call to +.br clone (2) +or +.br unshare (2) +with the +.br clone_newuser +flag makes the new child process (for +.br clone (2)) +or the caller (for +.br unshare (2)) +a member of the new user namespace created by the call. +.pp +the +.br ns_get_parent +.br ioctl (2) +operation can be used to discover the parental relationship +between user namespaces; see +.br ioctl_ns (2). +.\" +.\" ============================================================ +.\" +.ss capabilities +the child process created by +.br clone (2) +with the +.br clone_newuser +flag starts out with a complete set +of capabilities in the new user namespace. +likewise, a process that creates a new user namespace using +.br unshare (2) +or joins an existing user namespace using +.br setns (2) +gains a full set of capabilities in that namespace. +on the other hand, +that process has no capabilities in the parent (in the case of +.br clone (2)) +or previous (in the case of +.br unshare (2) +and +.br setns (2)) +user namespace, +even if the new namespace is created or joined by the root user +(i.e., a process with user id 0 in the root namespace). +.pp +note that a call to +.br execve (2) +will cause a process's capabilities to be recalculated in the usual way (see +.br capabilities (7)). +consequently, +unless the process has a user id of 0 within the namespace, +or the executable file has a nonempty inheritable capabilities mask, +the process will lose all capabilities. +see the discussion of user and group id mappings, below. +.pp +a call to +.br clone (2) +or +.br unshare (2) +using the +.br clone_newuser +flag +or a call to +.br setns (2) +that moves the caller into another user namespace +sets the "securebits" flags +(see +.br capabilities (7)) +to their default values (all flags disabled) in the child (for +.br clone (2)) +or caller (for +.br unshare (2) +or +.br setns (2)). +note that because the caller no longer has capabilities +in its original user namespace after a call to +.br setns (2), +it is not possible for a process to reset its "securebits" flags while +retaining its user namespace membership by using a pair of +.br setns (2) +calls to move to another user namespace and then return to +its original user namespace. +.pp +the rules for determining whether or not a process has a capability +in a particular user namespace are as follows: +.ip 1. 3 +a process has a capability inside a user namespace +if it is a member of that namespace and +it has the capability in its effective capability set. +a process can gain capabilities in its effective capability +set in various ways. +for example, it may execute a set-user-id program or an +executable with associated file capabilities. +in addition, +a process may gain capabilities via the effect of +.br clone (2), +.br unshare (2), +or +.br setns (2), +as already described. +.\" in the 3.8 sources, see security/commoncap.c::cap_capable(): +.ip 2. +if a process has a capability in a user namespace, +then it has that capability in all child (and further removed descendant) +namespaces as well. +.ip 3. +.\" * the owner of the user namespace in the parent of the +.\" * user namespace has all caps. +when a user namespace is created, the kernel records the effective +user id of the creating process as being the "owner" of the namespace. +.\" (and likewise associates the effective group id of the creating process +.\" with the namespace). +a process that resides +in the parent of the user namespace +.\" see kernel commit 520d9eabce18edfef76a60b7b839d54facafe1f9 for a fix +.\" on this point +and whose effective user id matches the owner of the namespace +has all capabilities in the namespace. +.\" this includes the case where the process executes a set-user-id +.\" program that confers the effective uid of the creator of the namespace. +by virtue of the previous rule, +this means that the process has all capabilities in all +further removed descendant user namespaces as well. +the +.b ns_get_owner_uid +.br ioctl (2) +operation can be used to discover the user id of the owner of the namespace; +see +.br ioctl_ns (2). +.\" +.\" ============================================================ +.\" +.ss effect of capabilities within a user namespace +having a capability inside a user namespace +permits a process to perform operations (that require privilege) +only on resources governed by that namespace. +in other words, having a capability in a user namespace permits a process +to perform privileged operations on resources that are governed by (nonuser) +namespaces owned by (associated with) the user namespace +(see the next subsection). +.pp +on the other hand, there are many privileged operations that affect +resources that are not associated with any namespace type, +for example, changing the system (i.e., calendar) time (governed by +.br cap_sys_time ), +loading a kernel module (governed by +.br cap_sys_module ), +and creating a device (governed by +.br cap_mknod ). +only a process with privileges in the +.i initial +user namespace can perform such operations. +.pp +holding +.b cap_sys_admin +within the user namespace that owns a process's mount namespace +allows that process to create bind mounts +and mount the following types of filesystems: +.\" fs_flags = fs_userns_mount in kernel sources +.pp +.rs 4 +.pd 0 +.ip * 2 +.ir /proc +(since linux 3.8) +.ip * +.ir /sys +(since linux 3.8) +.ip * +.ir devpts +(since linux 3.9) +.ip * +.br tmpfs (5) +(since linux 3.9) +.ip * +.ir ramfs +(since linux 3.9) +.ip * +.ir mqueue +(since linux 3.9) +.ip * +.ir bpf +.\" commit b2197755b2633e164a439682fb05a9b5ea48f706 +(since linux 4.4) +.ip * +.ir overlayfs +.\" commit 92dbc9dedccb9759c7f9f2f0ae6242396376988f +.\" commit 4cb2c00c43b3fe88b32f29df4f76da1b92c33224 +(since linux 5.11) +.pd +.re +.pp +holding +.b cap_sys_admin +within the user namespace that owns a process's cgroup namespace +allows (since linux 4.6) +that process to the mount the cgroup version 2 filesystem and +cgroup version 1 named hierarchies +(i.e., cgroup filesystems mounted with the +.ir """none,name=""" +option). +.pp +holding +.b cap_sys_admin +within the user namespace that owns a process's pid namespace +allows (since linux 3.8) +that process to mount +.i /proc +filesystems. +.pp +note, however, that mounting block-based filesystems can be done +only by a process that holds +.br cap_sys_admin +in the initial user namespace. +.\" +.\" ============================================================ +.\" +.ss interaction of user namespaces and other types of namespaces +starting in linux 3.8, unprivileged processes can create user namespaces, +and the other types of namespaces can be created with just the +.b cap_sys_admin +capability in the caller's user namespace. +.pp +when a nonuser namespace is created, +it is owned by the user namespace in which the creating process +was a member at the time of the creation of the namespace. +privileged operations on resources governed by the nonuser namespace +require that the process has the necessary capabilities +in the user namespace that owns the nonuser namespace. +.pp +if +.br clone_newuser +is specified along with other +.b clone_new* +flags in a single +.br clone (2) +or +.br unshare (2) +call, the user namespace is guaranteed to be created first, +giving the child +.rb ( clone (2)) +or caller +.rb ( unshare (2)) +privileges over the remaining namespaces created by the call. +thus, it is possible for an unprivileged caller to specify this combination +of flags. +.pp +when a new namespace (other than a user namespace) is created via +.br clone (2) +or +.br unshare (2), +the kernel records the user namespace of the creating process as the owner of +the new namespace. +(this association can't be changed.) +when a process in the new namespace subsequently performs +privileged operations that operate on global +resources isolated by the namespace, +the permission checks are performed according to the process's capabilities +in the user namespace that the kernel associated with the new namespace. +for example, suppose that a process attempts to change the hostname +.rb ( sethostname (2)), +a resource governed by the uts namespace. +in this case, +the kernel will determine which user namespace owns +the process's uts namespace, and check whether the process has the +required capability +.rb ( cap_sys_admin ) +in that user namespace. +.pp +the +.br ns_get_userns +.br ioctl (2) +operation can be used to discover the user namespace +that owns a nonuser namespace; see +.br ioctl_ns (2). +.\" +.\" ============================================================ +.\" +.ss user and group id mappings: uid_map and gid_map +when a user namespace is created, +it starts out without a mapping of user ids (group ids) +to the parent user namespace. +the +.ir /proc/[pid]/uid_map +and +.ir /proc/[pid]/gid_map +files (available since linux 3.5) +.\" commit 22d917d80e842829d0ca0a561967d728eb1d6303 +expose the mappings for user and group ids +inside the user namespace for the process +.ir pid . +these files can be read to view the mappings in a user namespace and +written to (once) to define the mappings. +.pp +the description in the following paragraphs explains the details for +.ir uid_map ; +.ir gid_map +is exactly the same, +but each instance of "user id" is replaced by "group id". +.pp +the +.i uid_map +file exposes the mapping of user ids from the user namespace +of the process +.ir pid +to the user namespace of the process that opened +.ir uid_map +(but see a qualification to this point below). +in other words, processes that are in different user namespaces +will potentially see different values when reading from a particular +.i uid_map +file, depending on the user id mappings for the user namespaces +of the reading processes. +.pp +each line in the +.i uid_map +file specifies a 1-to-1 mapping of a range of contiguous +user ids between two user namespaces. +(when a user namespace is first created, this file is empty.) +the specification in each line takes the form of +three numbers delimited by white space. +the first two numbers specify the starting user id in +each of the two user namespaces. +the third number specifies the length of the mapped range. +in detail, the fields are interpreted as follows: +.ip (1) 4 +the start of the range of user ids in +the user namespace of the process +.ir pid . +.ip (2) +the start of the range of user +ids to which the user ids specified by field one map. +how field two is interpreted depends on whether the process that opened +.i uid_map +and the process +.ir pid +are in the same user namespace, as follows: +.rs +.ip a) 3 +if the two processes are in different user namespaces: +field two is the start of a range of +user ids in the user namespace of the process that opened +.ir uid_map . +.ip b) +if the two processes are in the same user namespace: +field two is the start of the range of +user ids in the parent user namespace of the process +.ir pid . +this case enables the opener of +.i uid_map +(the common case here is opening +.ir /proc/self/uid_map ) +to see the mapping of user ids into the user namespace of the process +that created this user namespace. +.re +.ip (3) +the length of the range of user ids that is mapped between the two +user namespaces. +.pp +system calls that return user ids (group ids)\(emfor example, +.br getuid (2), +.br getgid (2), +and the credential fields in the structure returned by +.br stat (2)\(emreturn +the user id (group id) mapped into the caller's user namespace. +.pp +when a process accesses a file, its user and group ids +are mapped into the initial user namespace for the purpose of permission +checking and assigning ids when creating a file. +when a process retrieves file user and group ids via +.br stat (2), +the ids are mapped in the opposite direction, +to produce values relative to the process user and group id mappings. +.pp +the initial user namespace has no parent namespace, +but, for consistency, the kernel provides dummy user and group +id mapping files for this namespace. +looking at the +.i uid_map +file +.ri ( gid_map +is the same) from a shell in the initial namespace shows: +.pp +.in +4n +.ex +$ \fbcat /proc/$$/uid_map\fp + 0 0 4294967295 +.ee +.in +.pp +this mapping tells us +that the range starting at user id 0 in this namespace +maps to a range starting at 0 in the (nonexistent) parent namespace, +and the length of the range is the largest 32-bit unsigned integer. +this leaves 4294967295 (the 32-bit signed \-1 value) unmapped. +this is deliberate: +.ir "(uid_t)\ \-1" +is used in several interfaces (e.g., +.br setreuid (2)) +as a way to specify "no user id". +leaving +.ir "(uid_t)\ \-1" +unmapped and unusable guarantees that there will be no +confusion when using these interfaces. +.\" +.\" ============================================================ +.\" +.ss defining user and group id mappings: writing to uid_map and gid_map +after the creation of a new user namespace, the +.i uid_map +file of +.i one +of the processes in the namespace may be written to +.i once +to define the mapping of user ids in the new user namespace. +an attempt to write more than once to a +.i uid_map +file in a user namespace fails with the error +.br eperm . +similar rules apply for +.i gid_map +files. +.pp +the lines written to +.ir uid_map +.ri ( gid_map ) +must conform to the following validity rules: +.ip * 3 +the three fields must be valid numbers, +and the last field must be greater than 0. +.ip * +lines are terminated by newline characters. +.ip * +there is a limit on the number of lines in the file. +in linux 4.14 and earlier, this limit was (arbitrarily) +.\" 5*12-byte records could fit in a 64b cache line +set at 5 lines. +since linux 4.15, +.\" commit 6397fac4915ab3002dc15aae751455da1a852f25 +the limit is 340 lines. +in addition, the number of bytes written to +the file must be less than the system page size, +and the write must be performed at the start of the file (i.e., +.br lseek (2) +and +.br pwrite (2) +can't be used to write to nonzero offsets in the file). +.ip * +the range of user ids (group ids) +specified in each line cannot overlap with the ranges +in any other lines. +in the initial implementation (linux 3.8), this requirement was +satisfied by a simplistic implementation that imposed the further +requirement that +the values in both field 1 and field 2 of successive lines must be +in ascending numerical order, +which prevented some otherwise valid maps from being created. +linux 3.9 and later +.\" commit 0bd14b4fd72afd5df41e9fd59f356740f22fceba +fix this limitation, allowing any valid set of nonoverlapping maps. +.ip * +at least one line must be written to the file. +.pp +writes that violate the above rules fail with the error +.br einval . +.pp +in order for a process to write to the +.i /proc/[pid]/uid_map +.ri ( /proc/[pid]/gid_map ) +file, all of the following permission requirements must be met: +.ip 1. 3 +the writing process must have the +.br cap_setuid +.rb ( cap_setgid ) +capability in the user namespace of the process +.ir pid . +.ip 2. +the writing process must either be in the user namespace of the process +.i pid +or be in the parent user namespace of the process +.ir pid . +.ip 3. +the mapped user ids (group ids) must in turn have a mapping +in the parent user namespace. +.ip 4. +if updating +.ir /proc/[pid]/uid_map +to create a mapping that maps uid 0 in the parent namespace, +then one of the following must be true: +.rs +.ip * 3 +if writing process is in the parent user namespace, +then it must have the +.br cap_setfcap +capability in that user namespace; or +.ip * +if the writing process is in the child user namespace, +then the process that created the user namespace must have had the +.br cap_setfcap +capability when the namespace was created. +.re +.ip +this rule has been in place since +.\" commit db2e718a47984b9d71ed890eb2ea36ecf150de18 +linux 5.12. +it eliminates an earlier security bug whereby +a uid 0 process that lacks the +.b cap_setfcap +capability, +which is needed to create a binary with namespaced file capabilities +(as described in +.br capabilities (7)), +could nevertheless create such a binary, +by the following steps: +.rs +.ip * 3 +create a new user namespace with the identity mapping +(i.e., uid 0 in the new user namespace maps to uid 0 in the parent namespace), +so that uid 0 in both namespaces is equivalent to the same root user id. +.ip * +since the child process has the +.b cap_setfcap +capability, it could create a binary with namespaced file capabilities +that would then be effective in the parent user namespace +(because the root user ids are the same in the two namespaces). +.re +.ip 5. +one of the following two cases applies: +.rs +.ip * 3 +.ir either +the writing process has the +.br cap_setuid +.rb ( cap_setgid ) +capability in the +.i parent +user namespace. +.rs +.ip + 3 +no further restrictions apply: +the process can make mappings to arbitrary user ids (group ids) +in the parent user namespace. +.re +.ip * 3 +.ir or +otherwise all of the following restrictions apply: +.rs +.ip + 3 +the data written to +.i uid_map +.ri ( gid_map ) +must consist of a single line that maps +the writing process's effective user id +(group id) in the parent user namespace to a user id (group id) +in the user namespace. +.ip + +the writing process must have the same effective user id as the process +that created the user namespace. +.ip + +in the case of +.ir gid_map , +use of the +.br setgroups (2) +system call must first be denied by writing +.ri \(dq deny \(dq +to the +.i /proc/[pid]/setgroups +file (see below) before writing to +.ir gid_map . +.re +.re +.pp +writes that violate the above rules fail with the error +.br eperm . +.\" +.\" ============================================================ +.\" +.ss project id mappings: projid_map +similarly to user and group id mappings, +it is possible to create project id mappings for a user namespace. +(project ids are used for disk quotas; see +.br setquota (8) +and +.br quotactl (2).) +.pp +project id mappings are defined by writing to the +.i /proc/[pid]/projid_map +file (present since +.\" commit f76d207a66c3a53defea67e7d36c3eb1b7d6d61d +linux 3.7). +.pp +the validity rules for writing to the +.i /proc/[pid]/projid_map +file are as for writing to the +.i uid_map +file; violation of these rules causes +.br write (2) +to fail with the error +.br einval . +.pp +the permission rules for writing to the +.i /proc/[pid]/projid_map +file are as follows: +.ip 1. 3 +the writing process must either be in the user namespace of the process +.i pid +or be in the parent user namespace of the process +.ir pid . +.ip 2. +the mapped project ids must in turn have a mapping +in the parent user namespace. +.pp +violation of these rules causes +.br write (2) +to fail with the error +.br eperm . +.\" +.\" ============================================================ +.\" +.ss interaction with system calls that change process uids or gids +in a user namespace where the +.i uid_map +file has not been written, the system calls that change user ids will fail. +similarly, if the +.i gid_map +file has not been written, the system calls that change group ids will fail. +after the +.i uid_map +and +.i gid_map +files have been written, only the mapped values may be used in +system calls that change user and group ids. +.pp +for user ids, the relevant system calls include +.br setuid (2), +.br setfsuid (2), +.br setreuid (2), +and +.br setresuid (2). +for group ids, the relevant system calls include +.br setgid (2), +.br setfsgid (2), +.br setregid (2), +.br setresgid (2), +and +.br setgroups (2). +.pp +writing +.ri \(dq deny \(dq +to the +.i /proc/[pid]/setgroups +file before writing to +.i /proc/[pid]/gid_map +.\" things changed in linux 3.19 +.\" commit 9cc46516ddf497ea16e8d7cb986ae03a0f6b92f8 +.\" commit 66d2f338ee4c449396b6f99f5e75cd18eb6df272 +.\" http://lwn.net/articles/626665/ +will permanently disable +.br setgroups (2) +in a user namespace and allow writing to +.i /proc/[pid]/gid_map +without having the +.br cap_setgid +capability in the parent user namespace. +.\" +.\" ============================================================ +.\" +.ss the /proc/[pid]/setgroups file +.\" +.\" commit 9cc46516ddf497ea16e8d7cb986ae03a0f6b92f8 +.\" commit 66d2f338ee4c449396b6f99f5e75cd18eb6df272 +.\" http://lwn.net/articles/626665/ +.\" http://web.nvd.nist.gov/view/vuln/detail?vulnid=cve-2014-8989 +.\" +the +.i /proc/[pid]/setgroups +file displays the string +.ri \(dq allow \(dq +if processes in the user namespace that contains the process +.i pid +are permitted to employ the +.br setgroups (2) +system call; it displays +.ri \(dq deny \(dq +if +.br setgroups (2) +is not permitted in that user namespace. +note that regardless of the value in the +.i /proc/[pid]/setgroups +file (and regardless of the process's capabilities), calls to +.br setgroups (2) +are also not permitted if +.ir /proc/[pid]/gid_map +has not yet been set. +.pp +a privileged process (one with the +.br cap_sys_admin +capability in the namespace) may write either of the strings +.ri \(dq allow \(dq +or +.ri \(dq deny \(dq +to this file +.i before +writing a group id mapping +for this user namespace to the file +.ir /proc/[pid]/gid_map . +writing the string +.ri \(dq deny \(dq +prevents any process in the user namespace from employing +.br setgroups (2). +.pp +the essence of the restrictions described in the preceding +paragraph is that it is permitted to write to +.i /proc/[pid]/setgroups +only so long as calling +.br setgroups (2) +is disallowed because +.i /proc/[pid]/gid_map +has not been set. +this ensures that a process cannot transition from a state where +.br setgroups (2) +is allowed to a state where +.br setgroups (2) +is denied; +a process can transition only from +.br setgroups (2) +being disallowed to +.br setgroups (2) +being allowed. +.pp +the default value of this file in the initial user namespace is +.ri \(dq allow \(dq. +.pp +once +.ir /proc/[pid]/gid_map +has been written to +(which has the effect of enabling +.br setgroups (2) +in the user namespace), +it is no longer possible to disallow +.br setgroups (2) +by writing +.ri \(dq deny \(dq +to +.ir /proc/[pid]/setgroups +(the write fails with the error +.br eperm ). +.pp +a child user namespace inherits the +.ir /proc/[pid]/setgroups +setting from its parent. +.pp +if the +.i setgroups +file has the value +.ri \(dq deny \(dq, +then the +.br setgroups (2) +system call can't subsequently be reenabled (by writing +.ri \(dq allow \(dq +to the file) in this user namespace. +(attempts to do so fail with the error +.br eperm .) +this restriction also propagates down to all child user namespaces of +this user namespace. +.pp +the +.i /proc/[pid]/setgroups +file was added in linux 3.19, +but was backported to many earlier stable kernel series, +because it addresses a security issue. +the issue concerned files with permissions such as "rwx\-\-\-rwx". +such files give fewer permissions to "group" than they do to "other". +this means that dropping groups using +.br setgroups (2) +might allow a process file access that it did not formerly have. +before the existence of user namespaces this was not a concern, +since only a privileged process (one with the +.br cap_setgid +capability) could call +.br setgroups (2). +however, with the introduction of user namespaces, +it became possible for an unprivileged process to create +a new namespace in which the user had all privileges. +this then allowed formerly unprivileged +users to drop groups and thus gain file access +that they did not previously have. +the +.i /proc/[pid]/setgroups +file was added to address this security issue, +by denying any pathway for an unprivileged process to drop groups with +.br setgroups (2). +.\" +.\" /proc/pid/setgroups +.\" [allow == setgroups() is allowed, "deny" == setgroups() is disallowed] +.\" * can write if have cap_sys_admin in ns +.\" * must write before writing to /proc/pid/gid_map +.\" +.\" setgroups() +.\" * must already have written to gid_map +.\" * /proc/pid/setgroups must be "allow" +.\" +.\" /proc/pid/gid_map -- writing +.\" * must already have written "deny" to /proc/pid/setgroups +.\" +.\" ============================================================ +.\" +.ss unmapped user and group ids +there are various places where an unmapped user id (group id) +may be exposed to user space. +for example, the first process in a new user namespace may call +.br getuid (2) +before a user id mapping has been defined for the namespace. +in most such cases, an unmapped user id is converted +.\" from_kuid_munged(), from_kgid_munged() +to the overflow user id (group id); +the default value for the overflow user id (group id) is 65534. +see the descriptions of +.ir /proc/sys/kernel/overflowuid +and +.ir /proc/sys/kernel/overflowgid +in +.br proc (5). +.pp +the cases where unmapped ids are mapped in this fashion include +system calls that return user ids +.rb ( getuid (2), +.br getgid (2), +and similar), +credentials passed over a unix domain socket, +.\" also so_peercred +credentials returned by +.br stat (2), +.br waitid (2), +and the system v ipc "ctl" +.b ipc_stat +operations, +credentials exposed by +.ir /proc/[pid]/status +and the files in +.ir /proc/sysvipc/* , +credentials returned via the +.i si_uid +field in the +.i siginfo_t +received with a signal (see +.br sigaction (2)), +credentials written to the process accounting file (see +.br acct (5)), +and credentials returned with posix message queue notifications (see +.br mq_notify (3)). +.pp +there is one notable case where unmapped user and group ids are +.i not +.\" from_kuid(), from_kgid() +.\" also f_getowner_uids is an exception +converted to the corresponding overflow id value. +when viewing a +.i uid_map +or +.i gid_map +file in which there is no mapping for the second field, +that field is displayed as 4294967295 (\-1 as an unsigned integer). +.\" +.\" ============================================================ +.\" +.ss accessing files +in order to determine permissions when an unprivileged process accesses a file, +the process credentials (uid, gid) and the file credentials +are in effect mapped back to what they would be in +the initial user namespace and then compared to determine +the permissions that the process has on the file. +the same is also of other objects that employ the credentials plus +permissions mask accessibility model, such as system v ipc objects +.\" +.\" ============================================================ +.\" +.ss operation of file-related capabilities +certain capabilities allow a process to bypass various +kernel-enforced restrictions when performing operations on +files owned by other users or groups. +these capabilities are: +.br cap_chown , +.br cap_dac_override , +.br cap_dac_read_search , +.br cap_fowner , +and +.br cap_fsetid . +.pp +within a user namespace, +these capabilities allow a process to bypass the rules +if the process has the relevant capability over the file, +meaning that: +.ip * 3 +the process has the relevant effective capability in its user namespace; and +.ip * +the file's user id and group id both have valid mappings +in the user namespace. +.pp +the +.br cap_fowner +capability is treated somewhat exceptionally: +.\" these are the checks performed by the kernel function +.\" inode_owner_or_capable(). there is one exception to the exception: +.\" overriding the directory sticky permission bit requires that +.\" the file has a valid mapping for both its uid and gid. +it allows a process to bypass the corresponding rules so long as +at least the file's user id has a mapping in the user namespace +(i.e., the file's group id does not need to have a valid mapping). +.\" +.\" ============================================================ +.\" +.ss set-user-id and set-group-id programs +when a process inside a user namespace executes +a set-user-id (set-group-id) program, +the process's effective user (group) id inside the namespace is changed +to whatever value is mapped for the user (group) id of the file. +however, if either the user +.i or +the group id of the file has no mapping inside the namespace, +the set-user-id (set-group-id) bit is silently ignored: +the new program is executed, +but the process's effective user (group) id is left unchanged. +(this mirrors the semantics of executing a set-user-id or set-group-id +program that resides on a filesystem that was mounted with the +.br ms_nosuid +flag, as described in +.br mount (2).) +.\" +.\" ============================================================ +.\" +.ss miscellaneous +when a process's user and group ids are passed over a unix domain socket +to a process in a different user namespace (see the description of +.b scm_credentials +in +.br unix (7)), +they are translated into the corresponding values as per the +receiving process's user and group id mappings. +.\" +.sh conforming to +namespaces are a linux-specific feature. +.\" +.sh notes +over the years, there have been a lot of features that have been added +to the linux kernel that have been made available only to privileged users +because of their potential to confuse set-user-id-root applications. +in general, it becomes safe to allow the root user in a user namespace to +use those features because it is impossible, while in a user namespace, +to gain more privilege than the root user of a user namespace has. +.\" +.\" ============================================================ +.\" +.ss global root +the term "global root" is sometimes used as a shorthand for +user id 0 in the initial user namespace. +.\" +.\" ============================================================ +.\" +.ss availability +use of user namespaces requires a kernel that is configured with the +.b config_user_ns +option. +user namespaces require support in a range of subsystems across +the kernel. +when an unsupported subsystem is configured into the kernel, +it is not possible to configure user namespaces support. +.pp +as at linux 3.8, most relevant subsystems supported user namespaces, +but a number of filesystems did not have the infrastructure needed +to map user and group ids between user namespaces. +linux 3.9 added the required infrastructure support for many of +the remaining unsupported filesystems +(plan 9 (9p), andrew file system (afs), ceph, cifs, coda, nfs, and ocfs2). +linux 3.12 added support for the last of the unsupported major filesystems, +.\" commit d6970d4b726cea6d7a9bc4120814f95c09571fc3 +xfs. +.\" +.sh examples +the program below is designed to allow experimenting with +user namespaces, as well as other types of namespaces. +it creates namespaces as specified by command-line options and then executes +a command inside those namespaces. +the comments and +.i usage() +function inside the program provide a full explanation of the program. +the following shell session demonstrates its use. +.pp +first, we look at the run-time environment: +.pp +.in +4n +.ex +$ \fbuname \-rs\fp # need linux 3.8 or later +linux 3.8.0 +$ \fbid \-u\fp # running as unprivileged user +1000 +$ \fbid \-g\fp +1000 +.ee +.in +.pp +now start a new shell in new user +.ri ( \-u ), +mount +.ri ( \-m ), +and pid +.ri ( \-p ) +namespaces, with user id +.ri ( \-m ) +and group id +.ri ( \-g ) +1000 mapped to 0 inside the user namespace: +.pp +.in +4n +.ex +$ \fb./userns_child_exec \-p \-m \-u \-m \(aq0 1000 1\(aq \-g \(aq0 1000 1\(aq bash\fp +.ee +.in +.pp +the shell has pid 1, because it is the first process in the new +pid namespace: +.pp +.in +4n +.ex +bash$ \fbecho $$\fp +1 +.ee +.in +.pp +mounting a new +.i /proc +filesystem and listing all of the processes visible +in the new pid namespace shows that the shell can't see +any processes outside the pid namespace: +.pp +.in +4n +.ex +bash$ \fbmount \-t proc proc /proc\fp +bash$ \fbps ax\fp + pid tty stat time command + 1 pts/3 s 0:00 bash + 22 pts/3 r+ 0:00 ps ax +.ee +.in +.pp +inside the user namespace, the shell has user and group id 0, +and a full set of permitted and effective capabilities: +.pp +.in +4n +.ex +bash$ \fbcat /proc/$$/status | egrep \(aq\(ha[ug]id\(aq\fp +uid: 0 0 0 0 +gid: 0 0 0 0 +bash$ \fbcat /proc/$$/status | egrep \(aq\(hacap(prm|inh|eff)\(aq\fp +capinh: 0000000000000000 +capprm: 0000001fffffffff +capeff: 0000001fffffffff +.ee +.in +.ss program source +\& +.ex +/* userns_child_exec.c + + licensed under gnu general public license v2 or later + + create a child process that executes a shell command in new + namespace(s); allow uid and gid mappings to be specified when + creating a user namespace. +*/ +#define _gnu_source +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* a simple error\-handling function: print an error message based + on the value in \(aqerrno\(aq and terminate the calling process. */ + +#define errexit(msg) do { perror(msg); exit(exit_failure); \e + } while (0) + +struct child_args { + char **argv; /* command to be executed by child, with args */ + int pipe_fd[2]; /* pipe used to synchronize parent and child */ +}; + +static int verbose; + +static void +usage(char *pname) +{ + fprintf(stderr, "usage: %s [options] cmd [arg...]\en\en", pname); + fprintf(stderr, "create a child process that executes a shell " + "command in a new user namespace,\en" + "and possibly also other new namespace(s).\en\en"); + fprintf(stderr, "options can be:\en\en"); +#define fpe(str) fprintf(stderr, " %s", str); + fpe("\-i new ipc namespace\en"); + fpe("\-m new mount namespace\en"); + fpe("\-n new network namespace\en"); + fpe("\-p new pid namespace\en"); + fpe("\-u new uts namespace\en"); + fpe("\-u new user namespace\en"); + fpe("\-m uid_map specify uid map for user namespace\en"); + fpe("\-g gid_map specify gid map for user namespace\en"); + fpe("\-z map user\(aqs uid and gid to 0 in user namespace\en"); + fpe(" (equivalent to: \-m \(aq0 1\(aq \-g \(aq0 1\(aq)\en"); + fpe("\-v display verbose messages\en"); + fpe("\en"); + fpe("if \-z, \-m, or \-g is specified, \-u is required.\en"); + fpe("it is not permitted to specify both \-z and either \-m or \-g.\en"); + fpe("\en"); + fpe("map strings for \-m and \-g consist of records of the form:\en"); + fpe("\en"); + fpe(" id\-inside\-ns id\-outside\-ns len\en"); + fpe("\en"); + fpe("a map string can contain multiple records, separated" + " by commas;\en"); + fpe("the commas are replaced by newlines before writing" + " to map files.\en"); + + exit(exit_failure); +} + +/* update the mapping file \(aqmap_file\(aq, with the value provided in + \(aqmapping\(aq, a string that defines a uid or gid mapping. a uid or + gid mapping consists of one or more newline\-delimited records + of the form: + + id_inside\-ns id\-outside\-ns length + + requiring the user to supply a string that contains newlines is + of course inconvenient for command\-line use. thus, we permit the + use of commas to delimit records in this string, and replace them + with newlines before writing the string to the file. */ + +static void +update_map(char *mapping, char *map_file) +{ + int fd; + size_t map_len; /* length of \(aqmapping\(aq */ + + /* replace commas in mapping string with newlines. */ + + map_len = strlen(mapping); + for (int j = 0; j < map_len; j++) + if (mapping[j] == \(aq,\(aq) + mapping[j] = \(aq\en\(aq; + + fd = open(map_file, o_rdwr); + if (fd == \-1) { + fprintf(stderr, "error: open %s: %s\en", map_file, + strerror(errno)); + exit(exit_failure); + } + + if (write(fd, mapping, map_len) != map_len) { + fprintf(stderr, "error: write %s: %s\en", map_file, + strerror(errno)); + exit(exit_failure); + } + + close(fd); +} + +/* linux 3.19 made a change in the handling of setgroups(2) and the + \(aqgid_map\(aq file to address a security issue. the issue allowed + *unprivileged* users to employ user namespaces in order to drop + the upshot of the 3.19 changes is that in order to update the + \(aqgid_maps\(aq file, use of the setgroups() system call in this + user namespace must first be disabled by writing "deny" to one of + the /proc/pid/setgroups files for this namespace. that is the + purpose of the following function. */ + +static void +proc_setgroups_write(pid_t child_pid, char *str) +{ + char setgroups_path[path_max]; + int fd; + + snprintf(setgroups_path, path_max, "/proc/%jd/setgroups", + (intmax_t) child_pid); + + fd = open(setgroups_path, o_rdwr); + if (fd == \-1) { + + /* we may be on a system that doesn\(aqt support + /proc/pid/setgroups. in that case, the file won\(aqt exist, + and the system won\(aqt impose the restrictions that linux 3.19 + added. that\(aqs fine: we don\(aqt need to do anything in order + to permit \(aqgid_map\(aq to be updated. + + however, if the error from open() was something other than + the enoent error that is expected for that case, let the + user know. */ + + if (errno != enoent) + fprintf(stderr, "error: open %s: %s\en", setgroups_path, + strerror(errno)); + return; + } + + if (write(fd, str, strlen(str)) == \-1) + fprintf(stderr, "error: write %s: %s\en", setgroups_path, + strerror(errno)); + + close(fd); +} + +static int /* start function for cloned child */ +childfunc(void *arg) +{ + struct child_args *args = arg; + char ch; + + /* wait until the parent has updated the uid and gid mappings. + see the comment in main(). we wait for end of file on a + pipe that will be closed by the parent process once it has + updated the mappings. */ + + close(args\->pipe_fd[1]); /* close our descriptor for the write + end of the pipe so that we see eof + when parent closes its descriptor. */ + if (read(args\->pipe_fd[0], &ch, 1) != 0) { + fprintf(stderr, + "failure in child: read from pipe returned != 0\en"); + exit(exit_failure); + } + + close(args\->pipe_fd[0]); + + /* execute a shell command. */ + + printf("about to exec %s\en", args\->argv[0]); + execvp(args\->argv[0], args\->argv); + errexit("execvp"); +} + +#define stack_size (1024 * 1024) + +static char child_stack[stack_size]; /* space for child\(aqs stack */ + +int +main(int argc, char *argv[]) +{ + int flags, opt, map_zero; + pid_t child_pid; + struct child_args args; + char *uid_map, *gid_map; + const int map_buf_size = 100; + char map_buf[map_buf_size]; + char map_path[path_max]; + + /* parse command\-line options. the initial \(aq+\(aq character in + the final getopt() argument prevents gnu\-style permutation + of command\-line options. that\(aqs useful, since sometimes + the \(aqcommand\(aq to be executed by this program itself + has command\-line options. we don\(aqt want getopt() to treat + those as options to this program. */ + + flags = 0; + verbose = 0; + gid_map = null; + uid_map = null; + map_zero = 0; + while ((opt = getopt(argc, argv, "+imnpuum:g:zv")) != \-1) { + switch (opt) { + case \(aqi\(aq: flags |= clone_newipc; break; + case \(aqm\(aq: flags |= clone_newns; break; + case \(aqn\(aq: flags |= clone_newnet; break; + case \(aqp\(aq: flags |= clone_newpid; break; + case \(aqu\(aq: flags |= clone_newuts; break; + case \(aqv\(aq: verbose = 1; break; + case \(aqz\(aq: map_zero = 1; break; + case \(aqm\(aq: uid_map = optarg; break; + case \(aqg\(aq: gid_map = optarg; break; + case \(aqu\(aq: flags |= clone_newuser; break; + default: usage(argv[0]); + } + } + + /* \-m or \-g without \-u is nonsensical */ + + if (((uid_map != null || gid_map != null || map_zero) && + !(flags & clone_newuser)) || + (map_zero && (uid_map != null || gid_map != null))) + usage(argv[0]); + + args.argv = &argv[optind]; + + /* we use a pipe to synchronize the parent and child, in order to + ensure that the parent sets the uid and gid maps before the child + calls execve(). this ensures that the child maintains its + capabilities during the execve() in the common case where we + want to map the child\(aqs effective user id to 0 in the new user + namespace. without this synchronization, the child would lose + its capabilities if it performed an execve() with nonzero + user ids (see the capabilities(7) man page for details of the + transformation of a process\(aqs capabilities during execve()). */ + + if (pipe(args.pipe_fd) == \-1) + errexit("pipe"); + + /* create the child in new namespace(s). */ + + child_pid = clone(childfunc, child_stack + stack_size, + flags | sigchld, &args); + if (child_pid == \-1) + errexit("clone"); + + /* parent falls through to here. */ + + if (verbose) + printf("%s: pid of child created by clone() is %jd\en", + argv[0], (intmax_t) child_pid); + + /* update the uid and gid maps in the child. */ + + if (uid_map != null || map_zero) { + snprintf(map_path, path_max, "/proc/%jd/uid_map", + (intmax_t) child_pid); + if (map_zero) { + snprintf(map_buf, map_buf_size, "0 %jd 1", + (intmax_t) getuid()); + uid_map = map_buf; + } + update_map(uid_map, map_path); + } + + if (gid_map != null || map_zero) { + proc_setgroups_write(child_pid, "deny"); + + snprintf(map_path, path_max, "/proc/%jd/gid_map", + (intmax_t) child_pid); + if (map_zero) { + snprintf(map_buf, map_buf_size, "0 %ld 1", + (intmax_t) getgid()); + gid_map = map_buf; + } + update_map(gid_map, map_path); + } + + /* close the write end of the pipe, to signal to the child that we + have updated the uid and gid maps. */ + + close(args.pipe_fd[1]); + + if (waitpid(child_pid, null, 0) == \-1) /* wait for child */ + errexit("waitpid"); + + if (verbose) + printf("%s: terminating\en", argv[0]); + + exit(exit_success); +} +.ee +.sh see also +.br newgidmap (1), \" from the shadow package +.br newuidmap (1), \" from the shadow package +.br clone (2), +.br ptrace (2), +.br setns (2), +.br unshare (2), +.br proc (5), +.br subgid (5), \" from the shadow package +.br subuid (5), \" from the shadow package +.br capabilities (7), +.br cgroup_namespaces (7), +.br credentials (7), +.br namespaces (7), +.br pid_namespaces (7) +.pp +the kernel source file +.ir documentation/admin\-guide/namespaces/resource\-control.rst . +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/clog2.3 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sat jul 24 19:17:53 1993 by rik faith (faith@cs.unc.edu) +.th getusershell 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +getusershell, setusershell, endusershell \- get permitted user shells +.sh synopsis +.nf +.b #include +.pp +.b char *getusershell(void); +.b void setusershell(void); +.b void endusershell(void); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br getusershell (), +.br setusershell (), +.br endusershell (): +.nf + since glibc 2.21: +.\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8 + _default_source + in glibc 2.19 and 2.20: + _default_source || (_xopen_source && _xopen_source < 500) + up to and including glibc 2.19: + _bsd_source || (_xopen_source && _xopen_source < 500) +.fi +.sh description +the +.br getusershell () +function returns the next line from the file +.ir /etc/shells , +opening the file if necessary. +the line should contain +the pathname of a valid user shell. +if +.i /etc/shells +does not exist or +is unreadable, +.br getusershell () +behaves as if +.i /bin/sh +and +.i /bin/csh +were listed in the file. +.pp +the +.br setusershell () +function rewinds +.ir /etc/shells . +.pp +the +.br endusershell () +function closes +.ir /etc/shells . +.sh return value +the +.br getusershell () +function returns null on end-of-file. +.sh files +.i /etc/shells +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br getusershell (), +.br setusershell (), +.br endusershell () +t} thread safety mt-unsafe +.te +.hy +.ad +.sp 1 +.sh conforming to +4.3bsd. +.sh see also +.br shells (5) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/select.2 + +.so man3/cexp2.3 + +.\" copyright (c) 2014 michael kerrisk +.\" and copyright (c) 2014 peter zijlstra +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th sched_setattr 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +sched_setattr, sched_getattr \- +set and get scheduling policy and attributes +.sh synopsis +.nf +.br "#include " " /* definition of " sched_* " constants */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "int syscall(sys_sched_setattr, pid_t " pid ", struct sched_attr *" attr , +.bi " unsigned int " flags ); +.bi "int syscall(sys_sched_getattr, pid_t " pid ", struct sched_attr *" attr , +.bi " unsigned int " size ", unsigned int " flags ); +.fi +.\" fixme . add feature test macro requirements +.pp +.ir note : +glibc provides no wrappers for these system calls, +necessitating the use of +.br syscall (2). +.sh description +.ss sched_setattr() +the +.br sched_setattr () +system call sets the scheduling policy and +associated attributes for the thread whose id is specified in +.ir pid . +if +.i pid +equals zero, +the scheduling policy and attributes of the calling thread will be set. +.pp +currently, linux supports the following "normal" +(i.e., non-real-time) scheduling policies as values that may be specified in +.ir policy : +.tp 14 +.br sched_other +the standard round-robin time-sharing policy; +.\" in the 2.6 kernel sources, sched_other is actually called +.\" sched_normal. +.tp +.br sched_batch +for "batch" style execution of processes; and +.tp +.br sched_idle +for running +.i very +low priority background jobs. +.pp +various "real-time" policies are also supported, +for special time-critical applications that need precise control over +the way in which runnable threads are selected for execution. +for the rules governing when a process may use these policies, see +.br sched (7). +the real-time policies that may be specified in +.ir policy +are: +.tp 14 +.br sched_fifo +a first-in, first-out policy; and +.tp +.br sched_rr +a round-robin policy. +.pp +linux also provides the following policy: +.tp 14 +.b sched_deadline +a deadline scheduling policy; see +.br sched (7) +for details. +.pp +the +.i attr +argument is a pointer to a structure that defines +the new scheduling policy and attributes for the specified thread. +this structure has the following form: +.pp +.in +4n +.ex +struct sched_attr { + u32 size; /* size of this structure */ + u32 sched_policy; /* policy (sched_*) */ + u64 sched_flags; /* flags */ + s32 sched_nice; /* nice value (sched_other, + sched_batch) */ + u32 sched_priority; /* static priority (sched_fifo, + sched_rr) */ + /* remaining fields are for sched_deadline */ + u64 sched_runtime; + u64 sched_deadline; + u64 sched_period; +}; +.ee +.in +.pp +the fields of the +.ir sched_attr +structure are as follows: +.tp +.b size +this field should be set to the size of the structure in bytes, as in +.ir "sizeof(struct sched_attr)" . +if the provided structure is smaller than the kernel structure, +any additional fields are assumed to be '0'. +if the provided structure is larger than the kernel structure, +the kernel verifies that all additional fields are 0; +if they are not, +.br sched_setattr () +fails with the error +.br e2big +and updates +.i size +to contain the size of the kernel structure. +.ip +the above behavior when the size of the user-space +.i sched_attr +structure does not match the size of the kernel structure +allows for future extensibility of the interface. +malformed applications that pass oversize structures +won't break in the future if the size of the kernel +.i sched_attr +structure is increased. +in the future, +it could also allow applications that know about a larger user-space +.i sched_attr +structure to determine whether they are running on an older kernel +that does not support the larger structure. +.tp +.i sched_policy +this field specifies the scheduling policy, as one of the +.br sched_* +values listed above. +.tp +.i sched_flags +this field contains zero or more of the following flags +that are ored together to control scheduling behavior: +.rs +.tp +.br sched_flag_reset_on_fork +children created by +.br fork (2) +do not inherit privileged scheduling policies. +see +.br sched (7) +for details. +.tp +.br sched_flag_reclaim " (since linux 4.13)" +.\" 2d4283e9d583a3ee8cfb1cbb9c1270614df4c29d +this flag allows a +.br sched_deadline +thread to reclaim bandwidth unused by other real-time threads. +.\" bandwidth reclaim is done via the grub algorithm; see +.\" documentation/scheduler/sched-deadline.txt +.tp +.br sched_flag_dl_overrun " (since linux 4.16)" +.\" commit 34be39305a77b8b1ec9f279163c7cdb6cc719b91 +this flag allows an application to get informed about run-time overruns in +.br sched_deadline +threads. +such overruns may be caused by (for example) coarse execution time accounting +or incorrect parameter assignment. +notification takes the form of a +.b sigxcpu +signal which is generated on each overrun. +.ip +this +.br sigxcpu +signal is +.i process-directed +(see +.br signal (7)) +rather than thread-directed. +this is probably a bug. +on the one hand, +.br sched_setattr () +is being used to set a per-thread attribute. +on the other hand, if the process-directed signal is delivered to +a thread inside the process other than the one that had a run-time overrun, +the application has no way of knowing which thread overran. +.re +.tp +.i sched_nice +this field specifies the nice value to be set when specifying +.ir sched_policy +as +.br sched_other +or +.br sched_batch . +the nice value is a number in the range \-20 (high priority) +to +19 (low priority); see +.br sched (7). +.tp +.i sched_priority +this field specifies the static priority to be set when specifying +.ir sched_policy +as +.br sched_fifo +or +.br sched_rr . +the allowed range of priorities for these policies can be determined using +.br sched_get_priority_min (2) +and +.br sched_get_priority_max (2). +for other policies, this field must be specified as 0. +.tp +.i sched_runtime +this field specifies the "runtime" parameter for deadline scheduling. +the value is expressed in nanoseconds. +this field, and the next two fields, +are used only for +.br sched_deadline +scheduling; for further details, see +.br sched (7). +.tp +.i sched_deadline +this field specifies the "deadline" parameter for deadline scheduling. +the value is expressed in nanoseconds. +.tp +.i sched_period +this field specifies the "period" parameter for deadline scheduling. +the value is expressed in nanoseconds. +.pp +the +.i flags +argument is provided to allow for future extensions to the interface; +in the current implementation it must be specified as 0. +.\" +.\" +.ss sched_getattr() +the +.br sched_getattr () +system call fetches the scheduling policy and the +associated attributes for the thread whose id is specified in +.ir pid . +if +.i pid +equals zero, +the scheduling policy and attributes of the calling thread +will be retrieved. +.pp +the +.i size +argument should be set to the size of the +.i sched_attr +structure as known to user space. +the value must be at least as large as the size of the initially published +.i sched_attr +structure, or the call fails with the error +.br einval . +.pp +the retrieved scheduling attributes are placed in the fields of the +.i sched_attr +structure pointed to by +.ir attr . +the kernel sets +.i attr.size +to the size of its +.i sched_attr +structure. +.pp +if the caller-provided +.i attr +buffer is larger than the kernel's +.i sched_attr +structure, +the additional bytes in the user-space structure are not touched. +if the caller-provided structure is smaller than the kernel +.i sched_attr +structure, the kernel will silently not return any values which would be stored +outside the provided space. +as with +.br sched_setattr (), +these semantics allow for future extensibility of the interface. +.pp +the +.i flags +argument is provided to allow for future extensions to the interface; +in the current implementation it must be specified as 0. +.sh return value +on success, +.br sched_setattr () +and +.br sched_getattr () +return 0. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.br sched_getattr () +and +.br sched_setattr () +can both fail for the following reasons: +.tp +.b einval +.i attr +is null; or +.i pid +is negative; or +.i flags +is not zero. +.tp +.b esrch +the thread whose id is +.i pid +could not be found. +.pp +in addition, +.br sched_getattr () +can fail for the following reasons: +.tp +.b e2big +the buffer specified by +.i size +and +.i attr +is too small. +.tp +.b einval +.i size +is invalid; that is, it is smaller than the initial version of the +.i sched_attr +structure (48 bytes) or larger than the system page size. +.pp +in addition, +.br sched_setattr () +can fail for the following reasons: +.tp +.b e2big +the buffer specified by +.i size +and +.i attr +is larger than the kernel structure, +and one or more of the excess bytes is nonzero. +.tp +.b ebusy +.b sched_deadline +admission control failure, see +.br sched (7). +.tp +.b einval +.i attr.sched_policy +is not one of the recognized policies; +.i attr.sched_flags +contains a flag other than +.br sched_flag_reset_on_fork ; +or +.i attr.sched_priority +is invalid; or +.i attr.sched_policy +is +.br sched_deadline +and the deadline scheduling parameters in +.i attr +are invalid. +.tp +.b eperm +the caller does not have appropriate privileges. +.tp +.b eperm +the cpu affinity mask of the thread specified by +.i pid +does not include all cpus in the system +(see +.br sched_setaffinity (2)). +.sh versions +these system calls first appeared in linux 3.14. +.\" fixme . add glibc version +.sh conforming to +these system calls are nonstandard linux extensions. +.sh notes +glibc does not provide wrappers for these system calls; call them using +.br syscall (2). +.pp +.br sched_setattr () +provides a superset of the functionality of +.br sched_setscheduler (2), +.br sched_setparam (2), +.br nice (2), +and (other than the ability to set the priority of all processes +belonging to a specified user or all processes in a specified group) +.br setpriority (2). +analogously, +.br sched_getattr () +provides a superset of the functionality of +.br sched_getscheduler (2), +.br sched_getparam (2), +and (partially) +.br getpriority (2). +.sh bugs +in linux versions up to +.\" fixme . patch sent to peter zijlstra +3.15, +.br sched_setattr () +failed with the error +.br efault +instead of +.br e2big +for the case described in errors. +.pp +in linux versions up to 5.3, +.br sched_getattr () +failed with the error +.br efbig +if the in-kernel +.ir sched_attr +structure was larger than the +.ir size +passed by user space. +.\" in linux versions up to up 3.15, +.\" fixme . patch from peter zijlstra pending +.\" .br sched_setattr () +.\" allowed a negative +.\" .i attr.sched_policy +.\" value. +.sh see also +.ad l +.nh +.br chrt (1), +.br nice (2), +.br sched_get_priority_max (2), +.br sched_get_priority_min (2), +.br sched_getaffinity (2), +.br sched_getparam (2), +.br sched_getscheduler (2), +.br sched_rr_get_interval (2), +.br sched_setaffinity (2), +.br sched_setparam (2), +.br sched_setscheduler (2), +.br sched_yield (2), +.br setpriority (2), +.br pthread_getschedparam (3), +.br pthread_setschedparam (3), +.br pthread_setschedprio (3), +.br capabilities (7), +.br cpuset (7), +.br sched (7) +.ad +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2001 andries brouwer . +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th unlocked_stdio 3 2021-03-22 "" "linux programmer's manual" +.sh name +getc_unlocked, getchar_unlocked, putc_unlocked, +putchar_unlocked \- nonlocking stdio functions +.sh synopsis +.nf +.b #include +.pp +.bi "int getc_unlocked(file *" stream ); +.b "int getchar_unlocked(void);" +.bi "int putc_unlocked(int " c ", file *" stream ); +.bi "int putchar_unlocked(int " c ); +.pp +.bi "void clearerr_unlocked(file *" stream ); +.bi "int feof_unlocked(file *" stream ); +.bi "int ferror_unlocked(file *" stream ); +.bi "int fileno_unlocked(file *" stream ); +.bi "int fflush_unlocked(file *" stream ); +.pp +.bi "int fgetc_unlocked(file *" stream ); +.bi "int fputc_unlocked(int " c ", file *" stream ); +.pp +.bi "size_t fread_unlocked(void *restrict " ptr ", size_t " size ", size_t " n , +.bi " file *restrict " stream ); +.bi "size_t fwrite_unlocked(const void *restrict " ptr ", size_t " size \ +", size_t " n , +.bi " file *restrict " stream ); +.pp +.bi "char *fgets_unlocked(char *restrict " s ", int " n \ +", file *restrict " stream ); +.bi "int fputs_unlocked(const char *restrict " s ", file *restrict " stream ); +.pp +.b #include +.pp +.bi "wint_t getwc_unlocked(file *" stream ); +.b "wint_t getwchar_unlocked(void);" +.bi "wint_t fgetwc_unlocked(file *" stream ); +.pp +.bi "wint_t fputwc_unlocked(wchar_t " wc ", file *" stream ); +.bi "wint_t putwc_unlocked(wchar_t " wc ", file *" stream ); +.bi "wint_t putwchar_unlocked(wchar_t " wc ); +.pp +.bi "wchar_t *fgetws_unlocked(wchar_t *restrict " ws ", int " n , +.bi " file *restrict " stream ); +.bi "int fputws_unlocked(const wchar_t *restrict " ws , +.bi " file *restrict " stream ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.nh +.re +.ad l +.pp +.br getc_unlocked (), +.br getchar_unlocked (), +.br putc_unlocked (), +.br putchar_unlocked (): +.nf + /* since glibc 2.24: */ _posix_c_source >= 199309l + || /* glibc <= 2.23: */ _posix_c_source + || /* glibc <= 2.19: */ _svid_source || _bsd_source +.fi +.pp +.br clearerr_unlocked (), +.br feof_unlocked (), +.br ferror_unlocked (), +.br fileno_unlocked (), +.br fflush_unlocked (), +.br fgetc_unlocked (), +.br fputc_unlocked (), +.br fread_unlocked (), +.br fwrite_unlocked (): +.nf + /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _svid_source || _bsd_source +.fi +.pp +.br fgets_unlocked (), +.br fputs_unlocked (), +.br getwc_unlocked (), +.br getwchar_unlocked (), +.br fgetwc_unlocked (), +.br fputwc_unlocked (), +.br putwchar_unlocked (), +.br fgetws_unlocked (), +.br fputws_unlocked (): +.nf + _gnu_source +.fi +.hy +.ad +.sh description +each of these functions has the same behavior as its counterpart +without the "_unlocked" suffix, except that they do not use locking +(they do not set locks themselves, and do not test for the presence +of locks set by others) and hence are thread-unsafe. +see +.br flockfile (3). +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lb lb lbx +l l l. +interface attribute value +t{ +.br getc_unlocked (), +.br putc_unlocked (), +.br clearerr_unlocked (), +.br fflush_unlocked (), +.br fgetc_unlocked (), +.br fputc_unlocked (), +.br fread_unlocked (), +.br fwrite_unlocked (), +.br fgets_unlocked (), +.br fputs_unlocked (), +.br getwc_unlocked (), +.br fgetwc_unlocked (), +.br fputwc_unlocked (), +.br putwc_unlocked (), +.br fgetws_unlocked (), +.br fputws_unlocked () +t} thread safety t{ +mt-safe race:stream +t} +t{ +.br getchar_unlocked (), +.br getwchar_unlocked () +t} thread safety t{ +mt-unsafe race:stdin +t} +t{ +.br putchar_unlocked (), +.br putwchar_unlocked () +t} thread safety t{ +mt-unsafe race:stdout +t} +t{ +.br feof_unlocked (), +.br ferror_unlocked (), +.br fileno_unlocked () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +the four functions +.br getc_unlocked (), +.br getchar_unlocked (), +.br putc_unlocked (), +.br putchar_unlocked () +are in posix.1-2001 and posix.1-2008. +.pp +the nonstandard +.br *_unlocked () +variants occur on a few unix systems, and are available in recent glibc. +.\" e.g., in hp-ux 10.0. in hp-ux 10.30 they are called obsolescent, and +.\" moved to a compatibility library. +.\" available in hp-ux 10.0: clearerr_unlocked, fclose_unlocked, +.\" feof_unlocked, ferror_unlocked, fflush_unlocked, fgets_unlocked, +.\" fgetwc_unlocked, fgetws_unlocked, fileno_unlocked, fputs_unlocked, +.\" fputwc_unlocked, fputws_unlocked, fread_unlocked, fseek_unlocked, +.\" ftell_unlocked, fwrite_unlocked, getc_unlocked, getchar_unlocked, +.\" getw_unlocked, getwc_unlocked, getwchar_unlocked, putc_unlocked, +.\" putchar_unlocked, puts_unlocked, putws_unlocked, putw_unlocked, +.\" putwc_unlocked, putwchar_unlocked, rewind_unlocked, setvbuf_unlocked, +.\" ungetc_unlocked, ungetwc_unlocked. +they should probably not be used. +.sh see also +.br flockfile (3), +.br stdio (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/nextafter.3 + +.so man3/index.3 + +.so man3/trunc.3 + +.\" copyright (c) 2006 by michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" 2008-06-24, mtk: added some details about where jiffies come into +.\" play; added section on high-resolution timers. +.\" +.th time 7 2020-04-11 "linux" "linux programmer's manual" +.sh name +time \- overview of time and timers +.sh description +.ss real time and process time +.i "real time" +is defined as time measured from some fixed point, +either from a standard point in the past +(see the description of the epoch and calendar time below), +or from some point (e.g., the start) in the life of a process +.ri ( "elapsed time" ). +.pp +.i "process time" +is defined as the amount of cpu time used by a process. +this is sometimes divided into +.i user +and +.i system +components. +user cpu time is the time spent executing code in user mode. +system cpu time is the time spent by the kernel executing +in system mode on behalf of the process (e.g., executing system calls). +the +.br time (1) +command can be used to determine the amount of cpu time consumed +during the execution of a program. +a program can determine the amount of cpu time it has consumed using +.br times (2), +.br getrusage (2), +or +.br clock (3). +.ss the hardware clock +most computers have a (battery-powered) hardware clock which the kernel +reads at boot time in order to initialize the software clock. +for further details, see +.br rtc (4) +and +.br hwclock (8). +.ss the software clock, hz, and jiffies +the accuracy of various system calls that set timeouts, +(e.g., +.br select (2), +.br sigtimedwait (2)) +.\" semtimedop(), mq_timedwait(), io_getevents(), poll() are the same +.\" futexes and thus sem_timedwait() seem to use high-res timers. +and measure cpu time (e.g., +.br getrusage (2)) +is limited by the resolution of the +.ir "software clock" , +a clock maintained by the kernel which measures time in +.ir jiffies . +the size of a jiffy is determined by the value of the kernel constant +.ir hz . +.pp +the value of +.i hz +varies across kernel versions and hardware platforms. +on i386 the situation is as follows: +on kernels up to and including 2.4.x, hz was 100, +giving a jiffy value of 0.01 seconds; +starting with 2.6.0, hz was raised to 1000, giving a jiffy of +0.001 seconds. +since kernel 2.6.13, the hz value is a kernel +configuration parameter and can be 100, 250 (the default) or 1000, +yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. +since kernel 2.6.20, a further frequency is available: +300, a number that divides evenly for the common video +frame rates (pal, 25 hz; ntsc, 30 hz). +.pp +the +.br times (2) +system call is a special case. +it reports times with a granularity defined by the kernel constant +.ir user_hz . +user-space applications can determine the value of this constant using +.ir sysconf(_sc_clk_tck) . +.\" glibc gets this info with a little help from the elf loader; +.\" see glibc elf/dl-support.c and kernel fs/binfmt_elf.c. +.\" +.ss system and process clocks; time namespaces +the kernel supports a range of clocks that measure various kinds of +elapsed and virtual (i.e., consumed cpu) time. +these clocks are described in +.br clock_gettime (2). +a few of the clocks are settable using +.br clock_settime (2). +the values of certain clocks are virtualized by time namespaces; see +.br time_namespaces (7). +.\" +.ss high-resolution timers +before linux 2.6.21, the accuracy of timer and sleep system calls +(see below) was also limited by the size of the jiffy. +.pp +since linux 2.6.21, linux supports high-resolution timers (hrts), +optionally configurable via +.br config_high_res_timers . +on a system that supports hrts, the accuracy of sleep and timer +system calls is no longer constrained by the jiffy, +but instead can be as accurate as the hardware allows +(microsecond accuracy is typical of modern hardware). +you can determine whether high-resolution timers are supported by +checking the resolution returned by a call to +.br clock_getres (2) +or looking at the "resolution" entries in +.ir /proc/timer_list . +.pp +hrts are not supported on all hardware architectures. +(support is provided on x86, arm, and powerpc, among others.) +.ss the epoch +unix systems represent time in seconds since the +.ir epoch , +1970-01-01 00:00:00 +0000 (utc). +.pp +a program can determine the +.i "calendar time" +via the +.br clock_gettime (2) +.br clock_realtime +clock, +which returns time (in seconds and nanoseconds) that have +elapsed since the epoch; +.br time (2) +provides similar information, but only with accuracy to the +nearest second. +the system time can be changed using +.br clock_settime (2). +.\" +.ss broken-down time +certain library functions use a structure of +type +.i tm +to represent +.ir "broken-down time" , +which stores time value separated out into distinct components +(year, month, day, hour, minute, second, etc.). +this structure is described in +.br ctime (3), +which also describes functions that convert between calendar time and +broken-down time. +functions for converting between broken-down time and printable +string representations of the time are described in +.br ctime (3), +.br strftime (3), +and +.br strptime (3). +.ss sleeping and setting timers +various system calls and functions allow a program to sleep +(suspend execution) for a specified period of time; see +.br nanosleep (2), +.br clock_nanosleep (2), +and +.br sleep (3). +.pp +various system calls allow a process to set a timer that expires +at some point in the future, and optionally at repeated intervals; +see +.br alarm (2), +.br getitimer (2), +.br timerfd_create (2), +and +.br timer_create (2). +.ss timer slack +since linux 2.6.28, it is possible to control the "timer slack" +value for a thread. +the timer slack is the length of time by +which the kernel may delay the wake-up of certain +system calls that block with a timeout. +permitting this delay allows the kernel to coalesce wake-up events, +thus possibly reducing the number of system wake-ups and saving power. +for more details, see the description of +.b pr_set_timerslack +in +.br prctl (2). +.sh see also +.ad l +.nh +.br date (1), +.br time (1), +.br timeout (1), +.br adjtimex (2), +.br alarm (2), +.br clock_gettime (2), +.br clock_nanosleep (2), +.br getitimer (2), +.br getrlimit (2), +.br getrusage (2), +.br gettimeofday (2), +.br nanosleep (2), +.br stat (2), +.br time (2), +.br timer_create (2), +.br timerfd_create (2), +.br times (2), +.br utime (2), +.br adjtime (3), +.br clock (3), +.br clock_getcpuclockid (3), +.br ctime (3), +.br ntp_adjtime (3), +.br ntp_gettime (3), +.br pthread_getcpuclockid (3), +.br sleep (3), +.br strftime (3), +.br strptime (3), +.br timeradd (3), +.br usleep (3), +.br rtc (4), +.br time_namespaces (7), +.br hwclock (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +#!/bin/sh +# +# render man pages with fixmes shown as tables +# in the rendered page +# +for f in $*; do + cat $f | awk ' + /^\.\\" *fixme/ { + if ($0 ~ /.*fixme *\..*/) { + # fixmes of the form "fixme ." are "private" and + # ignored by this script + } else { + sub("fixme[: ]*", "") + if ($0 ~ /^\.\\"[ ]*$/) { + + # if the fixme line contains no additional text after + # "fixme", then discard the blank line + + getline + } + print "" + if (fixme == 0) { + print ".ts" + print ".allbox;" + print "lbw52" + print "l." + print "fixme" + print "t{" + } + fixme = 1 + } + } + + $0 !~ /^\.\\"/ && fixme == 1 { + fixme = 0 + print "t}" + print ".te" + print "" + } + + fixme == 1 { + sub("^\\...[ ]", "") + sub("^\\...", "") + gsub("'"'"'", "\\(aq") + if ($0 ~ /^[ ][ ]*.*/) { + print ".br" + sub("^[ ]*", " ") + } + } + + { + print $0 + } + ' | tee "/tmp/$(basename $f).src" | man --nh --nj -l /dev/stdin +done + +.so man3/fseek.3 + +.so man3/cpu_set.3 + +.so man3/__ppc_set_ppr_med.3 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" gnu texinfo documentation on glibc date/time functions. +.\" modified sat jul 24 18:03:44 1993 by rik faith (faith@cs.unc.edu) +.\" applied fix by wolfgang franke, aeb, 961011 +.\" corrected return value, aeb, 970307 +.\" added single unix spec conversions and %z, aeb/esr, 990329. +.\" 2005-11-22 mtk, added glibc notes covering optional 'flag' and +.\" 'width' components of conversion specifications. +.\" +.th strftime 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +strftime \- format date and time +.sh synopsis +.nf +.b #include +.pp +.bi "size_t strftime(char *restrict " s ", size_t " max , +.bi " const char *restrict " format , +.bi " const struct tm *restrict " tm ); +.fi +.sh description +the +.br strftime () +function formats the broken-down time +.i tm +according to the format specification +.i format +and places the +result in the character array +.i s +of size +.ir max . +the broken-down time structure +.i tm +is defined in +.ir . +see also +.br ctime (3). +.\" fixme . posix says: local timezone information is used as though +.\" strftime() called tzset(). but this doesn't appear to be the case +.pp +the format specification is a null-terminated string and may contain +special character sequences called +.ir "conversion specifications", +each of which is introduced by a \(aq%\(aq character and terminated by +some other character known as a +.ir "conversion specifier character". +all other character sequences are +.ir "ordinary character sequences". +.pp +the characters of ordinary character sequences (including the null byte) +are copied verbatim from +.i format +to +.ir s . +however, the characters +of conversion specifications are replaced as shown in the list below. +in this list, the field(s) employed from the +.i tm +structure are also shown. +.tp +.b %a +the abbreviated name of the day of the week according to the current locale. +(calculated from +.ir tm_wday .) +(the specific names used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.br abday_ { 1 \(en 7 } +as an argument.) +.tp +.b %a +the full name of the day of the week according to the current locale. +(calculated from +.ir tm_wday .) +(the specific names used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.br day_ { 1 \(en 7 } +as an argument.) +.tp +.b %b +the abbreviated month name according to the current locale. +(calculated from +.ir tm_mon .) +(the specific names used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.br abmon_ { 1 \(en 12 } +as an argument.) +.tp +.b %b +the full month name according to the current locale. +(calculated from +.ir tm_mon .) +(the specific names used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.br mon_ { 1 \(en 12 } +as an argument.) +.tp +.b %c +the preferred date and time representation for the current locale. +(the specific format used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.b d_t_fmt +as an argument for the +.b %c +conversion specification, and with +.b era_d_t_fmt +for the +.b %ec +conversion specification.) +(in the posix locale this is equivalent to +.br "%a %b %e %h:%m:%s %y" .) +.tp +.b %c +the century number (year/100) as a 2-digit integer. (su) +(the +.b %ec +conversion specification corresponds to the name of the era.) +(calculated from +.ir tm_year .) +.tp +.b %d +the day of the month as a decimal number (range 01 to 31). +(calculated from +.ir tm_mday .) +.tp +.b %d +equivalent to +.br %m/%d/%y . +(yecch\(emfor americans only. +americans should note that in other countries +.b %d/%m/%y +is rather common. +this means that in international context this format is +ambiguous and should not be used.) (su) +.tp +.b %e +like +.br %d , +the day of the month as a decimal number, but a leading +zero is replaced by a space. (su) +(calculated from +.ir tm_mday .) +.tp +.b %e +modifier: use alternative ("era-based") format, see below. (su) +.tp +.b %f +equivalent to +.b %y\-%m\-%d +(the iso\ 8601 date format). (c99) +.tp +.b %g +the iso\ 8601 week-based year (see notes) with century as a decimal number. +the 4-digit year corresponding to the iso week number (see +.br %v ). +this has the same format and value as +.br %y , +except that if the iso week number belongs to the previous or next year, +that year is used instead. (tz) +(calculated from +.ir tm_year , +.ir tm_yday , +and +.ir tm_wday .) +.tp +.b %g +like +.br %g , +but without century, that is, with a 2-digit year (00\(en99). (tz) +(calculated from +.ir tm_year , +.ir tm_yday , +and +.ir tm_wday .) +.tp +.b %h +equivalent to +.br %b . +(su) +.tp +.b %h +the hour as a decimal number using a 24-hour clock (range 00 to 23). +(calculated from +.ir tm_hour .) +.tp +.b %i +the hour as a decimal number using a 12-hour clock (range 01 to 12). +(calculated from +.ir tm_hour .) +.tp +.b %j +the day of the year as a decimal number (range 001 to 366). +(calculated from +.ir tm_yday .) +.tp +.b %k +the hour (24-hour clock) as a decimal number (range 0 to 23); +single digits are preceded by a blank. +(see also +.br %h .) +(calculated from +.ir tm_hour .) +(tz) +.tp +.b %l +the hour (12-hour clock) as a decimal number (range 1 to 12); +single digits are preceded by a blank. +(see also +.br %i .) +(calculated from +.ir tm_hour .) +(tz) +.tp +.b %m +the month as a decimal number (range 01 to 12). +(calculated from +.ir tm_mon .) +.tp +.b %m +the minute as a decimal number (range 00 to 59). +(calculated from +.ir tm_min .) +.tp +.b %n +a newline character. (su) +.tp +.b %o +modifier: use alternative numeric symbols, see below. (su) +.tp +.b %p +either "am" or "pm" according to the given time value, or the +corresponding strings for the current locale. +noon is treated as "pm" and midnight as "am". +(calculated from +.ir tm_hour .) +(the specific string representations used for "am" and "pm" +in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.br am_str " and " pm_str , +respectively.) +.tp +.b %p +like +.b %p +but in lowercase: "am" or "pm" or a corresponding +string for the current locale. +(calculated from +.ir tm_hour .) +(gnu) +.tp +.b %r +the time in a.m. or p.m. notation. +(su) +(the specific format used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.b t_fmt_ampm +as an argument.) +(in the posix locale this is equivalent to +.br "%i:%m:%s %p" .) +.tp +.b %r +the time in 24-hour notation +.rb ( %h:%m ). +(su) +for a version including the seconds, see +.b %t +below. +.tp +.b %s +the number of seconds since the epoch, 1970-01-01 00:00:00 +0000 (utc). (tz) +(calculated from +.ir mktime(tm) .) +.tp +.b %s +the second as a decimal number (range 00 to 60). +(the range is up to 60 to allow for occasional leap seconds.) +(calculated from +.ir tm_sec .) +.tp +.b %t +a tab character. (su) +.tp +.b %t +the time in 24-hour notation +.rb ( %h:%m:%s ). +(su) +.tp +.b %u +the day of the week as a decimal, range 1 to 7, monday being 1. +see also +.br %w . +(calculated from +.ir tm_wday .) +(su) +.tp +.b %u +the week number of the current year as a decimal number, +range 00 to 53, starting with the first sunday as the first day +of week 01. +see also +.b %v +and +.br %w . +(calculated from +.ir tm_yday +and +.ir tm_wday .) +.tp +.b %v +the iso\ 8601 week number (see notes) of the current year as a decimal number, +range 01 to 53, where week 1 is the first week that has at least +4 days in the new year. +see also +.b %u +and +.br %w . +(calculated from +.ir tm_year , +.ir tm_yday , +and +.ir tm_wday .) +(su) +.tp +.b %w +the day of the week as a decimal, range 0 to 6, sunday being 0. +see also +.br %u . +(calculated from +.ir tm_wday .) +.tp +.b %w +the week number of the current year as a decimal number, +range 00 to 53, starting with the first monday as the first day of week 01. +(calculated from +.ir tm_yday +and +.ir tm_wday .) +.tp +.b %x +the preferred date representation for the current locale without the time. +(the specific format used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.b d_fmt +as an argument for the +.b %x +conversion specification, and with +.b era_d_fmt +for the +.b %ex +conversion specification.) +(in the posix locale this is equivalent to +.br %m/%d/%y .) +.tp +.b %x +the preferred time representation for the current locale without the date. +(the specific format used in the current locale can be obtained by calling +.br nl_langinfo (3) +with +.b t_fmt +as an argument for the +.b %x +conversion specification, and with +.b era_t_fmt +for the +.b %ex +conversion specification.) +(in the posix locale this is equivalent to +.br %h:%m:%s .) +.tp +.b %y +the year as a decimal number without a century (range 00 to 99). +(the +.b %ey +conversion specification corresponds to the year since the beginning of the era +denoted by the +.b %ec +conversion specification.) +(calculated from +.ir tm_year ) +.tp +.b %y +the year as a decimal number including the century. +(the +.b %ey +conversion specification corresponds to the full alternative year representation.) +(calculated from +.ir tm_year ) +.tp +.b %z +the +.i +hhmm +or +.i \-hhmm +numeric timezone (that is, the hour and minute offset from utc). (su) +.tp +.b %z +the timezone name or abbreviation. +.tp +.b %+ +.\" nov 05 -- not in linux/glibc, but is in some bsds (according to +.\" their man pages) +the date and time in +.br date (1) +format. (tz) +(not supported in glibc2.) +.tp +.b %% +a literal \(aq%\(aq character. +.pp +some conversion specifications can be modified by preceding the +conversion specifier character by the +.b e +or +.b o +.i modifier +to indicate that an alternative format should be used. +if the alternative format or specification does not exist for +the current locale, the behavior will be as if the unmodified +conversion specification were used. (su) +the single unix specification mentions +.br %ec , +.br %ec , +.br %ex , +.br %ex , +.br %ey , +.br %ey , +.br %od , +.br %oe , +.br %oh , +.br %oi , +.br %om , +.br %om , +.br %os , +.br %ou , +.br %ou , +.br %ov , +.br %ow , +.br %ow , +.br %oy , +where the effect of the +.b o +modifier is to use +alternative numeric symbols (say, roman numerals), and that of the +.b e +modifier is to use a locale-dependent alternative representation. +the rules governing date representation with the +.b e +modifier can be obtained by supplying +.b era +as an argument to a +.br nl_langinfo (3). +one example of such alternative forms is the japanese era calendar scheme in the +.b ja_jp +glibc locale. +.sh return value +provided that the result string, +including the terminating null byte, does not exceed +.i max +bytes, +.br strftime () +returns the number of bytes (excluding the terminating null byte) +placed in the array +.ir s . +if the length of the result string (including the terminating null byte) +would exceed +.i max +bytes, then +.br strftime () +returns 0, and the contents of the array are undefined. +.\" (this behavior applies since at least libc 4.4.4; +.\" very old versions of libc, such as libc 4.4.1, +.\" would return +.\" .i max +.\" if the array was too small.) +.pp +note that the return value 0 does not necessarily indicate an error. +for example, in many locales +.b %p +yields an empty string. +an empty +.i format +string will likewise yield an empty string. +.sh environment +the environment variables +.b tz +and +.b lc_time +are used. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br strftime () +t} thread safety mt-safe env locale +.te +.hy +.ad +.sp 1 +.sh conforming to +svr4, c89, c99. +.\" fixme strftime() is in posix.1-2001 and posix.1-2008, but the details +.\" in the standards changed across versions. investigate and +.\" write up. +there are strict inclusions between the set of conversions +given in ansi c (unmarked), those given in the single unix specification +(marked su), those given in olson's timezone package (marked tz), +and those given in glibc (marked gnu), except that +.b %+ +is not supported in glibc2. +on the other hand glibc2 has several more extensions. +posix.1 only refers to ansi c; posix.2 describes under +.br date (1) +several extensions that could apply to +.br strftime () +as well. +the +.b %f +conversion is in c99 and posix.1-2001. +.pp +in susv2, the +.b %s +specifier allowed a range of 00 to 61, +to allow for the theoretical possibility of a minute that +included a double leap second +(there never has been such a minute). +.sh notes +.ss iso 8601 week dates +.br %g , +.br %g , +and +.br %v +yield values calculated from the week-based year defined by the +iso\ 8601 standard. +in this system, weeks start on a monday, and are numbered from 01, +for the first week, up to 52 or 53, for the last week. +week 1 is the first week where four or more days fall within the +new year (or, synonymously, week 01 is: +the first week of the year that contains a thursday; +or, the week that has 4 january in it). +when three or fewer days of the first calendar week of the new year fall +within that year, +then the iso 8601 week-based system counts those days as part of week 52 +or 53 of the preceding year. +for example, 1 january 2010 is a friday, +meaning that just three days of that calendar week fall in 2010. +thus, the iso\ 8601 week-based system considers these days to be part of +week 53 +.rb ( %v ) +of the year 2009 +.rb ( %g ); +week 01 of iso\ 8601 year 2010 starts on monday, 4 january 2010. +similarly, the first two days of january 2011 are considered to be part +of week 52 of the year 2010. +.ss glibc notes +glibc provides some extensions for conversion specifications. +(these extensions are not specified in posix.1-2001, but a few other +systems provide similar features.) +.\" hp-ux and tru64 also have features like this. +between the \(aq%\(aq character and the conversion specifier character, +an optional +.i flag +and field +.i width +may be specified. +(these precede the +.b e +or +.b o +modifiers, if present.) +.pp +the following flag characters are permitted: +.tp +.b _ +(underscore) +pad a numeric result string with spaces. +.tp +.b \- +(dash) +do not pad a numeric result string. +.tp +.b 0 +pad a numeric result string with zeros even if the conversion +specifier character uses space-padding by default. +.tp +.b \(ha +convert alphabetic characters in result string to uppercase. +.tp +.b # +swap the case of the result string. +(this flag works only with certain conversion specifier characters, +and of these, it is only really useful with +.br %z .) +.pp +an optional decimal width specifier may follow the (possibly absent) flag. +if the natural size of the field is smaller than this width, +then the result string is padded (on the left) to the specified width. +.sh bugs +if the output string would exceed +.i max +bytes, +.i errno +is +.i not +set. +this makes it impossible to distinguish this error case from cases where the +.i format +string legitimately produces a zero-length output string. +posix.1-2001 +does +.i not +specify any +.i errno +settings for +.br strftime (). +.pp +some buggy versions of +.br gcc (1) +complain about the use of +.br %c : +.ir "warning: \`%c\(aq yields only last 2 digits of year in some locales" . +of course programmers are encouraged to use +.br %c , +as it gives the preferred date and time representation. +one meets all kinds of strange obfuscations +to circumvent this +.br gcc (1) +problem. +a relatively clean one is to add an +intermediate function +.pp +.in +4n +.ex +size_t +my_strftime(char *s, size_t max, const char *fmt, + const struct tm *tm) +{ + return strftime(s, max, fmt, tm); +} +.ee +.in +.pp +nowadays, +.br gcc (1) +provides the +.ir \-wno\-format\-y2k +option to prevent the warning, +so that the above workaround is no longer required. +.sh examples +.br "rfc\ 2822-compliant date format" +(with an english locale for %a and %b) +.pp +.in +4n +.ex +"%a,\ %d\ %b\ %y\ %t\ %z" +.ee +.in +.pp +.br "rfc\ 822-compliant date format" +(with an english locale for %a and %b) +.pp +.in +4n +.ex +"%a,\ %d\ %b\ %y\ %t\ %z" +.ee +.in +.ss example program +the program below can be used to experiment with +.br strftime (). +.pp +some examples of the result string produced by the glibc implementation of +.br strftime () +are as follows: +.pp +.in +4n +.ex +.rb "$" " ./a.out \(aq%m\(aq" +result string is "11" +.rb "$" " ./a.out \(aq%5m\(aq" +result string is "00011" +.rb "$" " ./a.out \(aq%_5m\(aq" +result string is " 11" +.ee +.in +.ss program source +\& +.ex +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + char outstr[200]; + time_t t; + struct tm *tmp; + + t = time(null); + tmp = localtime(&t); + if (tmp == null) { + perror("localtime"); + exit(exit_failure); + } + + if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) { + fprintf(stderr, "strftime returned 0"); + exit(exit_failure); + } + + printf("result string is \e"%s\e"\en", outstr); + exit(exit_success); +} +.ee +.sh see also +.br date (1), +.br time (2), +.br ctime (3), +.br nl_langinfo (3), +.br setlocale (3), +.br sprintf (3), +.br strptime (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/xdr.3 + +.so man3/mq_open.3 +.\" because mq_open(3) is layered on a system call of the same name + +.so man3/hsearch.3 + +.\" copyright (c) 2012 by michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th malloc_trim 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +malloc_trim \- release free memory from the heap +.sh synopsis +.nf +.b #include +.pp +.bi "int malloc_trim(size_t " pad ); +.fi +.sh description +the +.br malloc_trim () +function attempts to release free memory from the heap +(by calling +.br sbrk (2) +or +.br madvise (2) +with suitable arguments). +.pp +the +.i pad +argument specifies the amount of free space to leave untrimmed +at the top of the heap. +if this argument is 0, only the minimum amount of memory is maintained +at the top of the heap (i.e., one page or less). +a nonzero argument can be used to maintain some trailing space +at the top of the heap in order to allow future allocations +to be made without having to extend the heap with +.br sbrk (2). +.sh return value +the +.br malloc_trim () +function returns 1 if memory was actually released back to the system, +or 0 if it was not possible to release any memory. +.sh errors +no errors are defined. +.\" .sh versions +.\" available already in glibc 2.0, possibly earlier +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br malloc_trim () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +this function is a gnu extension. +.sh notes +only the main heap (using +.br sbrk (2)) +honors the +.i pad +argument; thread heaps do not. +.pp +since glibc 2.8 this function frees memory in all arenas and in all +chunks with whole free pages. +.\" see commit 68631c8eb92ff38d9da1ae34f6aa048539b199cc +.\" (dated 2007-12-16) which adds iteration over all +.\" arenas and frees all pages in chunks which are free. +.pp +before glibc 2.8 this function only freed memory at the +top of the heap in the main arena. +.sh see also +.br sbrk (2), +.br malloc (3), +.br mallopt (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/gethostbyname.3 + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th iswblank 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +iswblank \- test for whitespace wide character +.sh synopsis +.nf +.b #include +.pp +.bi "int iswblank(wint_t " wc ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br iswblank (): +.nf + _isoc99_source || _posix_c_source >= 200112l +.fi +.sh description +the +.br iswblank () +function is the wide-character equivalent of the +.br isblank (3) +function. +it tests whether \fiwc\fp is a wide character +belonging to the wide-character class "blank". +.pp +the wide-character class "blank" is a subclass of the wide-character class +"space". +.pp +being a subclass of the wide-character class "space", +the wide-character class "blank" is disjoint from the +wide-character class "graph" and therefore also disjoint +from its subclasses "alnum", "alpha", "upper", "lower", "digit", +"xdigit", "punct". +.pp +the wide-character class "blank" always contains +at least the space character +and the control character \(aq\et\(aq. +.sh return value +the +.br iswblank () +function returns nonzero +if \fiwc\fp is a wide character +belonging to the wide-character class "blank". +otherwise, it returns zero. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br iswblank () +t} thread safety mt-safe locale +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +the behavior of +.br iswblank () +depends on the +.b lc_ctype +category of the +current locale. +.sh see also +.br isblank (3), +.br iswctype (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/strfmon.3 + +.so man3/tailq.3 + +.\" copyright (c) 2001 andries brouwer . +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th setlogmask 3 2021-03-22 "" "linux programmer's manual" +.sh name +setlogmask \- set log priority mask +.sh synopsis +.nf +.b #include +.pp +.bi "int setlogmask(int " mask ); +.fi +.sh description +a process has a log priority mask that determines which calls to +.br syslog (3) +may be logged. +all other calls will be ignored. +logging is enabled for the priorities that have the corresponding +bit set in +.ir mask . +the initial mask is such that logging is enabled for all priorities. +.pp +the +.br setlogmask () +function sets this logmask for the calling process, +and returns the previous mask. +if the mask argument is 0, the current logmask is not modified. +.pp +the eight priorities are +.br log_emerg , +.br log_alert , +.br log_crit , +.br log_err , +.br log_warning , +.br log_notice , +.br log_info , +and +.br log_debug . +the bit corresponding to a priority +.i p +is +.ir log_mask(p) . +some systems also provide a macro +.ir log_upto(p) +for the mask +of all priorities in the above list up to and including +.ir p . +.sh return value +this function returns the previous log priority mask. +.sh errors +none. +.\" .sh notes +.\" the glibc logmask handling was broken in versions before glibc 2.1.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br setlogmask () +t} thread safety mt-unsafe race:logmask +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.\" note that the description in posix.1-2001 is flawed. +.pp +.br log_upto () +will be included in the next release of the posix specification (issue 8). +.\" fixme . https://www.austingroupbugs.net/view.php?id=1033 +.sh see also +.br closelog (3), +.br openlog (3), +.br syslog (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getgrnam.3 + +.\" copyright (c) 2007 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th euidaccess 3 2021-03-22 "" "linux programmer's manual" +.sh name +euidaccess, eaccess \- check effective user's permissions for a file +.sh synopsis +.nf +.br "#define _gnu_source" " /* see feature_test_macros(7) */" +.b #include +.pp +.bi "int euidaccess(const char *" pathname ", int " mode ); +.bi "int eaccess(const char *" pathname ", int " mode ); +.fi +.sh description +like +.br access (2), +.br euidaccess () +checks permissions and existence of the file identified by its argument +.ir pathname . +however, whereas +.br access (2) +performs checks using the real user and group identifiers of the process, +.br euidaccess () +uses the effective identifiers. +.pp +.i mode +is a mask consisting of one or more of +.br r_ok ", " w_ok ", " x_ok ", and " f_ok , +with the same meanings as for +.br access (2). +.pp +.br eaccess () +is a synonym for +.br euidaccess (), +provided for compatibility with some other systems. +.sh return value +on success (all requested permissions granted), zero is returned. +on error (at least one bit in +.i mode +asked for a permission that is denied, or some other error occurred), +\-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +as for +.br access (2). +.sh versions +the +.br eaccess () +function was added to glibc in version 2.4. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br euidaccess (), +.br eaccess () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +these functions are nonstandard. +some other systems have an +.\" e.g., freebsd 6.1. +.br eaccess () +function. +.sh notes +.ir warning : +using this function to check a process's permissions on a file before +performing some operation based on that information leads to race conditions: +the file permissions may change between the two steps. +generally, it is safer just to attempt the desired operation and handle +any permission error that occurs. +.pp +this function always dereferences symbolic links. +if you need to check the permissions on a symbolic link, use +.br faccessat (2) +with the flags +.br at_eaccess +and +.br at_symlink_nofollow . +.sh see also +.br access (2), +.br chmod (2), +.br chown (2), +.br faccessat (2), +.br open (2), +.br setgid (2), +.br setuid (2), +.br stat (2), +.br credentials (7), +.br path_resolution (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/asin.3 + +.so man3/stailq.3 + +.so man2/swapon.2 + +.so man2/getresuid.2 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified 1993-07-24 by rik faith +.\" modified 2004-10-10 by aeb +.\" +.th initgroups 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +initgroups \- initialize the supplementary group access list +.sh synopsis +.nf +.b #include +.b #include +.pp +.bi "int initgroups(const char *" user ", gid_t " group ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br initgroups (): +.nf + since glibc 2.19: + _default_source + glibc 2.19 and earlier: + _bsd_source +.fi +.sh description +the +.br initgroups () +function initializes the group access list by +reading the group database +.i /etc/group +and using all groups of +which +.i user +is a member. +the additional group +.i group +is +also added to the list. +.pp +the +.i user +argument must be non-null. +.sh return value +the +.br initgroups () +function returns 0 on success. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b enomem +insufficient memory to allocate group information structure. +.tp +.b eperm +the calling process has insufficient privilege. +see the underlying system call +.br setgroups (2). +.sh files +.tp +.i /etc/group +group database file +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br initgroups () +t} thread safety mt-safe locale +.te +.hy +.ad +.sp 1 +.sh conforming to +svr4, 4.3bsd. +.sh see also +.br getgroups (2), +.br setgroups (2), +.br credentials (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1995 andries brouwer (aeb@cwi.nl) +.\" written 10 june 1995 by andries brouwer +.\" and copyright (c) 2007, 2015, 2020, michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified thu oct 31 15:16:23 1996 by eric s. raymond +.\" +.th llseek 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +_llseek \- reposition read/write file offset +.sh synopsis +.nf +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "int syscall(sys__llseek, unsigned int " fd ", unsigned long " offset_high , +.bi " unsigned long " offset_low ", loff_t *" result , +.bi " unsigned int " whence ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br _llseek (), +necessitating the use of +.br syscall (2). +.sh description +note: for information about the +.br llseek (3) +library function, see +.br lseek64 (3). +.pp +the +.br _llseek () +system call repositions the offset of the open file description associated +with the file descriptor +.i fd +to the value +.ip +(offset_high << 32) | offset_low +.pp +this new offset is a byte offset +relative to the beginning of the file, the current file offset, +or the end of the file, depending on whether +.i whence +is +.br seek_set , +.br seek_cur , +or +.br seek_end , +respectively. +.pp +the new file offset is returned in the argument +.ir result . +the type +.i loff_t +is a 64-bit signed type. +.pp +this system call exists on various 32-bit platforms to support +seeking to large file offsets. +.sh return value +upon successful completion, +.br _llseek () +returns 0. +otherwise, a value of \-1 is returned and +.i errno +is set to indicate the error. +.sh errors +.tp +.b ebadf +.i fd +is not an open file descriptor. +.tp +.b efault +problem with copying results to user space. +.tp +.b einval +.i whence +is invalid. +.sh conforming to +this function is linux-specific, and should not be used in programs +intended to be portable. +.sh notes +you probably want to use the +.br lseek (2) +wrapper function instead. +.sh see also +.br lseek (2), +.br open (2), +.br lseek64 (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getutent.3 + +.so man3/getline.3 + +.\" copyright (c) 2014 michael kerrisk +.\" and copyright (c) 2014 peter zijlstra +.\" and copyright (c) 2014 juri lelli +.\" various pieces from the old sched_setscheduler(2) page +.\" copyright (c) tom bjorkholm, markus kuhn & david a. wheeler 1996-1999 +.\" and copyright (c) 2007 carsten emde +.\" and copyright (c) 2008 michael kerrisk +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.\" worth looking at: http://rt.wiki.kernel.org/index.php +.\" +.th sched 7 2021-03-22 "linux" "linux programmer's manual" +.sh name +sched \- overview of cpu scheduling +.sh description +since linux 2.6.23, the default scheduler is cfs, +the "completely fair scheduler". +the cfs scheduler replaced the earlier "o(1)" scheduler. +.\" +.ss api summary +linux provides the following system calls for controlling +the cpu scheduling behavior, policy, and priority of processes +(or, more precisely, threads). +.tp +.br nice (2) +set a new nice value for the calling thread, +and return the new nice value. +.tp +.br getpriority (2) +return the nice value of a thread, a process group, +or the set of threads owned by a specified user. +.tp +.br setpriority (2) +set the nice value of a thread, a process group, +or the set of threads owned by a specified user. +.tp +.br sched_setscheduler (2) +set the scheduling policy and parameters of a specified thread. +.tp +.br sched_getscheduler (2) +return the scheduling policy of a specified thread. +.tp +.br sched_setparam (2) +set the scheduling parameters of a specified thread. +.tp +.br sched_getparam (2) +fetch the scheduling parameters of a specified thread. +.tp +.br sched_get_priority_max (2) +return the maximum priority available in a specified scheduling policy. +.tp +.br sched_get_priority_min (2) +return the minimum priority available in a specified scheduling policy. +.tp +.br sched_rr_get_interval (2) +fetch the quantum used for threads that are scheduled under +the "round-robin" scheduling policy. +.tp +.br sched_yield (2) +cause the caller to relinquish the cpu, +so that some other thread be executed. +.tp +.br sched_setaffinity (2) +(linux-specific) +set the cpu affinity of a specified thread. +.tp +.br sched_getaffinity (2) +(linux-specific) +get the cpu affinity of a specified thread. +.tp +.br sched_setattr (2) +set the scheduling policy and parameters of a specified thread. +this (linux-specific) system call provides a superset of the functionality of +.br sched_setscheduler (2) +and +.br sched_setparam (2). +.tp +.br sched_getattr (2) +fetch the scheduling policy and parameters of a specified thread. +this (linux-specific) system call provides a superset of the functionality of +.br sched_getscheduler (2) +and +.br sched_getparam (2). +.\" +.ss scheduling policies +the scheduler is the kernel component that decides which runnable thread +will be executed by the cpu next. +each thread has an associated scheduling policy and a \fistatic\fp +scheduling priority, +.ir sched_priority . +the scheduler makes its decisions based on knowledge of the scheduling +policy and static priority of all threads on the system. +.pp +for threads scheduled under one of the normal scheduling policies +(\fbsched_other\fp, \fbsched_idle\fp, \fbsched_batch\fp), +\fisched_priority\fp is not used in scheduling +decisions (it must be specified as 0). +.pp +processes scheduled under one of the real-time policies +(\fbsched_fifo\fp, \fbsched_rr\fp) have a +\fisched_priority\fp value in the range 1 (low) to 99 (high). +(as the numbers imply, real-time threads always have higher priority +than normal threads.) +note well: posix.1 requires an implementation to support only a +minimum 32 distinct priority levels for the real-time policies, +and some systems supply just this minimum. +portable programs should use +.br sched_get_priority_min (2) +and +.br sched_get_priority_max (2) +to find the range of priorities supported for a particular policy. +.pp +conceptually, the scheduler maintains a list of runnable +threads for each possible \fisched_priority\fp value. +in order to determine which thread runs next, the scheduler looks for +the nonempty list with the highest static priority and selects the +thread at the head of this list. +.pp +a thread's scheduling policy determines +where it will be inserted into the list of threads +with equal static priority and how it will move inside this list. +.pp +all scheduling is preemptive: if a thread with a higher static +priority becomes ready to run, the currently running thread +will be preempted and +returned to the wait list for its static priority level. +the scheduling policy determines the +ordering only within the list of runnable threads with equal static +priority. +.ss sched_fifo: first in-first out scheduling +\fbsched_fifo\fp can be used only with static priorities higher than +0, which means that when a \fbsched_fifo\fp thread becomes runnable, +it will always immediately preempt any currently running +\fbsched_other\fp, \fbsched_batch\fp, or \fbsched_idle\fp thread. +\fbsched_fifo\fp is a simple scheduling +algorithm without time slicing. +for threads scheduled under the +\fbsched_fifo\fp policy, the following rules apply: +.ip 1) 3 +a running \fbsched_fifo\fp thread that has been preempted by another thread of +higher priority will stay at the head of the list for its priority and +will resume execution as soon as all threads of higher priority are +blocked again. +.ip 2) +when a blocked \fbsched_fifo\fp thread becomes runnable, it +will be inserted at the end of the list for its priority. +.ip 3) +if a call to +.br sched_setscheduler (2), +.br sched_setparam (2), +.br sched_setattr (2), +.br pthread_setschedparam (3), +or +.br pthread_setschedprio (3) +changes the priority of the running or runnable +.b sched_fifo +thread identified by +.i pid +the effect on the thread's position in the list depends on +the direction of the change to threads priority: +.rs +.ip \(bu 3 +if the thread's priority is raised, +it is placed at the end of the list for its new priority. +as a consequence, +it may preempt a currently running thread with the same priority. +.ip \(bu +if the thread's priority is unchanged, +its position in the run list is unchanged. +.ip \(bu +if the thread's priority is lowered, +it is placed at the front of the list for its new priority. +.re +.ip +according to posix.1-2008, +changes to a thread's priority (or policy) using any mechanism other than +.br pthread_setschedprio (3) +should result in the thread being placed at the end of +the list for its priority. +.\" in 2.2.x and 2.4.x, the thread is placed at the front of the queue +.\" in 2.0.x, the right thing happened: the thread went to the back -- mtk +.ip 4) +a thread calling +.br sched_yield (2) +will be put at the end of the list. +.pp +no other events will move a thread +scheduled under the \fbsched_fifo\fp policy in the wait list of +runnable threads with equal static priority. +.pp +a \fbsched_fifo\fp +thread runs until either it is blocked by an i/o request, it is +preempted by a higher priority thread, or it calls +.br sched_yield (2). +.ss sched_rr: round-robin scheduling +\fbsched_rr\fp is a simple enhancement of \fbsched_fifo\fp. +everything +described above for \fbsched_fifo\fp also applies to \fbsched_rr\fp, +except that each thread is allowed to run only for a maximum time +quantum. +if a \fbsched_rr\fp thread has been running for a time +period equal to or longer than the time quantum, it will be put at the +end of the list for its priority. +a \fbsched_rr\fp thread that has +been preempted by a higher priority thread and subsequently resumes +execution as a running thread will complete the unexpired portion of +its round-robin time quantum. +the length of the time quantum can be +retrieved using +.br sched_rr_get_interval (2). +.\" on linux 2.4, the length of the rr interval is influenced +.\" by the process nice value -- mtk +.\" +.ss sched_deadline: sporadic task model deadline scheduling +since version 3.14, linux provides a deadline scheduling policy +.rb ( sched_deadline ). +this policy is currently implemented using +gedf (global earliest deadline first) +in conjunction with cbs (constant bandwidth server). +to set and fetch this policy and associated attributes, +one must use the linux-specific +.br sched_setattr (2) +and +.br sched_getattr (2) +system calls. +.pp +a sporadic task is one that has a sequence of jobs, where each +job is activated at most once per period. +each job also has a +.ir "relative deadline" , +before which it should finish execution, and a +.ir "computation time" , +which is the cpu time necessary for executing the job. +the moment when a task wakes up +because a new job has to be executed is called the +.ir "arrival time" +(also referred to as the request time or release time). +the +.ir "start time" +is the time at which a task starts its execution. +the +.i "absolute deadline" +is thus obtained by adding the relative deadline to the arrival time. +.pp +the following diagram clarifies these terms: +.pp +.in +4n +.ex +arrival/wakeup absolute deadline + | start time | + | | | + v v v +-----x--------xooooooooooooooooo--------x--------x--- + |<- comp. time ->| + |<------- relative deadline ------>| + |<-------------- period ------------------->| +.ee +.in +.pp +when setting a +.b sched_deadline +policy for a thread using +.br sched_setattr (2), +one can specify three parameters: +.ir runtime , +.ir deadline , +and +.ir period . +these parameters do not necessarily correspond to the aforementioned terms: +usual practice is to set runtime to something bigger than the average +computation time (or worst-case execution time for hard real-time tasks), +deadline to the relative deadline, and period to the period of the task. +thus, for +.br sched_deadline +scheduling, we have: +.pp +.in +4n +.ex +arrival/wakeup absolute deadline + | start time | + | | | + v v v +-----x--------xooooooooooooooooo--------x--------x--- + |<-- runtime ------->| + |<----------- deadline ----------->| + |<-------------- period ------------------->| +.ee +.in +.pp +the three deadline-scheduling parameters correspond to the +.ir sched_runtime , +.ir sched_deadline , +and +.ir sched_period +fields of the +.i sched_attr +structure; see +.br sched_setattr (2). +these fields express values in nanoseconds. +.\" fixme it looks as though specifying sched_period as 0 means +.\" "make sched_period the same as sched_deadline". +.\" this needs to be documented. +if +.ir sched_period +is specified as 0, then it is made the same as +.ir sched_deadline . +.pp +the kernel requires that: +.pp + sched_runtime <= sched_deadline <= sched_period +.pp +.\" see __checkparam_dl in kernel/sched/core.c +in addition, under the current implementation, +all of the parameter values must be at least 1024 +(i.e., just over one microsecond, +which is the resolution of the implementation), and less than 2^63. +if any of these checks fails, +.br sched_setattr (2) +fails with the error +.br einval . +.pp +the cbs guarantees non-interference between tasks, by throttling +threads that attempt to over-run their specified runtime. +.pp +to ensure deadline scheduling guarantees, +the kernel must prevent situations where the set of +.b sched_deadline +threads is not feasible (schedulable) within the given constraints. +the kernel thus performs an admittance test when setting or changing +.b sched_deadline +policy and attributes. +this admission test calculates whether the change is feasible; +if it is not, +.br sched_setattr (2) +fails with the error +.br ebusy . +.pp +for example, it is required (but not necessarily sufficient) for +the total utilization to be less than or equal to the total number of +cpus available, where, since each thread can maximally run for +runtime per period, that thread's utilization is its +runtime divided by its period. +.pp +in order to fulfill the guarantees that are made when +a thread is admitted to the +.br sched_deadline +policy, +.br sched_deadline +threads are the highest priority (user controllable) threads in the +system; if any +.br sched_deadline +thread is runnable, +it will preempt any thread scheduled under one of the other policies. +.pp +a call to +.br fork (2) +by a thread scheduled under the +.b sched_deadline +policy fails with the error +.br eagain , +unless the thread has its reset-on-fork flag set (see below). +.pp +a +.b sched_deadline +thread that calls +.br sched_yield (2) +will yield the current job and wait for a new period to begin. +.\" +.\" fixme calling sched_getparam() on a sched_deadline thread +.\" fails with einval, but sched_getscheduler() succeeds. +.\" is that intended? (why?) +.\" +.ss sched_other: default linux time-sharing scheduling +\fbsched_other\fp can be used at only static priority 0 +(i.e., threads under real-time policies always have priority over +.b sched_other +processes). +\fbsched_other\fp is the standard linux time-sharing scheduler that is +intended for all threads that do not require the special +real-time mechanisms. +.pp +the thread to run is chosen from the static +priority 0 list based on a \fidynamic\fp priority that is determined only +inside this list. +the dynamic priority is based on the nice value (see below) +and is increased for each time quantum the thread is ready to run, +but denied to run by the scheduler. +this ensures fair progress among all \fbsched_other\fp threads. +.pp +in the linux kernel source code, the +.b sched_other +policy is actually named +.br sched_normal . +.\" +.ss the nice value +the nice value is an attribute +that can be used to influence the cpu scheduler to +favor or disfavor a process in scheduling decisions. +it affects the scheduling of +.br sched_other +and +.br sched_batch +(see below) processes. +the nice value can be modified using +.br nice (2), +.br setpriority (2), +or +.br sched_setattr (2). +.pp +according to posix.1, the nice value is a per-process attribute; +that is, the threads in a process should share a nice value. +however, on linux, the nice value is a per-thread attribute: +different threads in the same process may have different nice values. +.pp +the range of the nice value +varies across unix systems. +on modern linux, the range is \-20 (high priority) to +19 (low priority). +on some other systems, the range is \-20..20. +very early linux kernels (before linux 2.0) had the range \-infinity..15. +.\" linux before 1.3.36 had \-infinity..15. +.\" since kernel 1.3.43, linux has the range \-20..19. +.pp +the degree to which the nice value affects the relative scheduling of +.br sched_other +processes likewise varies across unix systems and +across linux kernel versions. +.pp +with the advent of the cfs scheduler in kernel 2.6.23, +linux adopted an algorithm that causes +relative differences in nice values to have a much stronger effect. +in the current implementation, each unit of difference in the +nice values of two processes results in a factor of 1.25 +in the degree to which the scheduler favors the higher priority process. +this causes very low nice values (+19) to truly provide little cpu +to a process whenever there is any other +higher priority load on the system, +and makes high nice values (\-20) deliver most of the cpu to applications +that require it (e.g., some audio applications). +.pp +on linux, the +.br rlimit_nice +resource limit can be used to define a limit to which +an unprivileged process's nice value can be raised; see +.br setrlimit (2) +for details. +.pp +for further details on the nice value, see the subsections on +the autogroup feature and group scheduling, below. +.\" +.ss sched_batch: scheduling batch processes +(since linux 2.6.16.) +\fbsched_batch\fp can be used only at static priority 0. +this policy is similar to \fbsched_other\fp in that it schedules +the thread according to its dynamic priority +(based on the nice value). +the difference is that this policy +will cause the scheduler to always assume +that the thread is cpu-intensive. +consequently, the scheduler will apply a small scheduling +penalty with respect to wakeup behavior, +so that this thread is mildly disfavored in scheduling decisions. +.pp +.\" the following paragraph is drawn largely from the text that +.\" accompanied ingo molnar's patch for the implementation of +.\" sched_batch. +.\" commit b0a9499c3dd50d333e2aedb7e894873c58da3785 +this policy is useful for workloads that are noninteractive, +but do not want to lower their nice value, +and for workloads that want a deterministic scheduling policy without +interactivity causing extra preemptions (between the workload's tasks). +.\" +.ss sched_idle: scheduling very low priority jobs +(since linux 2.6.23.) +\fbsched_idle\fp can be used only at static priority 0; +the process nice value has no influence for this policy. +.pp +this policy is intended for running jobs at extremely low +priority (lower even than a +19 nice value with the +.b sched_other +or +.b sched_batch +policies). +.\" +.ss resetting scheduling policy for child processes +each thread has a reset-on-fork scheduling flag. +when this flag is set, children created by +.br fork (2) +do not inherit privileged scheduling policies. +the reset-on-fork flag can be set by either: +.ip * 3 +oring the +.b sched_reset_on_fork +flag into the +.i policy +argument when calling +.br sched_setscheduler (2) +(since linux 2.6.32); +or +.ip * +specifying the +.b sched_flag_reset_on_fork +flag in +.ir attr.sched_flags +when calling +.br sched_setattr (2). +.pp +note that the constants used with these two apis have different names. +the state of the reset-on-fork flag can analogously be retrieved using +.br sched_getscheduler (2) +and +.br sched_getattr (2). +.pp +the reset-on-fork feature is intended for media-playback applications, +and can be used to prevent applications evading the +.br rlimit_rttime +resource limit (see +.br getrlimit (2)) +by creating multiple child processes. +.pp +more precisely, if the reset-on-fork flag is set, +the following rules apply for subsequently created children: +.ip * 3 +if the calling thread has a scheduling policy of +.b sched_fifo +or +.br sched_rr , +the policy is reset to +.br sched_other +in child processes. +.ip * +if the calling process has a negative nice value, +the nice value is reset to zero in child processes. +.pp +after the reset-on-fork flag has been enabled, +it can be reset only if the thread has the +.br cap_sys_nice +capability. +this flag is disabled in child processes created by +.br fork (2). +.\" +.ss privileges and resource limits +in linux kernels before 2.6.12, only privileged +.rb ( cap_sys_nice ) +threads can set a nonzero static priority (i.e., set a real-time +scheduling policy). +the only change that an unprivileged thread can make is to set the +.b sched_other +policy, and this can be done only if the effective user id of the caller +matches the real or effective user id of the target thread +(i.e., the thread specified by +.ir pid ) +whose policy is being changed. +.pp +a thread must be privileged +.rb ( cap_sys_nice ) +in order to set or modify a +.br sched_deadline +policy. +.pp +since linux 2.6.12, the +.b rlimit_rtprio +resource limit defines a ceiling on an unprivileged thread's +static priority for the +.b sched_rr +and +.b sched_fifo +policies. +the rules for changing scheduling policy and priority are as follows: +.ip * 3 +if an unprivileged thread has a nonzero +.b rlimit_rtprio +soft limit, then it can change its scheduling policy and priority, +subject to the restriction that the priority cannot be set to a +value higher than the maximum of its current priority and its +.b rlimit_rtprio +soft limit. +.ip * +if the +.b rlimit_rtprio +soft limit is 0, then the only permitted changes are to lower the priority, +or to switch to a non-real-time policy. +.ip * +subject to the same rules, +another unprivileged thread can also make these changes, +as long as the effective user id of the thread making the change +matches the real or effective user id of the target thread. +.ip * +special rules apply for the +.br sched_idle +policy. +in linux kernels before 2.6.39, +an unprivileged thread operating under this policy cannot +change its policy, regardless of the value of its +.br rlimit_rtprio +resource limit. +in linux kernels since 2.6.39, +.\" commit c02aa73b1d18e43cfd79c2f193b225e84ca497c8 +an unprivileged thread can switch to either the +.br sched_batch +or the +.br sched_other +policy so long as its nice value falls within the range permitted by its +.br rlimit_nice +resource limit (see +.br getrlimit (2)). +.pp +privileged +.rb ( cap_sys_nice ) +threads ignore the +.b rlimit_rtprio +limit; as with older kernels, +they can make arbitrary changes to scheduling policy and priority. +see +.br getrlimit (2) +for further information on +.br rlimit_rtprio . +.ss limiting the cpu usage of real-time and deadline processes +a nonblocking infinite loop in a thread scheduled under the +.br sched_fifo , +.br sched_rr , +or +.br sched_deadline +policy can potentially block all other threads from accessing +the cpu forever. +prior to linux 2.6.25, the only way of preventing a runaway real-time +process from freezing the system was to run (at the console) +a shell scheduled under a higher static priority than the tested application. +this allows an emergency kill of tested +real-time applications that do not block or terminate as expected. +.pp +since linux 2.6.25, there are other techniques for dealing with runaway +real-time and deadline processes. +one of these is to use the +.br rlimit_rttime +resource limit to set a ceiling on the cpu time that +a real-time process may consume. +see +.br getrlimit (2) +for details. +.pp +since version 2.6.25, linux also provides two +.i /proc +files that can be used to reserve a certain amount of cpu time +to be used by non-real-time processes. +reserving cpu time in this fashion allows some cpu time to be +allocated to (say) a root shell that can be used to kill a runaway process. +both of these files specify time values in microseconds: +.tp +.ir /proc/sys/kernel/sched_rt_period_us +this file specifies a scheduling period that is equivalent to +100% cpu bandwidth. +the value in this file can range from 1 to +.br int_max , +giving an operating range of 1 microsecond to around 35 minutes. +the default value in this file is 1,000,000 (1 second). +.tp +.ir /proc/sys/kernel/sched_rt_runtime_us +the value in this file specifies how much of the "period" time +can be used by all real-time and deadline scheduled processes +on the system. +the value in this file can range from \-1 to +.br int_max \-1. +specifying \-1 makes the run time the same as the period; +that is, no cpu time is set aside for non-real-time processes +(which was the linux behavior before kernel 2.6.25). +the default value in this file is 950,000 (0.95 seconds), +meaning that 5% of the cpu time is reserved for processes that +don't run under a real-time or deadline scheduling policy. +.ss response time +a blocked high priority thread waiting for i/o has a certain +response time before it is scheduled again. +the device driver writer +can greatly reduce this response time by using a "slow interrupt" +interrupt handler. +.\" as described in +.\" .br request_irq (9). +.ss miscellaneous +child processes inherit the scheduling policy and parameters across a +.br fork (2). +the scheduling policy and parameters are preserved across +.br execve (2). +.pp +memory locking is usually needed for real-time processes to avoid +paging delays; this can be done with +.br mlock (2) +or +.br mlockall (2). +.\" +.ss the autogroup feature +.\" commit 5091faa449ee0b7d73bc296a93bca9540fc51d0a +since linux 2.6.38, +the kernel provides a feature known as autogrouping to improve interactive +desktop performance in the face of multiprocess, cpu-intensive +workloads such as building the linux kernel with large numbers of +parallel build processes (i.e., the +.br make (1) +.br \-j +flag). +.pp +this feature operates in conjunction with the +cfs scheduler and requires a kernel that is configured with +.br config_sched_autogroup . +on a running system, this feature is enabled or disabled via the file +.ir /proc/sys/kernel/sched_autogroup_enabled ; +a value of 0 disables the feature, while a value of 1 enables it. +the default value in this file is 1, unless the kernel was booted with the +.ir noautogroup +parameter. +.pp +a new autogroup is created when a new session is created via +.br setsid (2); +this happens, for example, when a new terminal window is started. +a new process created by +.br fork (2) +inherits its parent's autogroup membership. +thus, all of the processes in a session are members of the same autogroup. +an autogroup is automatically destroyed when the last process +in the group terminates. +.pp +when autogrouping is enabled, all of the members of an autogroup +are placed in the same kernel scheduler "task group". +the cfs scheduler employs an algorithm that equalizes the +distribution of cpu cycles across task groups. +the benefits of this for interactive desktop performance +can be described via the following example. +.pp +suppose that there are two autogroups competing for the same cpu +(i.e., presume either a single cpu system or the use of +.br taskset (1) +to confine all the processes to the same cpu on an smp system). +the first group contains ten cpu-bound processes from +a kernel build started with +.ir "make\ \-j10" . +the other contains a single cpu-bound process: a video player. +the effect of autogrouping is that the two groups will +each receive half of the cpu cycles. +that is, the video player will receive 50% of the cpu cycles, +rather than just 9% of the cycles, +which would likely lead to degraded video playback. +the situation on an smp system is more complex, +.\" mike galbraith, 25 nov 2016: +.\" i'd say something more wishy-washy here, like cycles are +.\" distributed fairly across groups and leave it at that, as your +.\" detailed example is incorrect due to smp fairness (which i don't +.\" like much because [very unlikely] worst case scenario +.\" renders a box sized group incapable of utilizing more that +.\" a single cpu total). for example, if a group of nr_cpus +.\" size competes with a singleton, load balancing will try to give +.\" the singleton a full cpu of its very own. if groups intersect for +.\" whatever reason on say my quad lappy, distribution is 80/20 in +.\" favor of the singleton. +but the general effect is the same: +the scheduler distributes cpu cycles across task groups such that +an autogroup that contains a large number of cpu-bound processes +does not end up hogging cpu cycles at the expense of the other +jobs on the system. +.pp +a process's autogroup (task group) membership can be viewed via the file +.ir /proc/[pid]/autogroup : +.pp +.in +4n +.ex +$ \fbcat /proc/1/autogroup\fp +/autogroup\-1 nice 0 +.ee +.in +.pp +this file can also be used to modify the cpu bandwidth allocated +to an autogroup. +this is done by writing a number in the "nice" range to the file +to set the autogroup's nice value. +the allowed range is from +19 (low priority) to \-20 (high priority). +(writing values outside of this range causes +.br write (2) +to fail with the error +.br einval .) +.\" fixme . +.\" because of a bug introduced in linux 4.7 +.\" (commit 2159197d66770ec01f75c93fb11dc66df81fd45b made changes +.\" that exposed the fact that autogroup didn't call scale_load()), +.\" it happened that *all* values in this range caused a task group +.\" to be further disfavored by the scheduler, with \-20 resulting +.\" in the scheduler mildly disfavoring the task group and +19 greatly +.\" disfavoring it. +.\" +.\" a patch was posted on 23 nov 2016 +.\" ("sched/autogroup: fix 64bit kernel nice adjustment"; +.\" check later to see in which kernel version it lands. +.pp +the autogroup nice setting has the same meaning as the process nice value, +but applies to distribution of cpu cycles to the autogroup as a whole, +based on the relative nice values of other autogroups. +for a process inside an autogroup, the cpu cycles that it receives +will be a product of the autogroup's nice value +(compared to other autogroups) +and the process's nice value +(compared to other processes in the same autogroup. +.pp +the use of the +.br cgroups (7) +cpu controller to place processes in cgroups other than the +root cpu cgroup overrides the effect of autogrouping. +.pp +the autogroup feature groups only processes scheduled under +non-real-time policies +.rb ( sched_other , +.br sched_batch , +and +.br sched_idle ). +it does not group processes scheduled under real-time and +deadline policies. +those processes are scheduled according to the rules described earlier. +.\" +.ss the nice value and group scheduling +when scheduling non-real-time processes (i.e., those scheduled under the +.br sched_other , +.br sched_batch , +and +.br sched_idle +policies), the cfs scheduler employs a technique known as "group scheduling", +if the kernel was configured with the +.br config_fair_group_sched +option (which is typical). +.pp +under group scheduling, threads are scheduled in "task groups". +task groups have a hierarchical relationship, +rooted under the initial task group on the system, +known as the "root task group". +task groups are formed in the following circumstances: +.ip * 3 +all of the threads in a cpu cgroup form a task group. +the parent of this task group is the task group of the +corresponding parent cgroup. +.ip * +if autogrouping is enabled, +then all of the threads that are (implicitly) placed in an autogroup +(i.e., the same session, as created by +.br setsid (2)) +form a task group. +each new autogroup is thus a separate task group. +the root task group is the parent of all such autogroups. +.ip * +if autogrouping is enabled, then the root task group consists of +all processes in the root cpu cgroup that were not +otherwise implicitly placed into a new autogroup. +.ip * +if autogrouping is disabled, then the root task group consists of +all processes in the root cpu cgroup. +.ip * +if group scheduling was disabled (i.e., the kernel was configured without +.br config_fair_group_sched ), +then all of the processes on the system are notionally placed +in a single task group. +.pp +under group scheduling, +a thread's nice value has an effect for scheduling decisions +.ir "only relative to other threads in the same task group" . +this has some surprising consequences in terms of the traditional semantics +of the nice value on unix systems. +in particular, if autogrouping +is enabled (which is the default in various distributions), then employing +.br setpriority (2) +or +.br nice (1) +on a process has an effect only for scheduling relative +to other processes executed in the same session +(typically: the same terminal window). +.pp +conversely, for two processes that are (for example) +the sole cpu-bound processes in different sessions +(e.g., different terminal windows, +each of whose jobs are tied to different autogroups), +.ir "modifying the nice value of the process in one of the sessions" +.ir "has no effect" +in terms of the scheduler's decisions relative to the +process in the other session. +.\" more succinctly: the nice(1) command is in many cases a no-op since +.\" linux 2.6.38. +.\" +a possibly useful workaround here is to use a command such as +the following to modify the autogroup nice value for +.i all +of the processes in a terminal session: +.pp +.in +4n +.ex +$ \fbecho 10 > /proc/self/autogroup\fp +.ee +.in +.ss real-time features in the mainline linux kernel +.\" fixme . probably this text will need some minor tweaking +.\" ask carsten emde about this. +since kernel version 2.6.18, linux is gradually +becoming equipped with real-time capabilities, +most of which are derived from the former +.i realtime\-preempt +patch set. +until the patches have been completely merged into the +mainline kernel, +they must be installed to achieve the best real-time performance. +these patches are named: +.pp +.in +4n +.ex +patch\-\fikernelversion\fp\-rt\fipatchversion\fp +.ee +.in +.pp +and can be downloaded from +.ur http://www.kernel.org\:/pub\:/linux\:/kernel\:/projects\:/rt/ +.ue . +.pp +without the patches and prior to their full inclusion into the mainline +kernel, the kernel configuration offers only the three preemption classes +.br config_preempt_none , +.br config_preempt_voluntary , +and +.b config_preempt_desktop +which respectively provide no, some, and considerable +reduction of the worst-case scheduling latency. +.pp +with the patches applied or after their full inclusion into the mainline +kernel, the additional configuration item +.b config_preempt_rt +becomes available. +if this is selected, linux is transformed into a regular +real-time operating system. +the fifo and rr scheduling policies are then used to run a thread +with true real-time priority and a minimum worst-case scheduling latency. +.sh notes +the +.br cgroups (7) +cpu controller can be used to limit the cpu consumption of +groups of processes. +.pp +originally, standard linux was intended as a general-purpose operating +system being able to handle background processes, interactive +applications, and less demanding real-time applications (applications that +need to usually meet timing deadlines). +although the linux kernel 2.6 +allowed for kernel preemption and the newly introduced o(1) scheduler +ensures that the time needed to schedule is fixed and deterministic +irrespective of the number of active tasks, true real-time computing +was not possible up to kernel version 2.6.17. +.sh see also +.ad l +.nh +.br chcpu (1), +.br chrt (1), +.br lscpu (1), +.br ps (1), +.br taskset (1), +.br top (1), +.br getpriority (2), +.br mlock (2), +.br mlockall (2), +.br munlock (2), +.br munlockall (2), +.br nice (2), +.br sched_get_priority_max (2), +.br sched_get_priority_min (2), +.br sched_getaffinity (2), +.br sched_getparam (2), +.br sched_getscheduler (2), +.br sched_rr_get_interval (2), +.br sched_setaffinity (2), +.br sched_setparam (2), +.br sched_setscheduler (2), +.br sched_yield (2), +.br setpriority (2), +.br pthread_getaffinity_np (3), +.br pthread_getschedparam (3), +.br pthread_setaffinity_np (3), +.br sched_getcpu (3), +.br capabilities (7), +.br cpuset (7) +.ad +.pp +.i programming for the real world \- posix.4 +by bill o.\& gallmeister, o'reilly & associates, inc., isbn 1-56592-074-0. +.pp +the linux kernel source files +.ir documentation/scheduler/sched\-deadline.txt , +.ir documentation/scheduler/sched\-rt\-group.txt , +.ir documentation/scheduler/sched\-design\-cfs.txt , +and +.ir documentation/scheduler/sched\-nice\-design.txt +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/floor.3 + +.so man3/ctime.3 + +.so man3/error.3 + +.\" copyright 1995 jim van zandt +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" changed `square root' into `cube root' - aeb, 950919 +.\" +.\" modified 2002-07-27 walter harms +.\" (walter.harms@informatik.uni-oldenburg.de) +.\" +.th cbrt 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +cbrt, cbrtf, cbrtl \- cube root function +.sh synopsis +.nf +.b #include +.pp +.bi "double cbrt(double " x ); +.bi "float cbrtf(float " x ); +.bi "long double cbrtl(long double " x ); +.fi +.pp +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br cbrt (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.pp +.br cbrtf (), +.br cbrtl (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +these functions return the (real) cube root of +.ir x . +this function cannot fail; every representable real value has a +representable real cube root. +.sh return value +these functions return the cube root of +.ir x . +.pp +if +.i x +is +0, \-0, positive infinity, negative infinity, or nan, +.i x +is returned. +.sh errors +no errors occur. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br cbrt (), +.br cbrtf (), +.br cbrtl () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +c99, posix.1-2001, posix.1-2008. +.\" .br cbrt () +.\" was a gnu extension. it is now a c99 requirement. +.sh see also +.br pow (3), +.br sqrt (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getopt.3 + +.so man3/xdr.3 + +.so man3/drand48_r.3 + +.so man3/fpclassify.3 + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification +.\" http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.\" modified tue oct 16 23:18:40 bst 2001 by john levon +.th fgetws 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +fgetws \- read a wide-character string from a file stream +.sh synopsis +.nf +.b #include +.pp +.bi "wchar_t *fgetws(wchar_t *restrict " ws ", int " n \ +", file *restrict " stream ); +.fi +.sh description +the +.br fgetws () +function is the wide-character equivalent +of the +.br fgets (3) +function. +it reads a string of at most \fin\-1\fp wide characters into the +wide-character array pointed to by \fiws\fp, +and adds a terminating null wide character (l\(aq\e0\(aq). +it stops reading wide characters after it has encountered and +stored a newline wide character. +it also stops when end of stream is reached. +.pp +the programmer must ensure that there is room for at least \fin\fp wide +characters at \fiws\fp. +.pp +for a nonlocking counterpart, see +.br unlocked_stdio (3). +.sh return value +the +.br fgetws () +function, if successful, returns \fiws\fp. +if end of stream +was already reached or if an error occurred, it returns null. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br fgetws () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh notes +the behavior of +.br fgetws () +depends on the +.b lc_ctype +category of the +current locale. +.pp +in the absence of additional information passed to the +.br fopen (3) +call, it is +reasonable to expect that +.br fgetws () +will actually read a multibyte string +from the stream and then convert it to a wide-character string. +.pp +this function is unreliable, +because it does not permit to deal properly with +null wide characters that may be present in the input. +.sh see also +.br fgetwc (3), +.br unlocked_stdio (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/gethostname.2 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sat jul 24 17:48:42 1993 by rik faith (faith@cs.unc.edu) +.th telldir 3 2021-03-22 "" "linux programmer's manual" +.sh name +telldir \- return current location in directory stream +.sh synopsis +.nf +.b #include +.pp +.bi "long telldir(dir *" dirp ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br telldir (): +.nf + _xopen_source + || /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +the +.br telldir () +function returns the current location associated with +the directory stream \fidirp\fp. +.sh return value +on success, the +.br telldir () +function returns the current location +in the directory stream. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b ebadf +invalid directory stream descriptor \fidirp\fp. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br telldir () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, 4.3bsd. +.sh notes +in glibc up to version 2.1.1, the return type of +.br telldir () +was +.ir off_t . +posix.1-2001 specifies +.ir long , +and this is the type used since glibc 2.1.2. +.pp +in early filesystems, the value returned by +.br telldir () +was a simple file offset within a directory. +modern filesystems use tree or hash structures, rather than flat tables, +to represent directories. +on such filesystems, the value returned by +.br telldir () +(and used internally by +.br readdir (3)) +is a "cookie" that is used by the implementation +to derive a position within a directory. +.\" https://lwn.net/articles/544298/ +application programs should treat this strictly as an opaque value, making +.i no +assumptions about its contents. +.sh see also +.br closedir (3), +.br opendir (3), +.br readdir (3), +.br rewinddir (3), +.br scandir (3), +.br seekdir (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/gamma.3 + +.so man3/cimag.3 + +.\" copyright (c) 2007 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" 2007-10-23 mtk, nearly a complete rewrite of the earlier page. +.th intro 3 2020-11-01 "linux" "linux programmer's manual" +.sh name +intro \- introduction to library functions +.sh description +section 3 of the manual describes all library functions excluding the library +functions (system call wrappers) described in section 2, +which implement system calls. +.pp +many of the functions described in the section are part of the +standard c library +.ri ( libc ). +some functions are part of other libraries (e.g., +the math library, +.ir libm , +or the real-time library, +.ir librt ) +in which case the manual page will indicate the linker +option needed to link against the required library +(e.g., +.i \-lm +and +.ir \-lrt , +respectively, +for the aforementioned libraries). +.pp +in some cases, +the programmer must define a feature test macro in order to obtain +the declaration of a function from the header file specified +in the man page synopsis section. +(where required, these feature test macros must be defined before including +.i any +header files.) +in such cases, the required macro is described in the man page. +for further information on feature test macros, see +.br feature_test_macros (7). +.\" +.\" there +.\" are various function groups which can be identified by a letter which +.\" is appended to the chapter number: +.\" .ip (3c) +.\" these functions, the functions from chapter 2 and from chapter 3s are +.\" contained in the c standard library libc, which will be used by +.\" .br cc (1) +.\" by default. +.\" .ip (3s) +.\" these functions are parts of the +.\" .br stdio (3) +.\" library. they are contained in the standard c library libc. +.\" .ip (3m) +.\" these functions are contained in the arithmetic library libm. they are +.\" used by the +.\" .br f77 (1) +.\" fortran compiler by default, but not by the +.\" .br cc (1) +.\" c compiler, which needs the option \fi\-lm\fp. +.\" .ip (3f) +.\" these functions are part of the fortran library libf77. there are no +.\" special compiler flags needed to use these functions. +.\" .ip (3x) +.\" various special libraries. the manual pages documenting their functions +.\" specify the library names. +.sh conforming to +certain terms and abbreviations are used to indicate unix variants +and standards to which calls in this section conform. +see +.br standards (7). +.sh notes +.ss authors and copyright conditions +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! +.sh see also +.br intro (2), +.br errno (3), +.br capabilities (7), +.br credentials (7), +.br environ (7), +.br feature_test_macros (7), +.br libc (7), +.br math_error (7), +.br path_resolution (7), +.br pthreads (7), +.br signal (7), +.br standards (7), +.br system_data_types (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/dladdr.3 + +.so man3/casinh.3 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" and copyright 2008, linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified 1993-07-24 by rik faith (faith@cs.unc.edu) +.\" modified 2002-07-27 by walter harms +.\" (walter.harms@informatik.uni-oldenburg.de) +.\" +.th tan 3 2021-03-22 "" "linux programmer's manual" +.sh name +tan, tanf, tanl \- tangent function +.sh synopsis +.nf +.b #include +.pp +.bi "double tan(double " x ); +.bi "float tanf(float " x ); +.bi "long double tanl(long double " x ); +.fi +.pp +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br tanf (), +.br tanl (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +these functions return the tangent of +.ir x , +where +.i x +is +given in radians. +.sh return value +on success, these functions return the tangent of +.ir x . +.pp +if +.i x +is a nan, a nan is returned. +.pp +if +.i x +is positive infinity or negative infinity, +a domain error occurs, +and a nan is returned. +.pp +if the correct result would overflow, +a range error occurs, +and the functions return +.br huge_val , +.br huge_valf , +or +.br huge_vall , +respectively, with the mathematically correct sign. +.\" i think overflow can't occur, because the closest floating-point +.\" representation of pi/2 is still not close enough to pi/2 to +.\" produce a large enough value to overflow. +.\" testing certainly seems to bear this out. -- mtk, jul 08 +.\" +.\" posix.1 allows an optional underflow error; +.\" glibc 2.8 doesn't do this +.\" posix.1 an optional range error for subnormal x; +.\" glibc 2.8 doesn't do this +.sh errors +see +.br math_error (7) +for information on how to determine whether an error has occurred +when calling these functions. +.pp +the following errors can occur: +.tp +domain error: \fix\fp is an infinity +.i errno +is set to +.b edom +(but see bugs). +an invalid floating-point exception +.rb ( fe_invalid ) +is raised. +.tp +range error: result overflow +.\" unable to test this case, since the best approximation of +.\" pi/2 in double precision only yields a tan() value of 1.633e16. +.\" .i errno +.\" is set to +.\" .br erange . +an overflow floating-point exception +.rb ( fe_overflow ) +is raised. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br tan (), +.br tanf (), +.br tanl () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +c99, posix.1-2001, posix.1-2008. +.pp +the variant returning +.i double +also conforms to +svr4, 4.3bsd, c89. +.sh bugs +before version 2.10, the glibc implementation did not set +.\" http://sourceware.org/bugzilla/show_bug.cgi?id=6782 +.i errno +to +.b edom +when a domain error occurred. +.sh see also +.br acos (3), +.br asin (3), +.br atan (3), +.br atan2 (3), +.br cos (3), +.br ctan (3), +.br sin (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/rpc.3 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sat jul 24 18:49:23 1993 by rik faith (faith@cs.unc.edu) +.th memset 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +memset \- fill memory with a constant byte +.sh synopsis +.nf +.b #include +.pp +.bi "void *memset(void *" s ", int " c ", size_t " n ); +.fi +.sh description +the +.br memset () +function fills the first +.i n +bytes of the +memory area pointed to by +.i s +with the constant byte +.ir c . +.sh return value +the +.br memset () +function returns a pointer to the memory area +.ir s . +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br memset () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c89, c99, svr4, 4.3bsd. +.sh see also +.br bstring (3), +.br bzero (3), +.br swab (3), +.br wmemset (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 2003 walter harms (walter.harms@informatik.uni-oldenburg.de) +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" distributed under gpl +.\" %%%license_end +.\" +.\" this is the 3rd type of interface for cryptographic routines +.\" 1. encrypt() expects a bit field +.\" 2. cbc_crypt() byte values +.\" 3. xencrypt() a hexstring +.\" to bad to be true :( +.\" +.th xcrypt 3 2021-03-22 "" "linux programmer's manual" +.sh name +xencrypt, xdecrypt, passwd2des \- rfs password encryption +.sh synopsis +.nf +.b "#include " +.pp +.bi "void passwd2des(char " *passwd ", char *" key ");" +.pp +.bi "int xencrypt(char *" secret ", char *" passwd ");" +.bi "int xdecrypt(char *" secret ", char *" passwd ");" +.fi +.sh description +.br warning : +do not use these functions in new code. +they do not achieve any type of acceptable cryptographic security guarantees. +.pp +the function +.br passwd2des () +takes a character string +.i passwd +of arbitrary length and fills a character array +.i key +of length 8. +the array +.i key +is suitable for use as des key. +it has odd parity set in bit 0 of each byte. +both other functions described here use this function to turn their +argument +.i passwd +into a des key. +.pp +the +.br xencrypt () +function takes the ascii character string +.i secret +given in hex, +.\" (over the alphabet 0123456789abcdefabcdef), +which must have a length that is a multiple of 16, +encrypts it using the des key derived from +.i passwd +by +.br passwd2des (), +and outputs the result again in +.i secret +as a hex string +.\" (over the alphabet 0123456789abcdef) +of the same length. +.pp +the +.br xdecrypt () +function performs the converse operation. +.sh return value +the functions +.br xencrypt () +and +.br xdecrypt () +return 1 on success and 0 on error. +.sh versions +these functions are available in glibc since version 2.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br passwd2des (), +.br xencrypt (), +.br xdecrypt () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh bugs +the prototypes are missing from the abovementioned include file. +.sh see also +.br cbc_crypt (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/termios.3 + +.\" copyright (c) 2017 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_atfork 3 2020-08-13 "linux" "linux programmer's manual" +.sh name +pthread_atfork \- register fork handlers +.sh synopsis +.nf +.b #include +.pp +.bi "int pthread_atfork(void (*" prepare ")(void), void (*" parent ")(void)," +.bi " void (*" child ")(void));" +.fi +.pp +link with \fi\-pthread\fp. +.sh description +the +.br pthread_atfork () +function registers fork handlers that are to be executed when +.br fork (2) +is called by this thread. +the handlers are executed in the context of the thread that calls +.br fork (2). +.pp +three kinds of handler can be registered: +.ip * 3 +.ir prepare +specifies a handler that is executed before +.br fork (2) +processing starts. +.ip * +.i parent +specifies a handler that is executed in the parent process after +.br fork (2) +processing completes. +.ip * +.i child +specifies a handler that is executed in the child process after +.br fork (2) +processing completes. +.pp +any of the three arguments may be null if no handler is needed +in the corresponding phase of +.br fork (2) +processing. +.sh return value +on success, +.br pthread_atfork () +returns zero. +on error, it returns an error number. +.br pthread_atfork () +may be called multiple times by a thread, +to register multiple handlers for each phase. +the handlers for each phase are called in a specified order: the +.i prepare +handlers are called in reverse order of registration; the +.i parent +and +.i child +handlers are called in the order of registration. +.sh errors +.tp +.b enomem +could not allocate memory to record the form handler entry. +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +when +.br fork (2) +is called in a multithreaded process, +only the calling thread is duplicated in the child process. +the original intention of +.br pthread_atfork () +was to allow the calling thread to be returned to a consistent state. +for example, at the time of the call to +.br fork (2), +other threads may have locked mutexes that are visible in the +user-space memory duplicated in the child. +such mutexes would never be unlocked, +since the threads that placed the locks are not duplicated in the child. +the intent of +.br pthread_atfork () +was to provide a mechanism whereby the application (or a library) +could ensure that mutexes and other process and thread state would be +restored to a consistent state. +in practice, this task is generally too difficult to be practicable. +.pp +after a +.br fork (2) +in a multithreaded process returns in the child, +the child should call only async-signal-safe functions (see +.br signal\-safety (7)) +until such time as it calls +.br execve (2) +to execute a new program. +.pp +posix.1 specifies that +.br pthread_atfork () +shall not fail with the error +.br eintr . +.sh see also +.br fork (2), +.br atexit (3), +.br pthreads (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getutent.3 + +.so man3/unlocked_stdio.3 + +.\" copyright 1995 james r. van zandt +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th stpcpy 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +stpcpy \- copy a string returning a pointer to its end +.sh synopsis +.nf +.b #include +.pp +.bi "char *stpcpy(char *restrict " dest ", const char *restrict " src ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br stpcpy (): +.nf + since glibc 2.10: + _posix_c_source >= 200809l + before glibc 2.10: + _gnu_source +.fi +.sh description +the +.br stpcpy () +function copies the string pointed to by +.i src +(including the terminating null byte (\(aq\e0\(aq)) to the array pointed to by +.ir dest . +the strings may not overlap, and the destination string +.i dest +must be large enough to receive the copy. +.sh return value +.br stpcpy () +returns a pointer to the +.b end +of the string +.i dest +(that is, the address of the terminating null byte) +rather than the beginning. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br stpcpy () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +this function was added to posix.1-2008. +before that, it was not part of +the c or posix.1 standards, nor customary on unix systems. +it first appeared at least as early as 1986, +in the lattice c amigados compiler, +then in the gnu fileutils and gnu textutils in 1989, +and in the gnu c library by 1992. +it is also present on the bsds. +.sh bugs +this function may overrun the buffer +.ir dest . +.sh examples +for example, this program uses +.br stpcpy () +to concatenate +.b foo +and +.b bar +to produce +.br foobar , +which it then prints. +.pp +.ex +#define _gnu_source +#include +#include + +int +main(void) +{ + char buffer[20]; + char *to = buffer; + + to = stpcpy(to, "foo"); + to = stpcpy(to, "bar"); + printf("%s\en", buffer); +} +.ee +.sh see also +.br bcopy (3), +.br memccpy (3), +.br memcpy (3), +.br memmove (3), +.br stpncpy (3), +.br strcpy (3), +.br string (3), +.br wcpcpy (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/lround.3 + +.so man3/getnetent.3 + +.so man2/accept.2 + +.so man3/cpow.3 + +.\" copyright (c) 2019 aleksa sarai +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.th openat2 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +openat2 \- open and possibly create a file (extended) +.sh synopsis +.nf +.br "#include " \ +" /* definition of " o_* " and " s_* " constants */" +.br "#include " " /* definition of " resolve_* " constants */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "long syscall(sys_openat2, int " dirfd ", const char *" pathname , +.bi " struct open_how *" how ", size_t " size ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br openat2 (), +necessitating the use of +.br syscall (2). +.sh description +the +.br openat2 () +system call is an extension of +.br openat (2) +and provides a superset of its functionality. +.pp +the +.br openat2 () +system call opens the file specified by +.ir pathname . +if the specified file does not exist, it may optionally (if +.b o_creat +is specified in +.ir how.flags ) +be created. +.pp +as with +.br openat (2), +if +.i pathname +is a relative pathname, then it is interpreted relative to the +directory referred to by the file descriptor +.i dirfd +(or the current working directory of the calling process, if +.i dirfd +is the special value +.br at_fdcwd ). +if +.i pathname +is an absolute pathname, then +.i dirfd +is ignored (unless +.i how.resolve +contains +.br resolve_in_root , +in which case +.i pathname +is resolved relative to +.ir dirfd ). +.pp +rather than taking a single +.i flags +argument, an extensible structure (\fihow\fp) is passed to allow for +future extensions. +the +.i size +argument must be specified as +.ir "sizeof(struct open_how)" . +.\" +.ss the open_how structure +the +.i how +argument specifies how +.i pathname +should be opened, and acts as a superset of the +.ir flags +and +.ir mode +arguments to +.br openat (2). +this argument is a pointer to a structure of the following form: +.pp +.in +4n +.ex +struct open_how { + u64 flags; /* o_* flags */ + u64 mode; /* mode for o_{creat,tmpfile} */ + u64 resolve; /* resolve_* flags */ + /* ... */ +}; +.ee +.in +.pp +any future extensions to +.br openat2 () +will be implemented as new fields appended to the above structure, +with a zero value in a new field resulting in the kernel behaving +as though that extension field was not present. +therefore, the caller +.i must +zero-fill this structure on +initialization. +(see the "extensibility" section of the +.b notes +for more detail on why this is necessary.) +.pp +the fields of the +.i open_how +structure are as follows: +.tp +.i flags +this field specifies +the file creation and file status flags to use when opening the file. +all of the +.b o_* +flags defined for +.br openat (2) +are valid +.br openat2 () +flag values. +.ip +whereas +.br openat (2) +ignores unknown bits in its +.i flags +argument, +.br openat2 () +returns an error if unknown or conflicting flags are specified in +.ir how.flags . +.tp +.i mode +this field specifies the +mode for the new file, with identical semantics to the +.i mode +argument of +.br openat (2). +.ip +whereas +.br openat (2) +ignores bits other than those in the range +.i 07777 +in its +.i mode +argument, +.br openat2 () +returns an error if +.i how.mode +contains bits other than +.ir 07777 . +similarly, an error is returned if +.br openat2 () +is called with a nonzero +.ir how.mode +and +.ir how.flags +does not contain +.br o_creat +or +.br o_tmpfile . +.tp +.i resolve +this is a bit-mask of flags that modify the way in which +.b all +components of +.i pathname +will be resolved. +(see +.br path_resolution (7) +for background information.) +.ip +the primary use case for these flags is to allow trusted programs to restrict +how untrusted paths (or paths inside untrusted directories) are resolved. +the full list of +.i resolve +flags is as follows: +.rs +.tp +.b resolve_beneath +.\" commit adb21d2b526f7f196b2f3fdca97d80ba05dd14a0 +do not permit the path resolution to succeed if any component of the resolution +is not a descendant of the directory indicated by +.ir dirfd . +this causes absolute symbolic links (and absolute values of +.ir pathname ) +to be rejected. +.ip +currently, this flag also disables magic-link resolution (see below). +however, this may change in the future. +therefore, to ensure that magic links are not resolved, +the caller should explicitly specify +.br resolve_no_magiclinks . +.tp +.b resolve_in_root +.\" commit 8db52c7e7ee1bd861b6096fcafc0fe7d0f24a994 +treat the directory referred to by +.i dirfd +as the root directory while resolving +.ir pathname . +absolute symbolic links are interpreted relative to +.ir dirfd . +if a prefix component of +.i pathname +equates to +.ir dirfd , +then an immediately following +.ir ..\& +component likewise equates to +.ir dirfd +(just as +.i /..\& +is traditionally equivalent to +.ir / ). +if +.i pathname +is an absolute path, it is also interpreted relative to +.ir dirfd . +.ip +the effect of this flag is as though the calling process had used +.br chroot (2) +to (temporarily) modify its root directory (to the directory +referred to by +.ir dirfd ). +however, unlike +.br chroot (2) +(which changes the filesystem root permanently for a process), +.b resolve_in_root +allows a program to efficiently restrict path resolution on a per-open basis. +.ip +currently, this flag also disables magic-link resolution. +however, this may change in the future. +therefore, to ensure that magic links are not resolved, +the caller should explicitly specify +.br resolve_no_magiclinks . +.tp +.b resolve_no_magiclinks +.\" commit 278121417a72d87fb29dd8c48801f80821e8f75a +disallow all magic-link resolution during path resolution. +.ip +magic links are symbolic link-like objects that are most notably found in +.br proc (5); +examples include +.ir /proc/[pid]/exe +and +.ir /proc/[pid]/fd/* . +(see +.br symlink (7) +for more details.) +.ip +unknowingly opening magic links can be risky for some applications. +examples of such risks include the following: +.rs +.ip \(bu 2 +if the process opening a pathname is a controlling process that +currently has no controlling terminal (see +.br credentials (7)), +then opening a magic link inside +.ir /proc/[pid]/fd +that happens to refer to a terminal +would cause the process to acquire a controlling terminal. +.ip \(bu +.\" from https://lwn.net/articles/796868/: +.\" the presence of this flag will prevent a path lookup operation +.\" from traversing through one of these magic links, thus blocking +.\" (for example) attempts to escape from a container via a /proc +.\" entry for an open file descriptor. +in a containerized environment, +a magic link inside +.i /proc +may refer to an object outside the container, +and thus may provide a means to escape from the container. +.re +.ip +because of such risks, +an application may prefer to disable magic link resolution using the +.br resolve_no_magiclinks +flag. +.ip +if the trailing component (i.e., basename) of +.i pathname +is a magic link, +.i how.resolve +contains +.br resolve_no_magiclinks , +and +.i how.flags +contains both +.br o_path +and +.br o_nofollow , +then an +.b o_path +file descriptor referencing the magic link will be returned. +.tp +.b resolve_no_symlinks +.\" commit 278121417a72d87fb29dd8c48801f80821e8f75a +disallow resolution of symbolic links during path resolution. +this option implies +.br resolve_no_magiclinks . +.ip +if the trailing component (i.e., basename) of +.i pathname +is a symbolic link, +.i how.resolve +contains +.br resolve_no_symlinks , +and +.i how.flags +contains both +.br o_path +and +.br o_nofollow , +then an +.b o_path +file descriptor referencing the symbolic link will be returned. +.ip +note that the effect of the +.br resolve_no_symlinks +flag, +which affects the treatment of symbolic links in all of the components of +.ir pathname , +differs from the effect of the +.br o_nofollow +file creation flag (in +.ir how.flags ), +which affects the handling of symbolic links only in the final component of +.ir pathname . +.ip +applications that employ the +.br resolve_no_symlinks +flag are encouraged to make its use configurable +(unless it is used for a specific security purpose), +as symbolic links are very widely used by end-users. +setting this flag indiscriminately\(emi.e., +for purposes not specifically related to security\(emfor all uses of +.br openat2 () +may result in spurious errors on previously functional systems. +this may occur if, for example, +a system pathname that is used by an application is modified +(e.g., in a new distribution release) +so that a pathname component (now) contains a symbolic link. +.tp +.b resolve_no_xdev +.\" commit 72ba29297e1439efaa54d9125b866ae9d15df339 +disallow traversal of mount points during path resolution (including all bind +mounts). +consequently, +.i pathname +must either be on the same mount as the directory referred to by +.ir dirfd , +or on the same mount as the current working directory if +.i dirfd +is specified as +.br at_fdcwd . +.ip +applications that employ the +.b resolve_no_xdev +flag are encouraged to make its use configurable (unless it is +used for a specific security purpose), +as bind mounts are widely used by end-users. +setting this flag indiscriminately\(emi.e., +for purposes not specifically related to security\(emfor all uses of +.br openat2 () +may result in spurious errors on previously functional systems. +this may occur if, for example, +a system pathname that is used by an application is modified +(e.g., in a new distribution release) +so that a pathname component (now) contains a bind mount. +.tp +.b resolve_cached +make the open operation fail unless all path components are already present +in the kernel's lookup cache. +if any kind of revalidation or i/o is needed to satisfy the lookup, +.br openat2 () +fails with the error +.b eagain . +this is useful in providing a fast-path open that can be performed without +resorting to thread offload, or other mechanisms that an application might +use to offload slower operations. +.re +.ip +if any bits other than those listed above are set in +.ir how.resolve , +an error is returned. +.sh return value +on success, a new file descriptor is returned. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +the set of errors returned by +.br openat2 () +includes all of the errors returned by +.br openat (2), +as well as the following additional errors: +.tp +.b e2big +an extension that this kernel does not support was specified in +.ir how . +(see the "extensibility" section of +.b notes +for more detail on how extensions are handled.) +.tp +.b eagain +.i how.resolve +contains either +.br resolve_in_root +or +.br resolve_beneath , +and the kernel could not ensure that a ".." component didn't escape (due to a +race condition or potential attack). +the caller may choose to retry the +.br openat2 () +call. +.tp +.b eagain +.br resolve_cached +was set, and the open operation cannot be performed using only cached +information. +the caller should retry without +.b resolve_cached +set in +.i how.resolve . +.tp +.b einval +an unknown flag or invalid value was specified in +.ir how . +.tp +.b einval +.i mode +is nonzero, but +.i how.flags +does not contain +.br o_creat +or +.br o_tmpfile . +.tp +.b einval +.i size +was smaller than any known version of +.ir "struct open_how" . +.tp +.b eloop +.i how.resolve +contains +.br resolve_no_symlinks , +and one of the path components was a symbolic link (or magic link). +.tp +.b eloop +.i how.resolve +contains +.br resolve_no_magiclinks , +and one of the path components was a magic link. +.tp +.b exdev +.i how.resolve +contains either +.br resolve_in_root +or +.br resolve_beneath , +and an escape from the root during path resolution was detected. +.tp +.b exdev +.i how.resolve +contains +.br resolve_no_xdev , +and a path component crosses a mount point. +.sh versions +.br openat2 () +first appeared in linux 5.6. +.\" commit fddb5d430ad9fa91b49b1d34d0202ffe2fa0e179 +.sh conforming to +this system call is linux-specific. +.pp +the semantics of +.b resolve_beneath +were modeled after freebsd's +.br o_beneath . +.sh notes +.ss extensibility +in order to allow for future extensibility, +.br openat2 () +requires the user-space application to specify the size of the +.i open_how +structure that it is passing. +by providing this information, it is possible for +.br openat2 () +to provide both forwards- and backwards-compatibility, with +.i size +acting as an implicit version number. +(because new extension fields will always +be appended, the structure size will always increase.) +this extensibility design is very similar to other system calls such as +.br sched_setattr (2), +.br perf_event_open (2), +and +.br clone3 (2). +.pp +if we let +.i usize +be the size of the structure as specified by the user-space application, and +.i ksize +be the size of the structure which the kernel supports, then there are +three cases to consider: +.ip \(bu 2 +if +.ir ksize +equals +.ir usize , +then there is no version mismatch and +.i how +can be used verbatim. +.ip \(bu +if +.ir ksize +is larger than +.ir usize , +then there are some extension fields that the kernel supports +which the user-space application +is unaware of. +because a zero value in any added extension field signifies a no-op, +the kernel +treats all of the extension fields not provided by the user-space application +as having zero values. +this provides backwards-compatibility. +.ip \(bu +if +.ir ksize +is smaller than +.ir usize , +then there are some extension fields which the user-space application +is aware of but which the kernel does not support. +because any extension field must have its zero values signify a no-op, +the kernel can +safely ignore the unsupported extension fields if they are all-zero. +if any unsupported extension fields are nonzero, then \-1 is returned and +.i errno +is set to +.br e2big . +this provides forwards-compatibility. +.pp +because the definition of +.i struct open_how +may change in the future (with new fields being added when system headers are +updated), user-space applications should zero-fill +.i struct open_how +to ensure that recompiling the program with new headers will not result in +spurious errors at runtime. +the simplest way is to use a designated +initializer: +.pp +.in +4n +.ex +struct open_how how = { .flags = o_rdwr, + .resolve = resolve_in_root }; +.ee +.in +.pp +or explicitly using +.br memset (3) +or similar: +.pp +.in +4n +.ex +struct open_how how; +memset(&how, 0, sizeof(how)); +how.flags = o_rdwr; +how.resolve = resolve_in_root; +.ee +.in +.pp +a user-space application that wishes to determine which extensions +the running kernel supports can do so by conducting a binary search on +.ir size +with a structure which has every byte nonzero (to find the largest value +which doesn't produce an error of +.br e2big ). +.sh see also +.br openat (2), +.br path_resolution (7), +.br symlink (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/resolver.3 + +.so man2/unlink.2 + +.so man3/envz_add.3 + +.so man3/rpc.3 + +.so man3/mq_timedreceive.3 +.\" because mq_timedreceive(3) is layered on a system call of the same name + +.so man3/setjmp.3 + +.\" this man page was written by jeremy phelps . +.\" +.\" %%%license_start(freely_redistributable) +.\" redistribute and modify at will. +.\" %%%license_end +.\" +.th getpt 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +getpt \- open a new pseudoterminal master +.sh synopsis +.nf +.br "#define _gnu_source" " /* see feature_test_macros(7) */" +.b #include +.pp +.b "int getpt(void);" +.fi +.sh description +.br getpt () +opens a new pseudoterminal device and returns a file descriptor +that refers to that device. +it is equivalent to opening the pseudoterminal multiplexor device +.pp +.in +4n +.ex +open("/dev/ptmx", o_rdwr); +.ee +.in +.pp +on linux systems, though the pseudoterminal multiplexor device is located +elsewhere on some systems that use the gnu c library. +.sh return value +.br getpt () +returns an open file descriptor upon successful completion. +otherwise, it +returns \-1 and sets +.i errno +to indicate the error. +.sh errors +.br getpt () +can fail with various errors described in +.br open (2). +.sh versions +.br getpt () +is provided in glibc since version 2.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br getpt () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +.br getpt () +is glibc-specific; +use +.br posix_openpt (3) +instead. +.sh see also +.br grantpt (3), +.br posix_openpt (3), +.br ptsname (3), +.br unlockpt (3), +.br ptmx (4), +.br pty (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1980, 1991 regents of the university of california. +.\" all rights reserved. +.\" +.\" %%%license_start(bsd_4_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. all advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" this product includes software developed by the university of +.\" california, berkeley and its contributors. +.\" 4. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" @(#)ioctl.2 6.4 (berkeley) 3/10/91 +.\" +.\" modified 1993-07-23 by rik faith +.\" modified 1996-10-22 by eric s. raymond +.\" modified 1999-06-25 by rachael munns +.\" modified 2000-09-21 by andries brouwer +.\" +.th ioctl 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +ioctl \- control device +.sh synopsis +.nf +.b #include +.pp +.bi "int ioctl(int " fd ", unsigned long " request ", ...);" +.\" posix says 'request' is int, but glibc has the above +.\" see https://bugzilla.kernel.org/show_bug.cgi?id=42705 +.fi +.sh description +the +.br ioctl () +system call manipulates the underlying device parameters of special files. +in particular, many operating characteristics of character special files +(e.g., terminals) may be controlled with +.br ioctl () +requests. +the argument +.i fd +must be an open file descriptor. +.pp +the second argument is a device-dependent request code. +the third argument is an untyped pointer to memory. +it's traditionally +.bi "char *" argp +(from the days before +.b "void *" +was valid c), and will be so named for this discussion. +.pp +an +.br ioctl () +.i request +has encoded in it whether the argument is an +.i in +parameter or +.i out +parameter, and the size of the argument +.i argp +in bytes. +macros and defines used in specifying an +.br ioctl () +.i request +are located in the file +.ir . +see notes. +.sh return value +usually, on success zero is returned. +a few +.br ioctl () +requests use the return value as an output parameter +and return a nonnegative value on success. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b ebadf +.i fd +is not a valid file descriptor. +.tp +.b efault +.i argp +references an inaccessible memory area. +.tp +.b einval +.i request +or +.i argp +is not valid. +.tp +.b enotty +.i fd +is not associated with a character special device. +.tp +.b enotty +the specified request does not apply to the kind of object that the +file descriptor +.i fd +references. +.sh conforming to +no single standard. +arguments, returns, and semantics of +.br ioctl () +vary according to the device driver in question (the call is used as a +catch-all for operations that don't cleanly fit the unix stream i/o +model). +.pp +the +.br ioctl () +system call appeared in version 7 at&t unix. +.sh notes +in order to use this call, one needs an open file descriptor. +often the +.br open (2) +call has unwanted side effects, that can be avoided under linux +by giving it the +.b o_nonblock +flag. +.\" +.ss ioctl structure +.\" added two sections - aeb +ioctl command values are 32-bit constants. +in principle these constants are completely arbitrary, but people have +tried to build some structure into them. +.pp +the old linux situation was that of mostly 16-bit constants, where the +last byte is a serial number, and the preceding byte(s) give a type +indicating the driver. +sometimes the major number was used: 0x03 +for the +.b hdio_* +ioctls, 0x06 for the +.b lp* +ioctls. +and sometimes +one or more ascii letters were used. +for example, +.b tcgets +has value +0x00005401, with 0x54 = \(aqt\(aq indicating the terminal driver, and +.b cygettimeout +has value 0x00435906, with 0x43 0x59 = \(aqc\(aq \(aqy\(aq +indicating the cyclades driver. +.pp +later (0.98p5) some more information was built into the number. +one has 2 direction bits +(00: none, 01: write, 10: read, 11: read/write) +followed by 14 size bits (giving the size of the argument), +followed by an 8-bit type (collecting the ioctls in groups +for a common purpose or a common driver), and an 8-bit +serial number. +.pp +the macros describing this structure live in +.i +and are +.b _io(type,nr) +and +.br "{_ior,_iow,_iowr}(type,nr,size)" . +they use +.i sizeof(size) +so that size is a +misnomer here: this third argument is a data type. +.pp +note that the size bits are very unreliable: in lots of cases +they are wrong, either because of buggy macros using +.ir sizeof(sizeof(struct)) , +or because of legacy values. +.pp +thus, it seems that the new structure only gave disadvantages: +it does not help in checking, but it causes varying values +for the various architectures. +.sh see also +.br execve (2), +.br fcntl (2), +.br ioctl_console (2), +.br ioctl_fat (2), +.br ioctl_ficlonerange (2), +.br ioctl_fideduperange (2), +.br ioctl_fslabel (2), +.br ioctl_getfsmap (2), +.br ioctl_iflags (2), +.br ioctl_ns (2), +.br ioctl_tty (2), +.br ioctl_userfaultfd (2), +.br open (2), +.\" .br mt (4), +.br sd (4), +.br tty (4) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2012, petr benas +.\" and copyright (c) 2012, michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of +.\" this manual under the conditions for verbatim copying, provided that +.\" the entire resulting derived work is distributed under the terms of +.\" a permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume +.\" no responsibility for errors or omissions, or for damages resulting +.\" from the use of the information contained herein. the author(s) may +.\" not have taken the same level of care in the production of this +.\" manual, which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th get_nprocs 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +get_nprocs, get_nprocs_conf \- get number of processors +.sh synopsis +.nf +.b #include +.pp +.bi "int get_nprocs(void);" +.bi "int get_nprocs_conf(void);" +.fi +.sh description +the function +.br get_nprocs_conf () +returns the number of processors configured by the operating system. +.pp +the function +.br get_nprocs () +returns the number of processors currently available in the system. +this may be less than the number returned by +.br get_nprocs_conf () +because processors may be offline (e.g., on hotpluggable systems). +.sh return value +as given in description. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br get_nprocs (), +.br get_nprocs_conf () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +these functions are gnu extensions. +.sh notes +the current +.\" glibc 2.15 +implementation of these functions is rather expensive, +since they open and parse files in the +.i /sys +filesystem each time they are called. +.pp +the following +.br sysconf (3) +calls make use of the functions documented on this page +to return the same information. +.pp +.in +4n +.ex +np = sysconf(_sc_nprocessors_conf); /* processors configured */ +np = sysconf(_sc_nprocessors_onln); /* processors available */ +.ee +.in +.sh examples +the following example shows how +.br get_nprocs () +and +.br get_nprocs_conf () +can be used. +.pp +.ex +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + printf("this system has %d processors configured and " + "%d processors available.\en", + get_nprocs_conf(), get_nprocs()); + exit(exit_success); +} +.ee +.sh see also +.br nproc (1) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/setjmp.3 + +.so man3/getutent.3 + +.\" %%%license_start(public_domain) +.\" this page is in the public domain +.\" %%%license_end +.\" +.th tzselect 8 2021-03-22 "" "linux system administration" +.sh name +tzselect \- select a timezone +.sh synopsis +.nf +.b tzselect +.fi +.sh description +the +.b tzselect +program asks the user for information about the current location, +and outputs the resulting timezone description to standard output. +the output is suitable as a value for the +.b tz +environment variable. +.pp +all interaction with the user is done via standard input and standard error. +.sh exit status +the exit status is zero if a timezone was successfully obtained +from the user, and is nonzero otherwise. +.sh environment +.tp +.b awk +name of a posix-compliant +.i awk +program (default: +.br awk ). +.tp +.b tzdir +name of the directory containing timezone data files (default: +.ir /usr/share/zoneinfo ). +.\" or perhaps /usr/local/etc/zoneinfo in some older systems. +.sh files +.tp +\fbtzdir\fp\fi/iso3166.tab\fp +table of iso 3166 2-letter country codes and country names. +.tp +\fbtzdir\fp\fi/zone.tab\fp +table of country codes, latitude and longitude, tz values, and +descriptive comments. +.tp +\fbtzdir\fp\fi/\fp\fitz\fp +timezone data file for timezone +.ir tz . +.sh see also +.br tzfile (5), +.br zdump (8), +.br zic (8) +.\" @(#)tzselect.8 1.3 +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/cmsg.3 + +.so man7/system_data_types.7 + +.so man3/fma.3 + +.so man2/outb.2 + +.so man3/fenv.3 + +.so man3/unlocked_stdio.3 + +.\" copyright (c) bruno haible +.\" and copyright (c) 2014 michael kerrisk +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th towlower 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +towlower, towlower_l \- convert a wide character to lowercase +.sh synopsis +.nf +.b #include +.pp +.bi "wint_t towlower(wint_t " wc ); +.bi "wint_t towlower_l(wint_t " wc ", locale_t " locale ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br towlower_l (): +.nf + since glibc 2.10: + _xopen_source >= 700 + before glibc 2.10: + _gnu_source +.fi +.sh description +the +.br towlower () +function is the wide-character equivalent of the +.br tolower (3) +function. +if +.i wc +is an uppercase wide character, +and there exists a lowercase equivalent in the current locale, +it returns the lowercase equivalent of +.ir wc . +in all other cases, +.i wc +is returned unchanged. +.pp +the +.br towlower_l () +function performs the same task, +but performs the conversion based on the character type information in +the locale specified by +.ir locale . +the behavior of +.br towlower_l () +is undefined if +.i locale +is the special locale object +.b lc_global_locale +(see +.br duplocale (3)) +or is not a valid locale object handle. +.pp +the argument +.i wc +must be representable as a +.i wchar_t +and be a valid character in the locale or be the value +.br weof . +.sh return value +if +.i wc +was convertible to lowercase, +.br towlower () +returns its lowercase equivalent; +otherwise it returns +.ir wc . +.sh versions +the +.br towlower_l () +function first appeared in glibc 2.3. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br towlower () +t} thread safety mt-safe locale +t{ +.br towlower_l () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +.br towlower (): +c99, posix.1-2001 (xsi); +present as an xsi extension in posix.1-2008, but marked obsolete. +.pp +.br towlower_l (): +posix.1-2008. +.sh notes +the behavior of these functions depends on the +.b lc_ctype +category of the locale. +.pp +these functions are not very appropriate for dealing with unicode characters, +because unicode knows about three cases: upper, lower, and title case. +.sh see also +.br iswlower (3), +.br towctrans (3), +.br towupper (3), +.br locale (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" this man page is copyright (c) 1999 andi kleen . +.\" +.\" %%%license_start(verbatim_one_para) +.\" permission is granted to distribute possibly modified copies +.\" of this page provided the header is included verbatim, +.\" and in case of nontrivial modification author and date +.\" of the modification is added to the header. +.\" %%%license_end +.\" +.\" $id: packet.7,v 1.13 2000/08/14 08:03:45 ak exp $ +.\" +.th packet 7 2021-03-22 "linux" "linux programmer's manual" +.sh name +packet \- packet interface on device level +.sh synopsis +.nf +.b #include +.b #include +.b #include /* the l2 protocols */ +.pp +.bi "packet_socket = socket(af_packet, int " socket_type ", int "protocol ); +.fi +.sh description +packet sockets are used to receive or send raw packets at the device driver +(osi layer 2) level. +they allow the user to implement protocol modules in user space +on top of the physical layer. +.pp +the +.i socket_type +is either +.b sock_raw +for raw packets including the link-level header or +.b sock_dgram +for cooked packets with the link-level header removed. +the link-level header information is available in a common format in a +.ir sockaddr_ll +structure. +.i protocol +is the ieee 802.3 protocol number in network byte order. +see the +.i +include file for a list of allowed protocols. +when protocol +is set to +.br htons(eth_p_all) , +then all protocols are received. +all incoming packets of that protocol type will be passed to the packet +socket before they are passed to the protocols implemented in the kernel. +.pp +in order to create a packet socket, a process must have the +.b cap_net_raw +capability in the user namespace that governs its network namespace. +.pp +.b sock_raw +packets are passed to and from the device driver without any changes in +the packet data. +when receiving a packet, the address is still parsed and +passed in a standard +.i sockaddr_ll +address structure. +when transmitting a packet, the user-supplied buffer +should contain the physical-layer header. +that packet is then +queued unmodified to the network driver of the interface defined by the +destination address. +some device drivers always add other headers. +.b sock_raw +is similar to but not compatible with the obsolete +.b af_inet/sock_packet +of linux 2.0. +.pp +.b sock_dgram +operates on a slightly higher level. +the physical header is removed before the packet is passed to the user. +packets sent through a +.b sock_dgram +packet socket get a suitable physical-layer header based on the +information in the +.i sockaddr_ll +destination address before they are queued. +.pp +by default, all packets of the specified protocol type +are passed to a packet socket. +to get packets only from a specific interface use +.br bind (2) +specifying an address in a +.i struct sockaddr_ll +to bind the packet socket to an interface. +fields used for binding are +.ir sll_family +(should be +.br af_packet ), +.ir sll_protocol , +and +.ir sll_ifindex . +.pp +the +.br connect (2) +operation is not supported on packet sockets. +.pp +when the +.b msg_trunc +flag is passed to +.br recvmsg (2), +.br recv (2), +or +.br recvfrom (2), +the real length of the packet on the wire is always returned, +even when it is longer than the buffer. +.ss address types +the +.i sockaddr_ll +structure is a device-independent physical-layer address. +.pp +.in +4n +.ex +struct sockaddr_ll { + unsigned short sll_family; /* always af_packet */ + unsigned short sll_protocol; /* physical\-layer protocol */ + int sll_ifindex; /* interface number */ + unsigned short sll_hatype; /* arp hardware type */ + unsigned char sll_pkttype; /* packet type */ + unsigned char sll_halen; /* length of address */ + unsigned char sll_addr[8]; /* physical\-layer address */ +}; +.ee +.in +.pp +the fields of this structure are as follows: +.ip * 3 +.i sll_protocol +is the standard ethernet protocol type in network byte order as defined +in the +.i +include file. +it defaults to the socket's protocol. +.ip * +.i sll_ifindex +is the interface index of the interface +(see +.br netdevice (7)); +0 matches any interface (only permitted for binding). +.i sll_hatype +is an arp type as defined in the +.i +include file. +.ip * +.i sll_pkttype +contains the packet type. +valid types are +.b packet_host +for a packet addressed to the local host, +.b packet_broadcast +for a physical-layer broadcast packet, +.b packet_multicast +for a packet sent to a physical-layer multicast address, +.b packet_otherhost +for a packet to some other host that has been caught by a device driver +in promiscuous mode, and +.b packet_outgoing +for a packet originating from the local host that is looped back to a packet +socket. +these types make sense only for receiving. +.ip * +.i sll_addr +and +.i sll_halen +contain the physical-layer (e.g., ieee 802.3) address and its length. +the exact interpretation depends on the device. +.pp +when you send packets, it is enough to specify +.ir sll_family , +.ir sll_addr , +.ir sll_halen , +.ir sll_ifindex , +and +.ir sll_protocol . +the other fields should be 0. +.i sll_hatype +and +.i sll_pkttype +are set on received packets for your information. +.ss socket options +packet socket options are configured by calling +.br setsockopt (2) +with level +.br sol_packet . +.tp +.br packet_add_membership +.pd 0 +.tp +.br packet_drop_membership +.pd +packet sockets can be used to configure physical-layer multicasting +and promiscuous mode. +.b packet_add_membership +adds a binding and +.b packet_drop_membership +drops it. +they both expect a +.i packet_mreq +structure as argument: +.ip +.in +4n +.ex +struct packet_mreq { + int mr_ifindex; /* interface index */ + unsigned short mr_type; /* action */ + unsigned short mr_alen; /* address length */ + unsigned char mr_address[8]; /* physical\-layer address */ +}; +.ee +.in +.ip +.i mr_ifindex +contains the interface index for the interface whose status +should be changed. +the +.i mr_type +field specifies which action to perform. +.b packet_mr_promisc +enables receiving all packets on a shared medium (often known as +"promiscuous mode"), +.b packet_mr_multicast +binds the socket to the physical-layer multicast group specified in +.i mr_address +and +.ir mr_alen , +and +.b packet_mr_allmulti +sets the socket up to receive all multicast packets arriving at +the interface. +.ip +in addition, the traditional ioctls +.br siocsifflags , +.br siocaddmulti , +.b siocdelmulti +can be used for the same purpose. +.tp +.br packet_auxdata " (since linux 2.6.21)" +.\" commit 8dc4194474159660d7f37c495e3fc3f10d0db8cc +if this binary option is enabled, the packet socket passes a metadata +structure along with each packet in the +.br recvmsg (2) +control field. +the structure can be read with +.br cmsg (3). +it is defined as +.ip +.in +4n +.ex +struct tpacket_auxdata { + __u32 tp_status; + __u32 tp_len; /* packet length */ + __u32 tp_snaplen; /* captured length */ + __u16 tp_mac; + __u16 tp_net; + __u16 tp_vlan_tci; + __u16 tp_vlan_tpid; /* since linux 3.14; earlier, these + were unused padding bytes */ +.\" commit a0cdfcf39362410d5ea983f4daf67b38de129408 added tp_vlan_tpid +}; +.ee +.in +.tp +.br packet_fanout " (since linux 3.1)" +.\" commit dc99f600698dcac69b8f56dda9a8a00d645c5ffc +to scale processing across threads, packet sockets can form a fanout +group. +in this mode, each matching packet is enqueued onto only one +socket in the group. +a socket joins a fanout group by calling +.br setsockopt (2) +with level +.b sol_packet +and option +.br packet_fanout . +each network namespace can have up to 65536 independent groups. +a socket selects a group by encoding the id in the first 16 bits of +the integer option value. +the first packet socket to join a group implicitly creates it. +to successfully join an existing group, subsequent packet sockets +must have the same protocol, device settings, fanout mode, and +flags (see below). +packet sockets can leave a fanout group only by closing the socket. +the group is deleted when the last socket is closed. +.ip +fanout supports multiple algorithms to spread traffic between sockets, +as follows: +.rs +.ip * 3 +the default mode, +.br packet_fanout_hash , +sends packets from the same flow to the same socket to maintain +per-flow ordering. +for each packet, it chooses a socket by taking the packet flow hash +modulo the number of sockets in the group, where a flow hash is a hash +over network-layer address and optional transport-layer port fields. +.ip * +the load-balance mode +.br packet_fanout_lb +implements a round-robin algorithm. +.ip * +.br packet_fanout_cpu +selects the socket based on the cpu that the packet arrived on. +.ip * +.br packet_fanout_rollover +processes all data on a single socket, moving to the next when one +becomes backlogged. +.ip * +.br packet_fanout_rnd +selects the socket using a pseudo-random number generator. +.ip * +.br packet_fanout_qm +.\" commit 2d36097d26b5991d71a2cf4a20c1a158f0f1bfcd +(available since linux 3.14) +selects the socket using the recorded queue_mapping of the received skb. +.re +.ip +fanout modes can take additional options. +ip fragmentation causes packets from the same flow to have different +flow hashes. +the flag +.br packet_fanout_flag_defrag , +if set, causes packets to be defragmented before fanout is applied, to +preserve order even in this case. +fanout mode and options are communicated in the second 16 bits of the +integer option value. +the flag +.br packet_fanout_flag_rollover +enables the roll over mechanism as a backup strategy: if the +original fanout algorithm selects a backlogged socket, the packet +rolls over to the next available one. +.tp +.br packet_loss " (with " packet_tx_ring ) +when a malformed packet is encountered on a transmit ring, +the default is to reset its +.i tp_status +to +.br tp_status_wrong_format +and abort the transmission immediately. +the malformed packet blocks itself and subsequently enqueued packets from +being sent. +the format error must be fixed, the associated +.i tp_status +reset to +.br tp_status_send_request , +and the transmission process restarted via +.br send (2). +however, if +.br packet_loss +is set, any malformed packet will be skipped, its +.i tp_status +reset to +.br tp_status_available , +and the transmission process continued. +.tp +.br packet_reserve " (with " packet_rx_ring ) +by default, a packet receive ring writes packets immediately following the +metadata structure and alignment padding. +this integer option reserves additional headroom. +.tp +.br packet_rx_ring +create a memory-mapped ring buffer for asynchronous packet reception. +the packet socket reserves a contiguous region of application address +space, lays it out into an array of packet slots and copies packets +(up to +.ir tp_snaplen ) +into subsequent slots. +each packet is preceded by a metadata structure similar to +.ir tpacket_auxdata . +the protocol fields encode the offset to the data +from the start of the metadata header. +.i tp_net +stores the offset to the network layer. +if the packet socket is of type +.br sock_dgram , +then +.i tp_mac +is the same. +if it is of type +.br sock_raw , +then that field stores the offset to the link-layer frame. +packet socket and application communicate the head and tail of the ring +through the +.i tp_status +field. +the packet socket owns all slots with +.i tp_status +equal to +.br tp_status_kernel . +after filling a slot, it changes the status of the slot to transfer +ownership to the application. +during normal operation, the new +.i tp_status +value has at least the +.br tp_status_user +bit set to signal that a received packet has been stored. +when the application has finished processing a packet, it transfers +ownership of the slot back to the socket by setting +.i tp_status +equal to +.br tp_status_kernel . +.ip +packet sockets implement multiple variants of the packet ring. +the implementation details are described in +.ir documentation/networking/packet_mmap.rst +in the linux kernel source tree. +.tp +.br packet_statistics +retrieve packet socket statistics in the form of a structure +.ip +.in +4n +.ex +struct tpacket_stats { + unsigned int tp_packets; /* total packet count */ + unsigned int tp_drops; /* dropped packet count */ +}; +.ee +.in +.ip +receiving statistics resets the internal counters. +the statistics structure differs when using a ring of variant +.br tpacket_v3 . +.tp +.br packet_timestamp " (with " packet_rx_ring "; since linux 2.6.36)" +.\" commit 614f60fa9d73a9e8fdff3df83381907fea7c5649 +the packet receive ring always stores a timestamp in the metadata header. +by default, this is a software generated timestamp generated when the +packet is copied into the ring. +this integer option selects the type of timestamp. +besides the default, it support the two hardware formats described in +.ir documentation/networking/timestamping.rst +in the linux kernel source tree. +.tp +.br packet_tx_ring " (since linux 2.6.31)" +.\" commit 69e3c75f4d541a6eb151b3ef91f34033cb3ad6e1 +create a memory-mapped ring buffer for packet transmission. +this option is similar to +.br packet_rx_ring +and takes the same arguments. +the application writes packets into slots with +.i tp_status +equal to +.br tp_status_available +and schedules them for transmission by changing +.i tp_status +to +.br tp_status_send_request . +when packets are ready to be transmitted, the application calls +.br send (2) +or a variant thereof. +the +.i buf +and +.i len +fields of this call are ignored. +if an address is passed using +.br sendto (2) +or +.br sendmsg (2), +then that overrides the socket default. +on successful transmission, the socket resets +.i tp_status +to +.br tp_status_available . +it immediately aborts the transmission on error unless +.br packet_loss +is set. +.tp +.br packet_version " (with " packet_rx_ring "; since linux 2.6.27)" +.\" commit bbd6ef87c544d88c30e4b762b1b61ef267a7d279 +by default, +.br packet_rx_ring +creates a packet receive ring of variant +.br tpacket_v1 . +to create another variant, configure the desired variant by setting this +integer option before creating the ring. +.tp +.br packet_qdisc_bypass " (since linux 3.14)" +.\" commit d346a3fae3ff1d99f5d0c819bf86edf9094a26a1 +by default, packets sent through packet sockets pass through the kernel's +qdisc (traffic control) layer, which is fine for the vast majority of use +cases. +for traffic generator appliances using packet sockets +that intend to brute-force flood the network\(emfor example, +to test devices under load in a similar +fashion to pktgen\(emthis layer can be bypassed by setting +this integer option to 1. +a side effect is that packet buffering in the qdisc layer is avoided, +which will lead to increased drops when network +device transmit queues are busy; +therefore, use at your own risk. +.ss ioctls +.b siocgstamp +can be used to receive the timestamp of the last received packet. +argument is a +.i struct timeval +variable. +.\" fixme document siocgstampns +.pp +in addition, all standard ioctls defined in +.br netdevice (7) +and +.br socket (7) +are valid on packet sockets. +.ss error handling +packet sockets do no error handling other than errors occurred +while passing the packet to the device driver. +they don't have the concept of a pending error. +.sh errors +.tp +.b eaddrnotavail +unknown multicast group address passed. +.tp +.b efault +user passed invalid memory address. +.tp +.b einval +invalid argument. +.tp +.b emsgsize +packet is bigger than interface mtu. +.tp +.b enetdown +interface is not up. +.tp +.b enobufs +not enough memory to allocate the packet. +.tp +.b enodev +unknown device name or interface index specified in interface address. +.tp +.b enoent +no packet received. +.tp +.b enotconn +no interface address passed. +.tp +.b enxio +interface address contained an invalid interface index. +.tp +.b eperm +user has insufficient privileges to carry out this operation. +.pp +in addition, other errors may be generated by the low-level driver. +.sh versions +.b af_packet +is a new feature in linux 2.2. +earlier linux versions supported only +.br sock_packet . +.sh notes +for portable programs it is suggested to use +.b af_packet +via +.br pcap (3); +although this covers only a subset of the +.b af_packet +features. +.pp +the +.b sock_dgram +packet sockets make no attempt to create or parse the ieee 802.2 llc +header for a ieee 802.3 frame. +when +.b eth_p_802_3 +is specified as protocol for sending the kernel creates the +802.3 frame and fills out the length field; the user has to supply the llc +header to get a fully conforming packet. +incoming 802.3 packets are not multiplexed on the dsap/ssap protocol +fields; instead they are supplied to the user as protocol +.b eth_p_802_2 +with the llc header prefixed. +it is thus not possible to bind to +.br eth_p_802_3 ; +bind to +.b eth_p_802_2 +instead and do the protocol multiplex yourself. +the default for sending is the standard ethernet dix +encapsulation with the protocol filled in. +.pp +packet sockets are not subject to the input or output firewall chains. +.ss compatibility +in linux 2.0, the only way to get a packet socket was with the call: +.pp + socket(af_inet, sock_packet, protocol) +.pp +this is still supported, but deprecated and strongly discouraged. +the main difference between the two methods is that +.b sock_packet +uses the old +.i struct sockaddr_pkt +to specify an interface, which doesn't provide physical-layer +independence. +.pp +.in +4n +.ex +struct sockaddr_pkt { + unsigned short spkt_family; + unsigned char spkt_device[14]; + unsigned short spkt_protocol; +}; +.ee +.in +.pp +.i spkt_family +contains +the device type, +.i spkt_protocol +is the ieee 802.3 protocol type as defined in +.i +and +.i spkt_device +is the device name as a null-terminated string, for example, eth0. +.pp +this structure is obsolete and should not be used in new code. +.sh bugs +the ieee 802.2/803.3 llc handling could be considered as a bug. +.pp +socket filters are not documented. +.pp +the +.b msg_trunc +.br recvmsg (2) +extension is an ugly hack and should be replaced by a control message. +there is currently no way to get the original destination address of +packets via +.br sock_dgram . +.\" .sh credits +.\" this man page was written by andi kleen with help from matthew wilcox. +.\" af_packet in linux 2.2 was implemented +.\" by alexey kuznetsov, based on code by alan cox and others. +.sh see also +.br socket (2), +.br pcap (3), +.br capabilities (7), +.br ip (7), +.br raw (7), +.br socket (7) +.pp +rfc\ 894 for the standard ip ethernet encapsulation. +rfc\ 1700 for the ieee 802.3 ip encapsulation. +.pp +the +.i +include file for physical-layer protocols. +.pp +the linux kernel source tree. +.ir documentation/networking/filter.rst +describes how to apply berkeley packet filters to packet sockets. +.ir tools/testing/selftests/net/psock_tpacket.c +contains example source code for all available versions of +.br packet_rx_ring +and +.br packet_tx_ring . +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/setresgid.2 + +.so man3/rpc.3 + +.\" copyright (c) 1993 michael haardt (michael@moria.de), +.\" fri apr 2 11:32:09 met dst 1993 +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.\" modified sat jul 24 17:19:57 1993 by rik faith (faith@cs.unc.edu) +.th intro 6 2007-10-23 "linux" "linux programmer's manual" +.sh name +intro \- introduction to games +.sh description +section 6 of the manual describes the games and funny little programs +available on the system. +.sh notes +.ss authors and copyright conditions +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! +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2000 manoj srivastava +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.\" minor polishing, aeb +.\" modified, 2002-06-16, mike coleman +.\" +.th hosts 5 2021-03-22 "linux" "linux programmer's manual" +.sh name +hosts \- static table lookup for hostnames +.sh synopsis +.nf +.b /etc/hosts +.fi +.sh description +this manual page describes the format of the +.i /etc/hosts +file. +this file is a simple text file that associates ip addresses +with hostnames, one line per ip address. +for each host a single +line should be present with the following information: +.rs +.pp +ip_address canonical_hostname [aliases...] +.re +.pp +the ip address can conform to either ipv4 or ipv6. +fields of the entry are separated by any number of blanks and/or +tab characters. +text from a "#" character until the end of the line is +a comment, and is ignored. +host names may contain only alphanumeric +characters, minus signs ("\-"), and periods ("."). +they must begin with an +alphabetic character and end with an alphanumeric character. +optional aliases provide for name changes, alternate spellings, +shorter hostnames, or generic hostnames (for example, +.ir localhost ). +if required, a host may have two separate entries in this file; +one for each version of the internet protocol (ipv4 and ipv6). +.pp +the berkeley internet name domain (bind) server implements the +internet name server for unix systems. +it augments or replaces the +.i /etc/hosts +file or hostname lookup, and frees a host from relying on +.i /etc/hosts +being up to date and complete. +.pp +in modern systems, even though the host table has been superseded by +dns, it is still widely used for: +.tp +.b bootstrapping +most systems have a small host table containing the name and address +information for important hosts on the local network. +this is useful +when dns is not running, for example during system bootup. +.tp +.b nis +sites that use nis use the host table as input to the nis host +database. +even though nis can be used with dns, most nis sites still +use the host table with an entry for all local hosts as a backup. +.tp +.b isolated nodes +very small sites that are isolated from the network use the host table +instead of dns. +if the local information rarely changes, and the +network is not connected to the internet, dns offers little +advantage. +.sh files +.i /etc/hosts +.sh notes +modifications to this file normally take effect immediately, +except in cases where the file is cached by applications. +.ss historical notes +rfc\ 952 gave the original format for the host table, though it has +since changed. +.pp +before the advent of dns, the host table was the only way of resolving +hostnames on the fledgling internet. +indeed, this file could be +created from the official host data base maintained at the network +information control center (nic), though local changes were often +required to bring it up to date regarding unofficial aliases and/or +unknown hosts. +the nic no longer maintains the hosts.txt files, +though looking around at the time of writing (circa 2000), there are +historical hosts.txt files on the www. +i just found three, from 92, +94, and 95. +.sh examples +.ex +# the following lines are desirable for ipv4 capable hosts +127.0.0.1 localhost + +# 127.0.1.1 is often used for the fqdn of the machine +127.0.1.1 thishost.mydomain.org thishost +192.168.1.10 foo.mydomain.org foo +192.168.1.13 bar.mydomain.org bar +146.82.138.7 master.debian.org master +209.237.226.90 www.opensource.org + +# the following lines are desirable for ipv6 capable hosts +::1 localhost ip6\-localhost ip6\-loopback +ff02::1 ip6\-allnodes +ff02::2 ip6\-allrouters +.ee +.sh see also +.br hostname (1), +.br resolver (3), +.br host.conf (5), +.br resolv.conf (5), +.br resolver (5), +.br hostname (7), +.br named (8) +.pp +internet rfc\ 952 +.\" .sh author +.\" this manual page was written by manoj srivastava , +.\" for the debian gnu/linux system. +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2012 by michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th malloc_stats 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +malloc_stats \- print memory allocation statistics +.sh synopsis +.nf +.b #include +.pp +.b void malloc_stats(void); +.fi +.sh description +the +.br malloc_stats () +function prints (on standard error) statistics about memory allocated by +.br malloc (3) +and related functions. +for each arena (allocation area), this function prints +the total amount of memory allocated +and the total number of bytes consumed by in-use allocations. +(these two values correspond to the +.i arena +and +.i uordblks +fields retrieved by +.br mallinfo (3).) +in addition, +the function prints the sum of these two statistics for all arenas, +and the maximum number of blocks and bytes that were ever simultaneously +allocated using +.br mmap (2). +.\" .sh versions +.\" available already in glibc 2.0, possibly earlier +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br malloc_stats () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +this function is a gnu extension. +.sh notes +more detailed information about memory allocations in the main arena +can be obtained using +.br mallinfo (3). +.sh see also +.br mmap (2), +.br mallinfo (3), +.br malloc (3), +.br malloc_info (3), +.br mallopt (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2014 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th inet_net_pton 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +inet_net_pton, inet_net_ntop \- internet network number conversion +.sh synopsis +.nf +.b #include +.pp +.bi "int inet_net_pton(int " af ", const char *" pres , +.bi " void *" netp ", size_t " nsize ); +.bi "char *inet_net_ntop(int " af ", const void *" netp ", int " bits , +.bi " char *" pres ", size_t " psize ); +.fi +.pp +link with \fi\-lresolv\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br inet_net_pton (), +.br inet_net_ntop (): +.nf + since glibc 2.20: + _default_source + before glibc 2.20: + _bsd_source || _svid_source +.fi +.sh description +these functions convert network numbers between +presentation (i.e., printable) format and network (i.e., binary) format. +.pp +for both functions, +.i af +specifies the address family for the conversion; +the only supported value is +.br af_inet . +.ss inet_net_pton() +the +.br inet_net_pton () +function converts +.ir pres , +a null-terminated string containing an internet network number in +presentation format to network format. +the result of the conversion, which is in network byte order, +is placed in the buffer pointed to by +.ir net . +(the +.i netp +argument typically points to an +.i in_addr +structure.) +the +.i nsize +argument specifies the number of bytes available in +.ir netp . +.pp +on success, +.br inet_net_pton () +returns the number of bits in the network number field +of the result placed in +.ir netp . +for a discussion of the input presentation format and the return value, +see notes. +.pp +.ir note : +the buffer pointed to by +.i netp +should be zeroed out before calling +.br inet_net_pton (), +since the call writes only as many bytes as are required +for the network number (or as are explicitly specified by +.ir pres ), +which may be less than the number of bytes in a complete network address. +.ss inet_net_ntop() +the +.br inet_net_ntop () +function converts the network number in the buffer pointed to by +.ir netp +to presentation format; +.i *netp +is interpreted as a value in network byte order. +the +.i bits +argument specifies the number of bits in the network number in +.ir *netp . +.pp +the null-terminated presentation-format string +is placed in the buffer pointed to by +.ir pres . +the +.i psize +argument specifies the number of bytes available in +.ir pres . +the presentation string is in cidr format: +a dotted-decimal number representing the network address, +followed by a slash, and the size of the network number in bits. +.sh return value +on success, +.br inet_net_pton () +returns the number of bits in the network number. +on error, it returns \-1, and +.i errno +is set to indicate the error. +.pp +on success, +.br inet_net_ntop () +returns +.ir pres . +on error, it returns null, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b eafnosupport +.i af +specified a value other than +.br af_inet . +.tp +.b emsgsize +the size of the output buffer was insufficient. +.tp +.b enoent +.rb ( inet_net_pton ()) +.ir pres +was not in correct presentation format. +.sh conforming to +the +.br inet_net_pton () +and +.br inet_net_ntop () +functions are nonstandard, but widely available. +.sh notes +.ss input presentation format for inet_net_pton() +the network number may be specified either +as a hexadecimal value +or in dotted-decimal notation. +.pp +hexadecimal values are indicated by an initial "0x" or "0x". +the hexadecimal digits populate the nibbles (half octets) of the +network number from left to right in network byte order. +.\" if the hexadecimal string is short, the remaining nibbles are zeroed. +.pp +in dotted-decimal notation, up to four octets are specified, +as decimal numbers separated by dots. +thus, any of the following forms are accepted: +.pp + a.b.c.d + a.b.c + a.b + a +.pp +each part is a number in the range 0 to 255 that +populates one byte of the resulting network number, +going from left to right, in network-byte (big endian) order. +where a part is omitted, the resulting byte in the network number is zero. +.\" reading other man pages, some other implementations treat +.\" 'c' in a.b.c as a 16-bit number that populates right-most two bytes +.\" 'b' in a.b as a 24-bit number that populates right-most three bytes +.pp +for either hexadecimal or dotted-decimal format, +the network number can optionally be followed by a slash +and a number in the range 0 to 32, +which specifies the size of the network number in bits. +.ss return value of inet_net_pton() +the return value of +.br inet_net_pton () +is the number of bits in the network number field. +if the input presentation string terminates with a slash and +an explicit size value, then that size becomes the return value of +.br inet_net_pton (). +otherwise, the return value, +.ir bits , +is inferred as follows: +.ip * 3 +if the most significant byte of the network number is +greater than or equal to 240, +then +.i bits +is 32. +.ip * 3 +otherwise, +if the most significant byte of the network number is +greater than or equal to 224, +then +.i bits +is 4. +.ip * 3 +otherwise, +if the most significant byte of the network number is +greater than or equal to 192, +then +.i bits +is 24. +.ip * 3 +otherwise, +if the most significant byte of the network number is +greater than or equal to 128, +then +.i bits +is 16. +.ip * +otherwise, +.i bits +is 8. +.pp +if the resulting +.i bits +value from the above steps is greater than or equal to 8, +but the number of octets specified in the network number exceed +.ir "bits/8" , +then +.i bits +is set to 8 times the number of octets actually specified. +.sh examples +the program below demonstrates the use of +.br inet_net_pton () +and +.br inet_net_ntop (). +it uses +.br inet_net_pton () +to convert the presentation format network address provided in +its first command-line argument to binary form, displays the return value from +.br inet_net_pton (). +it then uses +.br inet_net_ntop () +to convert the binary form back to presentation format, +and displays the resulting string. +.pp +in order to demonstrate that +.br inet_net_pton () +may not write to all bytes of its +.i netp +argument, the program allows an optional second command-line argument, +a number used to initialize the buffer before +.br inet_net_pton () +is called. +as its final line of output, +the program displays all of the bytes of the buffer returned by +.br inet_net_pton () +allowing the user to see which bytes have not been touched by +.br inet_net_pton (). +.pp +an example run, showing that +.br inet_net_pton () +infers the number of bits in the network number: +.pp +.in +4n +.ex +$ \fb./a.out 193.168\fp +inet_net_pton() returned: 24 +inet_net_ntop() yielded: 193.168.0/24 +raw address: c1a80000 +.ee +.in +.pp +demonstrate that +.br inet_net_pton () +does not zero out unused bytes in its result buffer: +.pp +.in +4n +.ex +$ \fb./a.out 193.168 0xffffffff\fp +inet_net_pton() returned: 24 +inet_net_ntop() yielded: 193.168.0/24 +raw address: c1a800ff +.ee +.in +.pp +demonstrate that +.br inet_net_pton () +will widen the inferred size of the network number, +if the supplied number of bytes in the presentation +string exceeds the inferred value: +.pp +.in +4n +.ex +$ \fb./a.out 193.168.1.128\fp +inet_net_pton() returned: 32 +inet_net_ntop() yielded: 193.168.1.128/32 +raw address: c1a80180 +.ee +.in +.pp +explicitly specifying the size of the network number overrides any +inference about its size +(but any extra bytes that are explicitly specified will still be used by +.br inet_net_pton (): +to populate the result buffer): +.pp +.in +4n +.ex +$ \fb./a.out 193.168.1.128/24\fp +inet_net_pton() returned: 24 +inet_net_ntop() yielded: 193.168.1/24 +raw address: c1a80180 +.ee +.in +.ss program source +.ex +/* link with "\-lresolv" */ + +#include +#include +#include + +#define errexit(msg) do { perror(msg); exit(exit_failure); \e + } while (0) + +int +main(int argc, char *argv[]) +{ + char buf[100]; + struct in_addr addr; + int bits; + + if (argc < 2) { + fprintf(stderr, + "usage: %s presentation\-form [addr\-init\-value]\en", + argv[0]); + exit(exit_failure); + } + + /* if argv[2] is supplied (a numeric value), use it to initialize + the output buffer given to inet_net_pton(), so that we can see + that inet_net_pton() initializes only those bytes needed for + the network number. if argv[2] is not supplied, then initialize + the buffer to zero (as is recommended practice). */ + + addr.s_addr = (argc > 2) ? strtod(argv[2], null) : 0; + + /* convert presentation network number in argv[1] to binary. */ + + bits = inet_net_pton(af_inet, argv[1], &addr, sizeof(addr)); + if (bits == \-1) + errexit("inet_net_ntop"); + + printf("inet_net_pton() returned: %d\en", bits); + + /* convert binary format back to presentation, using \(aqbits\(aq + returned by inet_net_pton(). */ + + if (inet_net_ntop(af_inet, &addr, bits, buf, sizeof(buf)) == null) + errexit("inet_net_ntop"); + + printf("inet_net_ntop() yielded: %s\en", buf); + + /* display \(aqaddr\(aq in raw form (in network byte order), so we can + see bytes not displayed by inet_net_ntop(); some of those bytes + may not have been touched by inet_net_ntop(), and so will still + have any initial value that was specified in argv[2]. */ + + printf("raw address: %x\en", htonl(addr.s_addr)); + + exit(exit_success); +} +.ee +.sh see also +.br inet (3), +.br networks (5) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) andreas gruenbacher, february 2001 +.\" copyright (c) silicon graphics inc, september 2001 +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.th getxattr 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +getxattr, lgetxattr, fgetxattr \- retrieve an extended attribute value +.sh synopsis +.fam c +.nf +.b #include +.pp +.bi "ssize_t getxattr(const char *" path ", const char *" name , +.bi " void *" value ", size_t " size ); +.bi "ssize_t lgetxattr(const char *" path ", const char *" name , +.bi " void *" value ", size_t " size ); +.bi "ssize_t fgetxattr(int " fd ", const char *" name , +.bi " void *" value ", size_t " size ); +.fi +.fam t +.sh description +extended attributes are +.ir name :\c +.i value +pairs associated with inodes (files, directories, symbolic links, etc.). +they are extensions to the normal attributes which are associated +with all inodes in the system (i.e., the +.br stat (2) +data). +a complete overview of extended attributes concepts can be found in +.br xattr (7). +.pp +.br getxattr () +retrieves the value of the extended attribute identified by +.i name +and associated with the given +.i path +in the filesystem. +the attribute value is placed in the buffer pointed to by +.ir value ; +.i size +specifies the size of that buffer. +the return value of the call is the number of bytes placed in +.ir value . +.pp +.br lgetxattr () +is identical to +.br getxattr (), +except in the case of a symbolic link, where the link itself is +interrogated, not the file that it refers to. +.pp +.br fgetxattr () +is identical to +.br getxattr (), +only the open file referred to by +.i fd +(as returned by +.br open (2)) +is interrogated in place of +.ir path . +.pp +an extended attribute +.i name +is a null-terminated string. +the name includes a namespace prefix; there may be several, disjoint +namespaces associated with an individual inode. +the value of an extended attribute is a chunk of arbitrary textual or +binary data that was assigned using +.br setxattr (2). +.pp +if +.i size +is specified as zero, these calls return the current size of the +named extended attribute (and leave +.i value +unchanged). +this can be used to determine the size of the buffer that +should be supplied in a subsequent call. +(but, bear in mind that there is a possibility that the +attribute value may change between the two calls, +so that it is still necessary to check the return status +from the second call.) +.sh return value +on success, these calls return a nonnegative value which is +the size (in bytes) of the extended attribute value. +on failure, \-1 is returned and +.i errno +is set to indicate the error. +.sh errors +.tp +.b e2big +the size of the attribute value is larger than the maximum size allowed; the +attribute cannot be retrieved. +this can happen on filesystems that support +very large attribute values such as nfsv4, for example. +.tp +.b enodata +the named attribute does not exist, or the process has no access to +this attribute. +.\" .rb ( enoattr +.\" is defined to be a synonym for +.\" .br enodata +.\" in +.\" .ir .) +.tp +.b enotsup +extended attributes are not supported by the filesystem, or are disabled. +.tp +.b erange +the +.i size +of the +.i value +buffer is too small to hold the result. +.pp +in addition, the errors documented in +.br stat (2) +can also occur. +.sh versions +these system calls have been available on linux since kernel 2.4; +glibc support is provided since version 2.3. +.sh conforming to +these system calls are linux-specific. +.\" .sh authors +.\" andreas gruenbacher, +.\" .ri < a.gruenbacher@computer.org > +.\" and the sgi xfs development team, +.\" .ri < linux-xfs@oss.sgi.com >. +.\" please send any bug reports or comments to these addresses. +.sh examples +see +.br listxattr (2). +.sh see also +.br getfattr (1), +.br setfattr (1), +.br listxattr (2), +.br open (2), +.br removexattr (2), +.br setxattr (2), +.br stat (2), +.br symlink (7), +.br xattr (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2006 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th sem_post 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +sem_post \- unlock a semaphore +.sh synopsis +.nf +.b #include +.pp +.bi "int sem_post(sem_t *" sem ); +.fi +.pp +link with \fi\-pthread\fp. +.sh description +.br sem_post () +increments (unlocks) the semaphore pointed to by +.ir sem . +if the semaphore's value consequently becomes greater than zero, +then another process or thread blocked in a +.br sem_wait (3) +call will be woken up and proceed to lock the semaphore. +.sh return value +.br sem_post () +returns 0 on success; +on error, the value of the semaphore is left unchanged, +\-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b einval +.i sem +is not a valid semaphore. +.tp +.b eoverflow +.\" added in posix.1-2008 tc1 (austin interpretation 213) +the maximum allowable value for a semaphore would be exceeded. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br sem_post () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001. +.sh notes +.br sem_post () +is async-signal-safe: +it may be safely called within a signal handler. +.sh examples +see +.br sem_wait (3) +and +.br shm_open (3). +.sh see also +.br sem_getvalue (3), +.br sem_wait (3), +.br sem_overview (7), +.br signal\-safety (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/err.3 + +.so man7/uri.7 + +.so man3/bswap.3 + +.so man3/isalpha.3 + +.so man2/send.2 + +.\" copyright (c) 1993 michael haardt (michael@moria.de) +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.\" created 1993-04-02 by michael haardt (michael@moria.de) +.\" modified 1993-07-24 by rik faith (faith@cs.unc.edu) +.\" modified 1994-05-15 by daniel quinlan (quinlan@yggdrasil.com) +.\" modified 1994-11-22 by daniel quinlan (quinlan@yggdrasil.com) +.\" modified 1995-07-11 by daniel quinlan (quinlan@yggdrasil.com) +.\" modified 1996-12-18 by michael haardt and aeb +.\" modified 1999-05-31 by dimitri papadopoulos (dpo@club-internet.fr) +.\" modified 1999-08-08 by michael haardt (michael@moria.de) +.\" modified 2004-04-01 by aeb +.\" +.th ascii 7 2020-06-09 "linux" "linux programmer's manual" +.sh name +ascii \- ascii character set encoded in octal, decimal, +and hexadecimal +.sh description +ascii is the american standard code for information interchange. +it is a 7-bit code. +many 8-bit codes (e.g., iso 8859-1) contain ascii as their lower half. +the international counterpart of ascii is known as iso 646-irv. +.pp +the following table contains the 128 ascii characters. +.pp +c program \f(cw\(aq\ex\(aq\fp escapes are noted. +.if t \{\ +.ft cw +\} +.ts +l l l l | l l l l. +oct dec hex char oct dec hex char +_ +000 0 00 nul \(aq\e0\(aq (null character) 100 64 40 @ +001 1 01 soh (start of heading) 101 65 41 a +002 2 02 stx (start of text) 102 66 42 b +003 3 03 etx (end of text) 103 67 43 c +004 4 04 eot (end of transmission) 104 68 44 d +005 5 05 enq (enquiry) 105 69 45 e +006 6 06 ack (acknowledge) 106 70 46 f +007 7 07 bel \(aq\ea\(aq (bell) 107 71 47 g +010 8 08 bs \(aq\eb\(aq (backspace) 110 72 48 h +011 9 09 ht \(aq\et\(aq (horizontal tab) 111 73 49 i +012 10 0a lf \(aq\en\(aq (new line) 112 74 4a j +013 11 0b vt \(aq\ev\(aq (vertical tab) 113 75 4b k +014 12 0c ff \(aq\ef\(aq (form feed) 114 76 4c l +015 13 0d cr \(aq\er\(aq (carriage ret) 115 77 4d m +016 14 0e so (shift out) 116 78 4e n +017 15 0f si (shift in) 117 79 4f o +020 16 10 dle (data link escape) 120 80 50 p +021 17 11 dc1 (device control 1) 121 81 51 q +022 18 12 dc2 (device control 2) 122 82 52 r +023 19 13 dc3 (device control 3) 123 83 53 s +024 20 14 dc4 (device control 4) 124 84 54 t +025 21 15 nak (negative ack.) 125 85 55 u +026 22 16 syn (synchronous idle) 126 86 56 v +027 23 17 etb (end of trans. blk) 127 87 57 w +030 24 18 can (cancel) 130 88 58 x +031 25 19 em (end of medium) 131 89 59 y +032 26 1a sub (substitute) 132 90 5a z +033 27 1b esc (escape) 133 91 5b [ +034 28 1c fs (file separator) 134 92 5c \e \(aq\e\e\(aq +035 29 1d gs (group separator) 135 93 5d ] +036 30 1e rs (record separator) 136 94 5e \(ha +037 31 1f us (unit separator) 137 95 5f \&_ +040 32 20 space 140 96 60 \` +041 33 21 ! 141 97 61 a +042 34 22 " 142 98 62 b +043 35 23 # 143 99 63 c +044 36 24 $ 144 100 64 d +045 37 25 % 145 101 65 e +046 38 26 & 146 102 66 f +047 39 27 \(aq 147 103 67 g +050 40 28 ( 150 104 68 h +051 41 29 ) 151 105 69 i +052 42 2a * 152 106 6a j +053 43 2b + 153 107 6b k +054 44 2c , 154 108 6c l +055 45 2d \- 155 109 6d m +056 46 2e . 156 110 6e n +057 47 2f / 157 111 6f o +060 48 30 0 160 112 70 p +061 49 31 1 161 113 71 q +062 50 32 2 162 114 72 r +063 51 33 3 163 115 73 s +064 52 34 4 164 116 74 t +065 53 35 5 165 117 75 u +066 54 36 6 166 118 76 v +067 55 37 7 167 119 77 w +070 56 38 8 170 120 78 x +071 57 39 9 171 121 79 y +072 58 3a : 172 122 7a z +073 59 3b ; 173 123 7b { +074 60 3c < 174 124 7c | +075 61 3d = 175 125 7d } +076 62 3e > 176 126 7e \(ti +077 63 3f ? 177 127 7f del +.te +.if t \{\ +.in +.ft p +\} +.ss tables +for convenience, below are more compact tables in hex and decimal. +.pp +.nf +.if t \{\ +.in 1i +.ft cw +\} + 2 3 4 5 6 7 30 40 50 60 70 80 90 100 110 120 + ------------- --------------------------------- +0: 0 @ p \` p 0: ( 2 < f p z d n x +1: ! 1 a q a q 1: ) 3 = g q [ e o y +2: " 2 b r b r 2: * 4 > h r \e f p z +3: # 3 c s c s 3: ! + 5 ? i s ] g q { +4: $ 4 d t d t 4: " , 6 @ j t \(ha h r | +5: % 5 e u e u 5: # \- 7 a k u _ i s } +6: & 6 f v f v 6: $ . 8 b l v \` j t \(ti +7: \(aq 7 g w g w 7: % / 9 c m w a k u del +8: ( 8 h x h x 8: & 0 : d n x b l v +9: ) 9 i y i y 9: \(aq 1 ; e o y c m w +a: * : j z j z +b: + ; k [ k { +c: , < l \e l | +d: \- = m ] m } +e: . > n \(ha n \(ti +f: / ? o _ o del +.if t \{\ +.in +.ft p +\} +.fi +.sh notes +.ss history +an +.b ascii +manual page appeared in version 7 of at&t unix. +.pp +on older terminals, the underscore code is displayed as a left arrow, +called backarrow, the caret is displayed as an up-arrow and the vertical +bar has a hole in the middle. +.pp +uppercase and lowercase characters differ by just one bit and the +ascii character 2 differs from the double quote by just one bit, too. +that made it much easier to encode characters mechanically or with a +non-microcontroller-based electronic keyboard and that pairing was found +on old teletypes. +.pp +the ascii standard was published by the united states of america +standards institute (usasi) in 1968. +.\" +.\" asa was the american standards association and x3 was an asa sectional +.\" committee on computers and data processing. its name changed to +.\" american national standards committee x3 (ansc-x3) and now it is known +.\" as accredited standards committee x3 (asc x3). it is accredited by ansi +.\" and administered by iti. the subcommittee x3.2 worked on coded +.\" character sets; the task group working on ascii appears to have been +.\" designated x3.2.4. in 1966, asa became the united states of america +.\" standards institute (usasi) and published ascii in 1968. it became the +.\" american national standards institute (ansi) in 1969 and is the +.\" u.s. member body of iso; private and nonprofit. +.\" +.sh see also +.br charsets (7), +.br iso_8859\-1 (7), +.br iso_8859\-2 (7), +.br iso_8859\-3 (7), +.br iso_8859\-4 (7), +.br iso_8859\-5 (7), +.br iso_8859\-6 (7), +.br iso_8859\-7 (7), +.br iso_8859\-8 (7), +.br iso_8859\-9 (7), +.br iso_8859\-10 (7), +.br iso_8859\-11 (7), +.br iso_8859\-13 (7), +.br iso_8859\-14 (7), +.br iso_8859\-15 (7), +.br iso_8859\-16 (7), +.br utf\-8 (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/ctime.3 + +.\" copyright (c) 1992 drew eckhardt (drew@cs.colorado.edu), march 28, 1992 +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified by michael haardt +.\" modified by thomas koenig +.\" modified 1993-07-23 by rik faith +.\" modified 1993-07-25 by rik faith +.\" modified 1995-11-01 by michael haardt +.\" +.\" modified 1996-04-14 by andries brouwer +.\" [added some polishing contributed by mike battersby ] +.\" modified 1996-07-21 by andries brouwer +.\" modified 1997-01-17 by andries brouwer +.\" modified 2001-12-18 by andries brouwer +.\" modified 2002-07-24 by michael kerrisk +.\" added note on historical rules enforced when an unprivileged process +.\" sends a signal. +.\" modified 2004-06-16 by michael kerrisk +.\" added note on cap_kill +.\" modified 2004-06-24 by aeb +.\" modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr +.\" +.th kill 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +kill \- send signal to a process +.sh synopsis +.nf +.b #include +.pp +.bi "int kill(pid_t " pid ", int " sig ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br kill (): +.nf + _posix_c_source +.fi +.sh description +the +.br kill () +system call +can be used to send any signal to any process group or process. +.pp +if \fipid\fp is positive, then signal \fisig\fp is sent to the +process with the id specified by \fipid\fp. +.pp +if \fipid\fp equals 0, then \fisig\fp is sent to every process in the +process group of the calling process. +.pp +if \fipid\fp equals \-1, then \fisig\fp is sent to every process +for which the calling process has permission to send signals, +except for process 1 (\fiinit\fp), but see below. +.pp +if \fipid\fp is less than \-1, then \fisig\fp is sent to every process +in the process group whose id is \fi\-pid\fp. +.pp +if \fisig\fp is 0, then no signal is sent, +but existence and permission checks are still performed; +this can be used to check for the existence of a process id or +process group id that the caller is permitted to signal. +.pp +for a process to have permission to send a signal, +it must either be privileged (under linux: have the +.b cap_kill +capability in the user namespace of the target process), +or the real or effective user id of the sending process must equal +the real or saved set-user-id of the target process. +in the case of +.br sigcont , +it suffices when the sending and receiving +processes belong to the same session. +(historically, the rules were different; see notes.) +.sh return value +on success (at least one signal was sent), zero is returned. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b einval +an invalid signal was specified. +.tp +.b eperm +the calling process does not have permission to send the signal +to any of the target processes. +.tp +.b esrch +the target process or process group does not exist. +note that an existing process might be a zombie, +a process that has terminated execution, but +has not yet been +.br wait (2)ed +for. +.sh conforming to +posix.1-2001, posix.1-2008, svr4, 4.3bsd. +.sh notes +the only signals that can be sent to process id 1, the +.i init +process, are those for which +.i init +has explicitly installed signal handlers. +this is done to assure the +system is not brought down accidentally. +.pp +posix.1 requires that \fikill(\-1,sig)\fp send \fisig\fp +to all processes that the calling process may send signals to, +except possibly for some implementation-defined system processes. +linux allows a process to signal itself, but on linux the call +\fikill(\-1,sig)\fp does not signal the calling process. +.pp +posix.1 requires that if a process sends a signal to itself, +and the sending thread does not have the signal blocked, +and no other thread +has it unblocked or is waiting for it in +.br sigwait (3), +at least one +unblocked signal must be delivered to the sending thread before the +.br kill () +returns. +.ss linux notes +across different kernel versions, linux has enforced different rules +for the permissions required for an unprivileged process +to send a signal to another process. +.\" in the 0.* kernels things chopped and changed quite +.\" a bit - mtk, 24 jul 02 +in kernels 1.0 to 1.2.2, a signal could be sent if the +effective user id of the sender matched effective user id of the target, +or the real user id of the sender matched the real user id of the target. +from kernel 1.2.3 until 1.3.77, a signal could be sent if the +effective user id of the sender matched either the real or effective +user id of the target. +the current rules, which conform to posix.1, were adopted +in kernel 1.3.78. +.sh bugs +in 2.6 kernels up to and including 2.6.7, +there was a bug that meant that when sending signals to a process group, +.br kill () +failed with the error +.b eperm +if the caller did not have permission to send the signal to \fiany\fp (rather +than \fiall\fp) of the members of the process group. +notwithstanding this error return, the signal was still delivered +to all of the processes for which the caller had permission to signal. +.sh see also +.br kill (1), +.br _exit (2), +.br pidfd_send_signal (2), +.br signal (2), +.br tkill (2), +.br exit (3), +.br killpg (3), +.br sigqueue (3), +.br capabilities (7), +.br credentials (7), +.br signal (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sat jul 24 21:29:05 1993 by rik faith (faith@cs.unc.edu) +.\" modified thu jul 26 14:06:20 2001 by andries brouwer (aeb@cwi.nl) +.\" +.th byteorder 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +htonl, htons, ntohl, ntohs \- convert values between host and network +byte order +.sh synopsis +.nf +.b #include +.pp +.bi "uint32_t htonl(uint32_t " hostlong ); +.bi "uint16_t htons(uint16_t " hostshort ); +.pp +.bi "uint32_t ntohl(uint32_t " netlong ); +.bi "uint16_t ntohs(uint16_t " netshort ); +.fi +.sh description +the +.br htonl () +function converts the unsigned integer +.i hostlong +from host byte order to network byte order. +.pp +the +.br htons () +function converts the unsigned short integer +.i hostshort +from host byte order to network byte order. +.pp +the +.br ntohl () +function converts the unsigned integer +.i netlong +from network byte order to host byte order. +.pp +the +.br ntohs () +function converts the unsigned short integer +.i netshort +from network byte order to host byte order. +.pp +on the i386 the host byte order is least significant byte first, +whereas the network byte order, as used on the internet, is most +significant byte first. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br htonl (), +.br htons (), +.br ntohl (), +.br ntohs () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.pp +some systems require the inclusion of +.i +instead of +.ir . +.sh see also +.br bswap (3), +.br endian (3), +.br gethostbyname (3), +.br getservent (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) bruno haible +.\" and copyright 2014 michael kerrisk +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th mbstowcs 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +mbstowcs \- convert a multibyte string to a wide-character string +.sh synopsis +.nf +.b #include +.pp +.bi "size_t mbstowcs(wchar_t *restrict " dest ", const char *restrict " src , +.bi " size_t " n ); +.fi +.sh description +if +.i dest +is not null, +the +.br mbstowcs () +function converts the +multibyte string +.i src +to a wide-character string starting at +.ir dest . +at most +.i n +wide characters are written to +.ir dest . +the sequence of characters in the string +.i src +shall begin in the initial shift state. +the conversion can stop for three reasons: +.ip 1. 3 +an invalid multibyte sequence has been encountered. +in this case, +.i (size_t)\ \-1 +is returned. +.ip 2. +.i n +non-l\(aq\e0\(aq wide characters have been stored at +.ir dest . +in this case, the number of wide characters written to +.i dest +is returned, but the +shift state at this point is lost. +.ip 3. +the multibyte string has been completely converted, including the +terminating null character (\(aq\e0\(aq). +in this case, the number of wide characters written to +.ir dest , +excluding the terminating null wide character, is returned. +.pp +the programmer must ensure that there is room for at least +.i n +wide +characters at +.ir dest . +.pp +if +.ir dest +is null, +.i n +is ignored, and the conversion proceeds as +above, except that the converted wide characters are not written out to memory, +and that no length limit exists. +.pp +in order to avoid the case 2 above, the programmer should make sure +.i n +is +greater than or equal to +.ir "mbstowcs(null,src,0)+1" . +.sh return value +the +.br mbstowcs () +function returns the number of wide characters that make +up the converted part of the wide-character string, not including the +terminating null wide character. +if an invalid multibyte sequence was +encountered, +.i (size_t)\ \-1 +is returned. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br mbstowcs () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh notes +the behavior of +.br mbstowcs () +depends on the +.b lc_ctype +category of the +current locale. +.pp +the function +.br mbsrtowcs (3) +provides a better interface to the same +functionality. +.sh examples +the program below illustrates the use of +.br mbstowcs (), +as well as some of the wide character classification functions. +an example run is the following: +.pp +.in +4n +.ex +$ ./t_mbstowcs de_de.utf\-8 grüße! +length of source string (excluding terminator): + 8 bytes + 6 multibyte characters + +wide character string is: grüße! (6 characters) + g alpha upper + r alpha lower + ü alpha lower + ß alpha lower + e alpha lower + ! !alpha +.ee +.in +.ss program source +\& +.ex +#include +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + size_t mbslen; /* number of multibyte characters in source */ + wchar_t *wcs; /* pointer to converted wide character string */ + + if (argc < 3) { + fprintf(stderr, "usage: %s \en", argv[0]); + exit(exit_failure); + } + + /* apply the specified locale. */ + + if (setlocale(lc_all, argv[1]) == null) { + perror("setlocale"); + exit(exit_failure); + } + + /* calculate the length required to hold argv[2] converted to + a wide character string. */ + + mbslen = mbstowcs(null, argv[2], 0); + if (mbslen == (size_t) \-1) { + perror("mbstowcs"); + exit(exit_failure); + } + + /* describe the source string to the user. */ + + printf("length of source string (excluding terminator):\en"); + printf(" %zu bytes\en", strlen(argv[2])); + printf(" %zu multibyte characters\en\en", mbslen); + + /* allocate wide character string of the desired size. add 1 + to allow for terminating null wide character (l\(aq\e0\(aq). */ + + wcs = calloc(mbslen + 1, sizeof(*wcs)); + if (wcs == null) { + perror("calloc"); + exit(exit_failure); + } + + /* convert the multibyte character string in argv[2] to a + wide character string. */ + + if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) { + perror("mbstowcs"); + exit(exit_failure); + } + + printf("wide character string is: %ls (%zu characters)\en", + wcs, mbslen); + + /* now do some inspection of the classes of the characters in + the wide character string. */ + + for (wchar_t *wp = wcs; *wp != 0; wp++) { + printf(" %lc ", (wint_t) *wp); + + if (!iswalpha(*wp)) + printf("!"); + printf("alpha "); + + if (iswalpha(*wp)) { + if (iswupper(*wp)) + printf("upper "); + + if (iswlower(*wp)) + printf("lower "); + } + + putchar(\(aq\en\(aq); + } + + exit(exit_success); +} +.ee +.sh see also +.br mblen (3), +.br mbsrtowcs (3), +.br mbtowc (3), +.br wcstombs (3), +.br wctomb (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/outb.2 + +.\" copyright (c) 2003 andries brouwer (aeb@cwi.nl) +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.th posixoptions 7 2021-08-27 "" "linux programmer's manual" +.sh name +posixoptions \- optional parts of the posix standard +.sh description +the posix standard (the information below is from posix.1-2001) +describes a set of behaviors and interfaces for a compliant system. +however, many interfaces are optional and there are feature test macros +to test the availability of interfaces at compile time, and functions +.br sysconf (3), +.br fpathconf (3), +.br pathconf (3), +.br confstr (3) +to do this at run time. +from shell scripts one can use +.br getconf (1). +for more detail, see +.br sysconf (3). +.pp +we give the name of the posix abbreviation, the option, the name of the +.br sysconf (3) +parameter used to inquire about the option, and possibly +a very short description. +much more precise detail can be found in the posix standard itself, +versions of which can nowadays be accessed freely on the web. +.ss adv - _posix_advisory_info - _sc_advisory_info +the following advisory functions are present: +.pp +.nf +.in +4n +.ir posix_fadvise () +.ir posix_fallocate () +.ir posix_memalign () +.ir posix_madvise () +.in +.fi +.ss aio - _posix_asynchronous_io - _sc_asynchronous_io +the header +.i +is present. +the following functions are present: +.pp +.nf +.in +4n +.ir aio_cancel () +.ir aio_error () +.ir aio_fsync () +.ir aio_read () +.ir aio_return () +.ir aio_suspend () +.ir aio_write () +.ir lio_listio () +.in +.fi +.ss bar - _posix_barriers - _sc_barriers +this option implies the +.b _posix_threads +and +.b _posix_thread_safe_functions +options. +the following functions are present: +.pp +.nf +.in +4n +.ir pthread_barrier_destroy () +.ir pthread_barrier_init () +.ir pthread_barrier_wait () +.ir pthread_barrierattr_destroy () +.ir pthread_barrierattr_init () +.in +.fi +.\" .ss be +.\" batch environment. +.\" .ss cd +.\" c development. +.ss --- - posix_chown_restricted +if this option is in effect (as it always is under posix.1-2001), +then only root may change the owner of a file, and nonroot can +set the group of a file only to one of the groups it belongs to. +this affects the following functions +.pp +.nf +.in +4n +.ir chown () +.ir fchown () +.in +.fi +.\" what about lchown() ? +.ss cs - _posix_clock_selection - _sc_clock_selection +this option implies the +.b _posix_timers +option. +the following functions are present: +.pp +.nf +.in +4n +.ir pthread_condattr_getclock () +.ir pthread_condattr_setclock () +.ir clock_nanosleep () +.in +.fi +.pp +if +.b clock_realtime +is changed by the function +.ir clock_settime (), +then this affects all timers set for an absolute time. +.ss cpt - _posix_cputime - _sc_cputime +the +.b clock_process_cputime_id +clock id is supported. +the initial value of this clock is 0 for each process. +this option implies the +.b _posix_timers +option. +the function +.ir clock_getcpuclockid () +is present. +.\" .ss fd +.\" fortran development +.\" .ss fr +.\" fortran runtime +.ss --- - _posix_file_locking - _sc_file_locking +this option has been deleted. +not in final xpg6. +.ss fsc - _posix_fsync - _sc_fsync +the function +.ir fsync () +is present. +.ss ip6 - _posix_ipv6 - _sc_ipv6 +internet protocol version 6 is supported. +.ss --- - _posix_job_control - _sc_job_control +if this option is in effect (as it always is under posix.1-2001), +then the system implements posix-style job control, +and the following functions are present: +.pp +.nf +.in +4n +.ir setpgid () +.ir tcdrain () +.ir tcflush () +.ir tcgetpgrp () +.ir tcsendbreak () +.ir tcsetattr () +.ir tcsetpgrp () +.in +.fi +.ss mf - _posix_mapped_files - _sc_mapped_files +shared memory is supported. +the include file +.i +is present. +the following functions are present: +.pp +.nf +.in +4n +.ir mmap () +.ir msync () +.ir munmap () +.in +.fi +.ss ml - _posix_memlock - _sc_memlock +shared memory can be locked into core. +the following functions are present: +.pp +.nf +.in +4n +.ir mlockall () +.ir munlockall () +.in +.fi +.ss mr/mlr - _posix_memlock_range - _sc_memlock_range +more precisely, ranges can be locked into core. +the following functions are present: +.pp +.nf +.in +4n +.ir mlock () +.ir munlock () +.in +.fi +.ss mpr - _posix_memory_protection - _sc_memory_protection +the function +.ir mprotect () +is present. +.ss msg - _posix_message_passing - _sc_message_passing +the include file +.i +is present. +the following functions are present: +.pp +.nf +.in +4n +.ir mq_close () +.ir mq_getattr () +.ir mq_notify () +.ir mq_open () +.ir mq_receive () +.ir mq_send () +.ir mq_setattr () +.ir mq_unlink () +.in +.fi +.ss mon - _posix_monotonic_clock - _sc_monotonic_clock +.b clock_monotonic +is supported. +this option implies the +.b _posix_timers +option. +the following functions are affected: +.pp +.nf +.in +4n +.ir aio_suspend () +.ir clock_getres () +.ir clock_gettime () +.ir clock_settime () +.ir timer_create () +.in +.fi +.ss --- - _posix_multi_process - _sc_multi_process +this option has been deleted. +not in final xpg6. +.\" .ss mx +.\" iec 60559 floating-point option. +.ss --- - _posix_no_trunc +if this option is in effect (as it always is under posix.1-2001), +then pathname components longer than +.b name_max +are not truncated, +but give an error. +this property may be dependent on the path prefix of the component. +.ss pio - _posix_prioritized_io - _sc_prioritized_io +this option says that one can specify priorities for asynchronous i/o. +this affects the functions +.pp +.nf +.in +4n +.ir aio_read () +.ir aio_write () +.in +.fi +.ss ps - _posix_priority_scheduling - _sc_priority_scheduling +the include file +.i +is present. +the following functions are present: +.pp +.nf +.in +4n +.ir sched_get_priority_max () +.ir sched_get_priority_min () +.ir sched_getparam () +.ir sched_getscheduler () +.ir sched_rr_get_interval () +.ir sched_setparam () +.ir sched_setscheduler () +.ir sched_yield () +.in +.fi +.pp +if also +.b _posix_spawn +is in effect, then the following functions are present: +.pp +.nf +.in +4n +.ir posix_spawnattr_getschedparam () +.ir posix_spawnattr_getschedpolicy () +.ir posix_spawnattr_setschedparam () +.ir posix_spawnattr_setschedpolicy () +.in +.fi +.ss rs - _posix_raw_sockets +raw sockets are supported. +the following functions are affected: +.pp +.nf +.in +4n +.ir getsockopt () +.ir setsockopt () +.in +.fi +.ss --- - _posix_reader_writer_locks - _sc_reader_writer_locks +this option implies the +.b _posix_threads +option. +conversely, +under posix.1-2001 the +.b _posix_threads +option implies this option. +.pp +the following functions are present: +.pp +.in +4n +.nf +.ir pthread_rwlock_destroy () +.ir pthread_rwlock_init () +.ir pthread_rwlock_rdlock () +.ir pthread_rwlock_tryrdlock () +.ir pthread_rwlock_trywrlock () +.ir pthread_rwlock_unlock () +.ir pthread_rwlock_wrlock () +.ir pthread_rwlockattr_destroy () +.ir pthread_rwlockattr_init () +.in +.fi +.ss rts - _posix_realtime_signals - _sc_realtime_signals +realtime signals are supported. +the following functions are present: +.pp +.nf +.in +4n +.ir sigqueue () +.ir sigtimedwait () +.ir sigwaitinfo () +.in +.fi +.ss --- - _posix_regexp - _sc_regexp +if this option is in effect (as it always is under posix.1-2001), +then posix regular expressions are supported +and the following functions are present: +.pp +.nf +.in +4n +.ir regcomp () +.ir regerror () +.ir regexec () +.ir regfree () +.in +.fi +.ss --- - _posix_saved_ids - _sc_saved_ids +if this option is in effect (as it always is under posix.1-2001), +then a process has a saved set-user-id and a saved set-group-id. +the following functions are affected: +.pp +.nf +.in +4n +.ir exec () +.ir kill () +.ir seteuid () +.ir setegid () +.ir setgid () +.ir setuid () +.in +.fi +.\" .ss sd +.\" software development +.ss sem - _posix_semaphores - _sc_semaphores +the include file +.i +is present. +the following functions are present: +.pp +.nf +.in +4n +.ir sem_close () +.ir sem_destroy () +.ir sem_getvalue () +.ir sem_init () +.ir sem_open () +.ir sem_post () +.ir sem_trywait () +.ir sem_unlink () +.ir sem_wait () +.in +.fi +.ss shm - _posix_shared_memory_objects - _sc_shared_memory_objects +the following functions are present: +.pp +.nf +.in +4n +.ir mmap () +.ir munmap () +.ir shm_open () +.ir shm_unlink () +.in +.fi +.ss --- - _posix_shell - _sc_shell +if this option is in effect (as it always is under posix.1-2001), +the function +.ir system () +is present. +.ss spn - _posix_spawn - _sc_spawn +this option describes support for process creation in a context where +it is difficult or impossible to use +.ir fork (), +for example, because no mmu is present. +.pp +if +.b _posix_spawn +is in effect, then the include file +.i +and the following functions are present: +.pp +.nf +.in +4n +.ir posix_spawn () +.ir posix_spawn_file_actions_addclose () +.ir posix_spawn_file_actions_adddup2 () +.ir posix_spawn_file_actions_addopen () +.ir posix_spawn_file_actions_destroy () +.ir posix_spawn_file_actions_init () +.ir posix_spawnattr_destroy () +.ir posix_spawnattr_getsigdefault () +.ir posix_spawnattr_getflags () +.ir posix_spawnattr_getpgroup () +.ir posix_spawnattr_getsigmask () +.ir posix_spawnattr_init () +.ir posix_spawnattr_setsigdefault () +.ir posix_spawnattr_setflags () +.ir posix_spawnattr_setpgroup () +.ir posix_spawnattr_setsigmask () +.ir posix_spawnp () +.in +.fi +.pp +if also +.b _posix_priority_scheduling +is in effect, then +the following functions are present: +.pp +.nf +.in +4n +.ir posix_spawnattr_getschedparam () +.ir posix_spawnattr_getschedpolicy () +.ir posix_spawnattr_setschedparam () +.ir posix_spawnattr_setschedpolicy () +.in +.fi +.ss spi - _posix_spin_locks - _sc_spin_locks +this option implies the +.b _posix_threads +and +.b _posix_thread_safe_functions +options. +the following functions are present: +.pp +.nf +.in +4n +.ir pthread_spin_destroy () +.ir pthread_spin_init () +.ir pthread_spin_lock () +.ir pthread_spin_trylock () +.ir pthread_spin_unlock () +.in -4n +.fi +.ss ss - _posix_sporadic_server - _sc_sporadic_server +the scheduling policy +.b sched_sporadic +is supported. +this option implies the +.b _posix_priority_scheduling +option. +the following functions are affected: +.pp +.nf +.in +4n +.ir sched_setparam () +.ir sched_setscheduler () +.in +.fi +.ss sio - _posix_synchronized_io - _sc_synchronized_io +the following functions are affected: +.pp +.nf +.in +4n +.ir open () +.ir msync () +.ir fsync () +.ir fdatasync () +.in +.fi +.ss tsa - _posix_thread_attr_stackaddr - _sc_thread_attr_stackaddr +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_attr_getstack () +.ir pthread_attr_getstackaddr () +.ir pthread_attr_setstack () +.ir pthread_attr_setstackaddr () +.in +.fi +.ss tss - _posix_thread_attr_stacksize - _sc_thread_attr_stacksize +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_attr_getstack () +.ir pthread_attr_getstacksize () +.ir pthread_attr_setstack () +.ir pthread_attr_setstacksize () +.in +.fi +.ss tct - _posix_thread_cputime - _sc_thread_cputime +the clockid clock_thread_cputime_id is supported. +this option implies the +.b _posix_timers +option. +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_getcpuclockid () +.ir clock_getres () +.ir clock_gettime () +.ir clock_settime () +.ir timer_create () +.in +.fi +.ss tpi - _posix_thread_prio_inherit - _sc_thread_prio_inherit +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_mutexattr_getprotocol () +.ir pthread_mutexattr_setprotocol () +.in +.fi +.ss tpp - _posix_thread_prio_protect - _sc_thread_prio_protect +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_mutex_getprioceiling () +.ir pthread_mutex_setprioceiling () +.ir pthread_mutexattr_getprioceiling () +.ir pthread_mutexattr_getprotocol () +.ir pthread_mutexattr_setprioceiling () +.ir pthread_mutexattr_setprotocol () +.in +.fi +.ss tps - _posix_thread_priority_scheduling - _sc_thread_priority_scheduling +if this option is in effect, the different threads inside a process +can run with different priorities and/or different schedulers. +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_attr_getinheritsched () +.ir pthread_attr_getschedpolicy () +.ir pthread_attr_getscope () +.ir pthread_attr_setinheritsched () +.ir pthread_attr_setschedpolicy () +.ir pthread_attr_setscope () +.ir pthread_getschedparam () +.ir pthread_setschedparam () +.ir pthread_setschedprio () +.in +.fi +.ss tsh - _posix_thread_process_shared - _sc_thread_process_shared +the following functions are affected: +.pp +.nf +.in +4n +.ir pthread_barrierattr_getpshared () +.ir pthread_barrierattr_setpshared () +.ir pthread_condattr_getpshared () +.ir pthread_condattr_setpshared () +.ir pthread_mutexattr_getpshared () +.ir pthread_mutexattr_setpshared () +.ir pthread_rwlockattr_getpshared () +.ir pthread_rwlockattr_setpshared () +.in +.fi +.ss tsf - _posix_thread_safe_functions - _sc_thread_safe_functions +the following functions are affected: +.pp +.nf +.in +4n +.ir readdir_r () +.ir getgrgid_r () +.ir getgrnam_r () +.ir getpwnam_r () +.ir getpwuid_r () +.ir flockfile () +.ir ftrylockfile () +.ir funlockfile () +.ir getc_unlocked () +.ir getchar_unlocked () +.ir putc_unlocked () +.ir putchar_unlocked () +.ir rand_r () +.ir strerror_r () +.ir strtok_r () +.ir asctime_r () +.ir ctime_r () +.ir gmtime_r () +.ir localtime_r () +.in +.fi +.ss tsp - _posix_thread_sporadic_server - _sc_thread_sporadic_server +this option implies the +.b _posix_thread_priority_scheduling +option. +the following functions are affected: +.pp +.nf +.in +4n +.ir sched_getparam () +.ir sched_setparam () +.ir sched_setscheduler () +.in +.fi +.ss thr - _posix_threads - _sc_threads +basic support for posix threads is available. +the following functions are present: +.pp +.nf +.in +4n +.ir pthread_atfork () +.ir pthread_attr_destroy () +.ir pthread_attr_getdetachstate () +.ir pthread_attr_getschedparam () +.ir pthread_attr_init () +.ir pthread_attr_setdetachstate () +.ir pthread_attr_setschedparam () +.ir pthread_cancel () +.ir pthread_cleanup_push () +.ir pthread_cleanup_pop () +.ir pthread_cond_broadcast () +.ir pthread_cond_destroy () +.ir pthread_cond_init () +.ir pthread_cond_signal () +.ir pthread_cond_timedwait () +.ir pthread_cond_wait () +.ir pthread_condattr_destroy () +.ir pthread_condattr_init () +.ir pthread_create () +.ir pthread_detach () +.ir pthread_equal () +.ir pthread_exit () +.ir pthread_getspecific () +.ir pthread_join () +.ir pthread_key_create () +.ir pthread_key_delete () +.ir pthread_mutex_destroy () +.ir pthread_mutex_init () +.ir pthread_mutex_lock () +.ir pthread_mutex_trylock () +.ir pthread_mutex_unlock () +.ir pthread_mutexattr_destroy () +.ir pthread_mutexattr_init () +.ir pthread_once () +.ir pthread_rwlock_destroy () +.ir pthread_rwlock_init () +.ir pthread_rwlock_rdlock () +.ir pthread_rwlock_tryrdlock () +.ir pthread_rwlock_trywrlock () +.ir pthread_rwlock_unlock () +.ir pthread_rwlock_wrlock () +.ir pthread_rwlockattr_destroy () +.ir pthread_rwlockattr_init () +.ir pthread_self () +.ir pthread_setcancelstate () +.ir pthread_setcanceltype () +.ir pthread_setspecific () +.ir pthread_testcancel () +.in +.fi +.ss tmo - _posix_timeouts - _sc_timeouts +the following functions are present: +.pp +.nf +.in +4n +.ir mq_timedreceive () +.ir mq_timedsend () +.ir pthread_mutex_timedlock () +.ir pthread_rwlock_timedrdlock () +.ir pthread_rwlock_timedwrlock () +.ir sem_timedwait () +.ir posix_trace_timedgetnext_event () +.in +.fi +.ss tmr - _posix_timers - _sc_timers +the following functions are present: +.pp +.nf +.in +4n +.ir clock_getres () +.ir clock_gettime () +.ir clock_settime () +.ir nanosleep () +.ir timer_create () +.ir timer_delete () +.ir timer_gettime () +.ir timer_getoverrun () +.ir timer_settime () +.in +.fi +.ss trc - _posix_trace - _sc_trace +posix tracing is available. +the following functions are present: +.pp +.nf +.in +4n +.ir posix_trace_attr_destroy () +.ir posix_trace_attr_getclockres () +.ir posix_trace_attr_getcreatetime () +.ir posix_trace_attr_getgenversion () +.ir posix_trace_attr_getmaxdatasize () +.ir posix_trace_attr_getmaxsystemeventsize () +.ir posix_trace_attr_getmaxusereventsize () +.ir posix_trace_attr_getname () +.ir posix_trace_attr_getstreamfullpolicy () +.ir posix_trace_attr_getstreamsize () +.ir posix_trace_attr_init () +.ir posix_trace_attr_setmaxdatasize () +.ir posix_trace_attr_setname () +.ir posix_trace_attr_setstreamsize () +.ir posix_trace_attr_setstreamfullpolicy () +.ir posix_trace_clear () +.ir posix_trace_create () +.ir posix_trace_event () +.ir posix_trace_eventid_equal () +.ir posix_trace_eventid_get_name () +.ir posix_trace_eventid_open () +.ir posix_trace_eventtypelist_getnext_id () +.ir posix_trace_eventtypelist_rewind () +.ir posix_trace_flush () +.ir posix_trace_get_attr () +.ir posix_trace_get_status () +.ir posix_trace_getnext_event () +.ir posix_trace_shutdown () +.ir posix_trace_start () +.ir posix_trace_stop () +.ir posix_trace_trygetnext_event () +.in +.fi +.ss tef - _posix_trace_event_filter - _sc_trace_event_filter +this option implies the +.b _posix_trace +option. +the following functions are present: +.pp +.nf +.in +4n +.ir posix_trace_eventset_add () +.ir posix_trace_eventset_del () +.ir posix_trace_eventset_empty () +.ir posix_trace_eventset_fill () +.ir posix_trace_eventset_ismember () +.ir posix_trace_get_filter () +.ir posix_trace_set_filter () +.ir posix_trace_trid_eventid_open () +.in +.fi +.ss tri - _posix_trace_inherit - _sc_trace_inherit +tracing children of the traced process is supported. +this option implies the +.b _posix_trace +option. +the following functions are present: +.pp +.nf +.in +4n +.ir posix_trace_attr_getinherited () +.ir posix_trace_attr_setinherited () +.in +.fi +.ss trl - _posix_trace_log - _sc_trace_log +this option implies the +.b _posix_trace +option. +the following functions are present: +.pp +.nf +.in +4n +.ir posix_trace_attr_getlogfullpolicy () +.ir posix_trace_attr_getlogsize () +.ir posix_trace_attr_setlogfullpolicy () +.ir posix_trace_attr_setlogsize () +.ir posix_trace_close () +.ir posix_trace_create_withlog () +.ir posix_trace_open () +.ir posix_trace_rewind () +.in +.fi +.ss tym - _posix_typed_memory_objects - _sc_typed_memory_object +the following functions are present: +.pp +.nf +.in +4n +.ir posix_mem_offset () +.ir posix_typed_mem_get_info () +.ir posix_typed_mem_open () +.in +.fi +.ss --- - _posix_vdisable +always present (probably 0). +value to set a changeable special control +character to indicate that it is disabled. +.sh x/open system interface extensions +.ss xsi - _xopen_crypt - _sc_xopen_crypt +the following functions are present: +.pp +.nf +.in +4n +.ir crypt () +.ir encrypt () +.ir setkey () +.fi +.ss xsi - _xopen_realtime - _sc_xopen_realtime +this option implies the following options: +.pp +.pd 0 +.tp +.br _posix_asynchronous_io == 200112l +.tp +.b _posix_fsync +.tp +.b _posix_mapped_files +.tp +.br _posix_memlock == 200112l +.tp +.br _posix_memlock_range == 200112l +.tp +.b _posix_memory_protection +.tp +.br _posix_message_passing == 200112l +.tp +.b _posix_prioritized_io +.tp +.br _posix_priority_scheduling == 200112l +.tp +.br _posix_realtime_signals == 200112l +.tp +.br _posix_semaphores == 200112l +.tp +.br _posix_shared_memory_objects == 200112l +.tp +.br _posix_synchronized_io == 200112l +.tp +.br _posix_timers == 200112l +.pd +.\" +.ss adv - --- - --- +the advanced realtime option group implies that the following options +are all defined to 200112l: +.pp +.pd 0 +.tp +.b _posix_advisory_info +.tp +.b _posix_clock_selection +(implies +.br _posix_timers ) +.tp +.b _posix_cputime +(implies +.br _posix_timers ) +.tp +.b _posix_monotonic_clock +(implies +.br _posix_timers ) +.tp +.b _posix_spawn +.tp +.b _posix_sporadic_server +(implies +.br _posix_priority_scheduling ) +.tp +.b _posix_timeouts +.tp +.b _posix_typed_memory_objects +.pd +.\" +.ss xsi - _xopen_realtime_threads - _sc_xopen_realtime_threads +this option implies that the following options +are all defined to 200112l: +.pp +.pd 0 +.tp +.b _posix_thread_prio_inherit +.tp +.b _posix_thread_prio_protect +.tp +.b _posix_thread_priority_scheduling +.pd +.ss advanced realtime threads - --- - --- +this option implies that the following options +are all defined to 200112l: +.pp +.pd 0 +.tp +.b _posix_barriers +(implies +.br _posix_threads , +.br _posix_thread_safe_functions ) +.tp +.b _posix_spin_locks +(implies +.br _posix_threads , +.br _posix_thread_safe_functions ) +.tp +.b _posix_thread_cputime +(implies +.br _posix_timers ) +.tp +.b _posix_thread_sporadic_server +(implies +.br _posix_thread_priority_scheduling ) +.pd +.\" +.ss tracing - --- - --- +this option implies that the following options +are all defined to 200112l: +.pp +.pd 0 +.tp +.b _posix_trace +.tp +.b _posix_trace_event_filter +.tp +.b _posix_trace_log +.tp +.b _posix_trace_inherit +.pd +.ss streams - _xopen_streams - _sc_xopen_streams +the following functions are present: +.pp +.nf +.in +4n +.ir fattach () +.ir fdetach () +.ir getmsg () +.ir getpmsg () +.ir ioctl () +.ir isastream () +.ir putmsg () +.ir putpmsg () +.in +.fi +.ss xsi - _xopen_legacy - _sc_xopen_legacy +functions included in the legacy option group were previously mandatory, +but are now optional in this version. +the following functions are present: +.pp +.nf +.in +4n +.ir bcmp () +.ir bcopy () +.ir bzero () +.ir ecvt () +.ir fcvt () +.ir ftime () +.ir gcvt () +.ir getwd () +.ir index () +.ir mktemp () +.ir rindex () +.ir utimes () +.ir wcswcs () +.in +.fi +.ss xsi - _xopen_unix - _sc_xopen_unix +the following functions are present: +.pp +.nf +.in +4n +.ir mmap () +.ir munmap () +.ir msync () +.in +.fi +.pp +this option implies the following options: +.pp +.pd 0 +.tp +.b _posix_fsync +.tp +.b _posix_mapped_files +.tp +.b _posix_memory_protection +.tp +.b _posix_thread_attr_stackaddr +.tp +.b _posix_thread_attr_stacksize +.tp +.b _posix_thread_process_shared +.tp +.b _posix_thread_safe_functions +.tp +.b _posix_threads +.pd +.pp +this option may imply the following options from the xsi option groups: +.pp +.pd 0 +.tp +.rb "encryption (" _xopen_crypt ) +.tp +.rb "realtime (" _xopen_realtime ) +.tp +.rb "advanced realtime (" adb ) +.tp +.rb "realtime threads (" _xopen_realtime_threads ) +.tp +.rb "advanced realtime threads (" "advanced realtime threads" ) +.tp +.rb "tracing (" tracing ) +.tp +.rb "xsi streams (" streams ) +.tp +.rb "legacy (" _xopen_legacy ) +.pd +.sh see also +.br sysconf (3), +.br standards (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 2009 intel corporation +.\" author: andi kleen +.\" based on the move_pages manpage which was +.\" this manpage is copyright (c) 2006 silicon graphics, inc. +.\" christoph lameter +.\" +.\" %%%license_start(verbatim_two_para) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" %%%license_end +.\" +.th migrate_pages 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +migrate_pages \- move all pages in a process to another set of nodes +.sh synopsis +.nf +.b #include +.pp +.bi "long migrate_pages(int " pid ", unsigned long " maxnode, +.bi " const unsigned long *" old_nodes, +.bi " const unsigned long *" new_nodes ); +.fi +.pp +.ir note : +there is no glibc wrapper for this system call; see notes. +.pp +link with \fi\-lnuma\fp. +.sh description +.br migrate_pages () +attempts to move all pages of the process +.i pid +that are in memory nodes +.i old_nodes +to the memory nodes in +.ir new_nodes . +pages not located in any node in +.i old_nodes +will not be migrated. +as far as possible, +the kernel maintains the relative topology relationship inside +.i old_nodes +during the migration to +.ir new_nodes . +.pp +the +.i old_nodes +and +.i new_nodes +arguments are pointers to bit masks of node numbers, with up to +.i maxnode +bits in each mask. +these masks are maintained as arrays of unsigned +.i long +integers (in the last +.i long +integer, the bits beyond those specified by +.i maxnode +are ignored). +the +.i maxnode +argument is the maximum node number in the bit mask plus one (this is the same +as in +.br mbind (2), +but different from +.br select (2)). +.pp +the +.i pid +argument is the id of the process whose pages are to be moved. +to move pages in another process, +the caller must be privileged +.rb ( cap_sys_nice ) +or the real or effective user id of the calling process must match the +real or saved-set user id of the target process. +if +.i pid +is 0, then +.br migrate_pages () +moves pages of the calling process. +.pp +pages shared with another process will be moved only if the initiating +process has the +.b cap_sys_nice +privilege. +.sh return value +on success +.br migrate_pages () +returns the number of pages that could not be moved +(i.e., a return of zero means that all pages were successfully moved). +on error, it returns \-1, and sets +.i errno +to indicate the error. +.sh errors +.tp +.b efault +part or all of the memory range specified by +.ir old_nodes / new_nodes +and +.i maxnode +points outside your accessible address space. +.tp +.b einval +the value specified by +.i maxnode +exceeds a kernel-imposed limit. +.\" as at 3.5, this limit is "a page worth of bits", e.g., +.\" 8 * 4096 bits, assuming a 4kb page size. +or, +.i old_nodes +or +.i new_nodes +specifies one or more node ids that are +greater than the maximum supported node id. +or, none of the node ids specified by +.i new_nodes +are on-line and allowed by the process's current cpuset context, +or none of the specified nodes contain memory. +.tp +.b eperm +insufficient privilege +.rb ( cap_sys_nice ) +to move pages of the process specified by +.ir pid , +or insufficient privilege +.rb ( cap_sys_nice ) +to access the specified target nodes. +.tp +.b esrch +no process matching +.i pid +could be found. +.\" fixme document the other errors that can occur for migrate_pages() +.sh versions +the +.br migrate_pages () +system call first appeared on linux in version 2.6.16. +.sh conforming to +this system call is linux-specific. +.sh notes +glibc does not provide a wrapper for this system call. +for information on library support, see +.br numa (7). +.pp +use +.br get_mempolicy (2) +with the +.b mpol_f_mems_allowed +flag to obtain the set of nodes that are allowed by +the calling process's cpuset. +note that this information is subject to change at any +time by manual or automatic reconfiguration of the cpuset. +.pp +use of +.br migrate_pages () +may result in pages whose location +(node) violates the memory policy established for the +specified addresses (see +.br mbind (2)) +and/or the specified process (see +.br set_mempolicy (2)). +that is, memory policy does not constrain the destination +nodes used by +.br migrate_pages (). +.pp +the +.i +header is not included with glibc, but requires installing +.i libnuma\-devel +or a similar package. +.sh see also +.br get_mempolicy (2), +.br mbind (2), +.br set_mempolicy (2), +.br numa (3), +.br numa_maps (5), +.br cpuset (7), +.br numa (7), +.br migratepages (8), +.br numastat (8) +.pp +.ir documentation/vm/page_migration.rst +in the linux kernel source tree +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2006 by michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th fcloseall 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +fcloseall \- close all open streams +.sh synopsis +.nf +.br "#define _gnu_source" " /* see feature_test_macros(7) */" +.b #include +.pp +.b int fcloseall(void); +.fi +.sh description +the +.br fcloseall () +function closes all of the calling process's open streams. +buffered output for each stream is written before it is closed +(as for +.br fflush (3)); +buffered input is discarded. +.pp +the standard streams, +.ir stdin , +.ir stdout , +and +.i stderr +are also closed. +.sh return value +this function returns 0 if all files were successfully closed; +on error, +.b eof +is returned. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br fcloseall () +t} thread safety mt-unsafe race:streams +.te +.hy +.ad +.sp 1 +.pp +the +.br fcloseall () +function does not lock the streams, so it is not thread-safe. +.sh conforming to +this function is a gnu extension. +.sh see also +.br close (2), +.br fclose (3), +.br fflush (3), +.br fopen (3), +.br setbuf (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/lrint.3 + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th wcsrchr 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +wcsrchr \- search a wide character in a wide-character string +.sh synopsis +.nf +.b #include +.pp +.bi "wchar_t *wcsrchr(const wchar_t *" wcs ", wchar_t " wc ); +.fi +.sh description +the +.br wcsrchr () +function is the wide-character equivalent +of the +.br strrchr (3) +function. +it searches the last occurrence of +.i wc +in the wide-character +string pointed to by +.ir wcs . +.sh return value +the +.br wcsrchr () +function returns a pointer to the last occurrence of +.i wc +in the wide-character string pointed to by +.ir wcs , +or null if +.i wc +does not occur in the string. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br wcsrchr () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh see also +.br strrchr (3), +.br wcschr (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-9.7 + +.\" copyright (c) 2009 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_kill_other_threads_np 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_kill_other_threads_np \- terminate all other threads in process +.sh synopsis +.nf +.b #include +.pp +.b void pthread_kill_other_threads_np(void); +.fi +.sh description +.br pthread_kill_other_threads_np () +has an effect only in the linuxthreads threading implementation. +on that implementation, +calling this function causes the immediate termination of +all threads in the application, +except the calling thread. +the cancellation state and cancellation type of the +to-be-terminated threads are ignored, +and the cleanup handlers are not called in those threads. +.\" .sh versions +.\" available since glibc 2.0 +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_kill_other_threads_np () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +this function is a nonstandard gnu extension; +hence the suffix "_np" (nonportable) in the name. +.sh notes +.br pthread_kill_other_threads_np () +is intended to be called just before a thread calls +.br execve (2) +or a similar function. +this function is designed to address a limitation in the obsolete +linuxthreads implementation whereby the other threads of an application +are not automatically terminated (as posix.1-2001 requires) during +.br execve (2). +.pp +in the nptl threading implementation, +.br pthread_kill_other_threads_np () +exists, but does nothing. +(nothing needs to be done, +because the implementation does the right thing during an +.br execve (2).) +.sh see also +.br execve (2), +.br pthread_cancel (3), +.br pthread_setcancelstate (3), +.br pthread_setcanceltype (3), +.br pthreads (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/infinity.3 + +.so man3/makedev.3 + +.so man7/system_data_types.7 + +.so man3/stailq.3 + +.so man3/y0.3 + +.so man3/termios.3 + +.so man3/posix_spawn.3 + +.so man3/byteorder.3 + +.\" copyright (c) 2008 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_self 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_self \- obtain id of the calling thread +.sh synopsis +.nf +.b #include +.pp +.b pthread_t pthread_self(void); +.pp +compile and link with \fi\-pthread\fp. +.fi +.sh description +the +.br pthread_self () +function returns the id of the calling thread. +this is the same value that is returned in +.ir *thread +in the +.br pthread_create (3) +call that created this thread. +.sh return value +this function always succeeds, returning the calling thread's id. +.sh errors +this function always succeeds. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_self () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +posix.1 allows an implementation wide freedom in choosing +the type used to represent a thread id; +for example, representation using either an arithmetic type or +a structure is permitted. +therefore, variables of type +.i pthread_t +can't portably be compared using the c equality operator (\fb==\fp); +use +.br pthread_equal (3) +instead. +.pp +thread identifiers should be considered opaque: +any attempt to use a thread id other than in pthreads calls +is nonportable and can lead to unspecified results. +.pp +thread ids are guaranteed to be unique only within a process. +a thread id may be reused after a terminated thread has been joined, +or a detached thread has terminated. +.pp +the thread id returned by +.br pthread_self () +is not the same thing as the kernel thread id returned by a call to +.br gettid (2). +.sh see also +.br pthread_create (3), +.br pthread_equal (3), +.br pthreads (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/slist.3 + +.so man3/isalpha.3 + +.so man3/tanh.3 + +.so man3/envz_add.3 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sun jul 25 10:41:28 1993 by rik faith (faith@cs.unc.edu) +.th strxfrm 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +strxfrm \- string transformation +.sh synopsis +.nf +.b #include +.pp +.bi "size_t strxfrm(char *restrict " dest ", const char *restrict " src , +.bi " size_t " n ); +.fi +.sh description +the +.br strxfrm () +function transforms the +.i src +string into a +form such that the result of +.br strcmp (3) +on two strings that have +been transformed with +.br strxfrm () +is the same as the result of +.br strcoll (3) +on the two strings before their transformation. +the first +.i n +bytes of the transformed string are placed in +.ir dest . +the transformation is based on the program's current +locale for category +.br lc_collate . +(see +.br setlocale (3)). +.sh return value +the +.br strxfrm () +function returns the number of bytes required to +store the transformed string in +.i dest +excluding the +terminating null byte (\(aq\e0\(aq). +if the value returned is +.i n +or more, the +contents of +.i dest +are indeterminate. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br strxfrm () +t} thread safety mt-safe locale +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c89, c99, svr4, 4.3bsd. +.sh see also +.br bcmp (3), +.br memcmp (3), +.br setlocale (3), +.br strcasecmp (3), +.br strcmp (3), +.br strcoll (3), +.br string (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1993 michael haardt (michael@moria.de), +.\" fri apr 2 11:32:09 met dst 1993 +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.\" modified sun jul 25 11:06:22 1993 by rik faith +.\" modified mon oct 21 17:47:19 edt 1996 by eric s. raymond +.th issue 5 1993-07-24 "linux" "linux programmer's manual" +.sh name +issue \- prelogin message and identification file +.sh description +.i /etc/issue +is a text file which contains a message or +system identification to be printed before the login prompt. +it may contain various \fb@\fp\fichar\fp and \fb\e\fp\fichar\fp +sequences, if supported by the +.br getty -type +program employed on the system. +.sh files +.i /etc/issue +.sh see also +.br motd (5), +.br agetty (8), +.br mingetty (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1992 drew eckhardt , march 28, 1992 +.\" and copyright (c) michael kerrisk, 2001, 2002, 2005, 2013, 2019 +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" may be distributed under the gnu general public license. +.\" %%%license_end +.\" +.\" modified by michael haardt +.\" modified 24 jul 1993 by rik faith +.\" modified 21 aug 1994 by michael chastain : +.\" new man page (copied from 'fork.2'). +.\" modified 10 june 1995 by andries brouwer +.\" modified 25 april 1998 by xavier leroy +.\" modified 26 jun 2001 by michael kerrisk +.\" mostly upgraded to 2.4.x +.\" added prototype for sys_clone() plus description +.\" added clone_thread with a brief description of thread groups +.\" added clone_parent and revised entire page remove ambiguity +.\" between "calling process" and "parent process" +.\" added clone_ptrace and clone_vfork +.\" added eperm and einval error codes +.\" renamed "__clone" to "clone" (which is the prototype in ) +.\" various other minor tidy ups and clarifications. +.\" modified 26 jun 2001 by michael kerrisk +.\" updated notes for 2.4.7+ behavior of clone_thread +.\" modified 15 oct 2002 by michael kerrisk +.\" added description for clone_newns, which was added in 2.4.19 +.\" slightly rephrased, aeb. +.\" modified 1 feb 2003 - added clone_sighand restriction, aeb. +.\" modified 1 jan 2004 - various updates, aeb +.\" modified 2004-09-10 - added clone_parent_settid etc. - aeb. +.\" 2005-04-12, mtk, noted the pid caching behavior of nptl's getpid() +.\" wrapper under bugs. +.\" 2005-05-10, mtk, added clone_sysvsem, clone_untraced, clone_stopped. +.\" 2005-05-17, mtk, substantially enhanced discussion of clone_thread. +.\" 2008-11-18, mtk, order clone_* flags alphabetically +.\" 2008-11-18, mtk, document clone_newpid +.\" 2008-11-19, mtk, document clone_newuts +.\" 2008-11-19, mtk, document clone_newipc +.\" 2008-11-19, jens axboe, mtk, document clone_io +.\" +.th clone 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +clone, __clone2, clone3 \- create a child process +.sh synopsis +.nf +/* prototype for the glibc wrapper function */ +.pp +.b #define _gnu_source +.b #include +.pp +.bi "int clone(int (*" "fn" ")(void *), void *" stack \ +", int " flags ", void *" "arg" ", ..." +.bi " /* pid_t *" parent_tid ", void *" tls \ +", pid_t *" child_tid " */ );" +.pp +/* for the prototype of the raw clone() system call, see notes */ +.pp +.br "#include " " /* definition of " "struct clone_args" " */" +.br "#include " " /* definition of " clone_* " constants */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "long syscall(sys_clone3, struct clone_args *" cl_args ", size_t " size ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br clone3 (), +necessitating the use of +.br syscall (2). +.sh description +these system calls +create a new ("child") process, in a manner similar to +.br fork (2). +.pp +by contrast with +.br fork (2), +these system calls provide more precise control over what pieces of execution +context are shared between the calling process and the child process. +for example, using these system calls, the caller can control whether +or not the two processes share the virtual address space, +the table of file descriptors, and the table of signal handlers. +these system calls also allow the new child process to be placed +in separate +.br namespaces (7). +.pp +note that in this manual +page, "calling process" normally corresponds to "parent process". +but see the descriptions of +.b clone_parent +and +.b clone_thread +below. +.pp +this page describes the following interfaces: +.ip * 3 +the glibc +.br clone () +wrapper function and the underlying system call on which it is based. +the main text describes the wrapper function; +the differences for the raw system call +are described toward the end of this page. +.ip * +the newer +.br clone3 () +system call. +.pp +in the remainder of this page, the terminology "the clone call" is used +when noting details that apply to all of these interfaces, +.\" +.ss the clone() wrapper function +when the child process is created with the +.br clone () +wrapper function, +it commences execution by calling the function pointed to by the argument +.ir fn . +(this differs from +.br fork (2), +where execution continues in the child from the point +of the +.br fork (2) +call.) +the +.i arg +argument is passed as the argument of the function +.ir fn . +.pp +when the +.ir fn ( arg ) +function returns, the child process terminates. +the integer returned by +.i fn +is the exit status for the child process. +the child process may also terminate explicitly by calling +.br exit (2) +or after receiving a fatal signal. +.pp +the +.i stack +argument specifies the location of the stack used by the child process. +since the child and calling process may share memory, +it is not possible for the child process to execute in the +same stack as the calling process. +the calling process must therefore +set up memory space for the child stack and pass a pointer to this +space to +.br clone (). +stacks grow downward on all processors that run linux +(except the hp pa processors), so +.i stack +usually points to the topmost address of the memory space set up for +the child stack. +note that +.br clone () +does not provide a means whereby the caller can inform the kernel of the +size of the stack area. +.pp +the remaining arguments to +.br clone () +are discussed below. +.\" +.ss clone3() +the +.br clone3 () +system call provides a superset of the functionality of the older +.br clone () +interface. +it also provides a number of api improvements, including: +space for additional flags bits; +cleaner separation in the use of various arguments; +and the ability to specify the size of the child's stack area. +.pp +as with +.br fork (2), +.br clone3 () +returns in both the parent and the child. +it returns 0 in the child process and returns the pid of the child +in the parent. +.pp +the +.i cl_args +argument of +.br clone3 () +is a structure of the following form: +.pp +.in +4n +.ex +struct clone_args { + u64 flags; /* flags bit mask */ + u64 pidfd; /* where to store pid file descriptor + (\fiint *\fp) */ + u64 child_tid; /* where to store child tid, + in child\(aqs memory (\fipid_t *\fp) */ + u64 parent_tid; /* where to store child tid, + in parent\(aqs memory (\fipid_t *\fp) */ + u64 exit_signal; /* signal to deliver to parent on + child termination */ + u64 stack; /* pointer to lowest byte of stack */ + u64 stack_size; /* size of stack */ + u64 tls; /* location of new tls */ + u64 set_tid; /* pointer to a \fipid_t\fp array + (since linux 5.5) */ + u64 set_tid_size; /* number of elements in \fiset_tid\fp + (since linux 5.5) */ + u64 cgroup; /* file descriptor for target cgroup + of child (since linux 5.7) */ +}; +.ee +.in +.pp +the +.i size +argument that is supplied to +.br clone3 () +should be initialized to the size of this structure. +(the existence of the +.i size +argument permits future extensions to the +.ir clone_args +structure.) +.pp +the stack for the child process is specified via +.ir cl_args.stack , +which points to the lowest byte of the stack area, +and +.ir cl_args.stack_size , +which specifies the size of the stack in bytes. +in the case where the +.br clone_vm +flag (see below) is specified, a stack must be explicitly allocated +and specified. +otherwise, these two fields can be specified as null and 0, +which causes the child to use the same stack area as the parent +(in the child's own virtual address space). +.pp +the remaining fields in the +.i cl_args +argument are discussed below. +.\" +.ss equivalence between clone() and clone3() arguments +unlike the older +.br clone () +interface, where arguments are passed individually, in the newer +.br clone3 () +interface the arguments are packaged into the +.i clone_args +structure shown above. +this structure allows for a superset of the information passed via the +.br clone () +arguments. +.pp +the following table shows the equivalence between the arguments of +.br clone () +and the fields in the +.i clone_args +argument supplied to +.br clone3 (): +.rs 4 +.ts +lb lb lb +l l l +li li l. +clone() clone3() notes + \ficl_args\fp field +flags & \(ti0xff flags t{ +for most flags; details below +t} +parent_tid pidfd see clone_pidfd +child_tid child_tid see clone_child_settid +parent_tid parent_tid see clone_parent_settid +flags & 0xff exit_signal +stack stack +\fp---\fp stack_size +tls tls see clone_settls +\fp---\fp set_tid see below for details +\fp---\fp set_tid_size +\fp---\fp cgroup see clone_into_cgroup +.te +.re +.\" +.ss the child termination signal +when the child process terminates, a signal may be sent to the parent. +the termination signal is specified in the low byte of +.i flags +.rb ( clone ()) +or in +.i cl_args.exit_signal +.rb ( clone3 ()). +if this signal is specified as anything other than +.br sigchld , +then the parent process must specify the +.b __wall +or +.b __wclone +options when waiting for the child with +.br wait (2). +if no signal (i.e., zero) is specified, then the parent process is not signaled +when the child terminates. +.\" +.ss the set_tid array +by default, the kernel chooses the next sequential pid for the new +process in each of the pid namespaces where it is present. +when creating a process with +.br clone3 (), +the +.i set_tid +array (available since linux 5.5) +can be used to select specific pids for the process in some +or all of the pid namespaces where it is present. +if the pid of the newly created process should be set only for the current +pid namespace or in the newly created pid namespace (if +.i flags +contains +.br clone_newpid ) +then the first element in the +.i set_tid +array has to be the desired pid and +.i set_tid_size +needs to be 1. +.pp +if the pid of the newly created process should have a certain value in +multiple pid namespaces, then the +.i set_tid +array can have multiple entries. +the first entry defines the pid in the most +deeply nested pid namespace and each of the following entries contains +the pid in the +corresponding ancestor pid namespace. +the number of pid namespaces in which a pid +should be set is defined by +.i set_tid_size +which cannot be larger than the number of currently nested pid namespaces. +.pp +to create a process with the following pids in a pid namespace hierarchy: +.rs 4 +.ts +lb lb lb +l l l. +pid ns level requested pid notes +0 31496 outermost pid namespace +1 42 +2 7 innermost pid namespace +.te +.re +.pp +set the array to: +.pp +.in +4n +.ex +set_tid[0] = 7; +set_tid[1] = 42; +set_tid[2] = 31496; +set_tid_size = 3; +.ee +.in +.pp +if only the pids in the two innermost pid namespaces +need to be specified, set the array to: +.pp +.in +4n +.ex +set_tid[0] = 7; +set_tid[1] = 42; +set_tid_size = 2; +.ee +.in +.pp +the pid in the pid namespaces outside the two innermost pid namespaces +is selected the same way as any other pid is selected. +.pp +the +.i set_tid +feature requires +.br cap_sys_admin +or +(since linux 5.9) +.\" commit 124ea650d3072b005457faed69909221c2905a1f +.\" commit 1caef81da05a84a40dbf02110e967ce6d1135ff6 +.br cap_checkpoint_restore +in all owning user namespaces of the target pid namespaces. +.pp +callers may only choose a pid greater than 1 in a given pid namespace +if an +.br init +process (i.e., a process with pid 1) already exists in that namespace. +otherwise the pid +entry for this pid namespace must be 1. +.\" +.ss the flags mask +both +.br clone () +and +.br clone3 () +allow a flags bit mask that modifies their behavior +and allows the caller to specify what is shared between the calling process +and the child process. +this bit mask\(emthe +.i flags +argument of +.br clone () +or the +.i cl_args.flags +field passed to +.br clone3 ()\(emis +referred to as the +.i flags +mask in the remainder of this page. +.pp +the +.i flags +mask is specified as a bitwise-or of zero or more of +the constants listed below. +except as noted below, these flags are available +(and have the same effect) in both +.br clone () +and +.br clone3 (). +.tp +.br clone_child_cleartid " (since linux 2.5.49)" +clear (zero) the child thread id at the location pointed to by +.i child_tid +.rb ( clone ()) +or +.i cl_args.child_tid +.rb ( clone3 ()) +in child memory when the child exits, and do a wakeup on the futex +at that address. +the address involved may be changed by the +.br set_tid_address (2) +system call. +this is used by threading libraries. +.tp +.br clone_child_settid " (since linux 2.5.49)" +store the child thread id at the location pointed to by +.i child_tid +.rb ( clone ()) +or +.i cl_args.child_tid +.rb ( clone3 ()) +in the child's memory. +the store operation completes before the clone call +returns control to user space in the child process. +(note that the store operation may not have completed before the clone call +returns in the parent process, which is relevant if the +.br clone_vm +flag is also employed.) +.tp +.br clone_clear_sighand " (since linux 5.5)" +.\" commit b612e5df4587c934bd056bf05f4a1deca4de4f75 +by default, signal dispositions in the child thread are the same as +in the parent. +if this flag is specified, +then all signals that are handled in the parent +are reset to their default dispositions +.rb ( sig_dfl ) +in the child. +.ip +specifying this flag together with +.b clone_sighand +is nonsensical and disallowed. +.tp +.br clone_detached " (historical)" +for a while (during the linux 2.5 development series) +.\" added in 2.5.32; removed in 2.6.0-test4 +there was a +.b clone_detached +flag, +which caused the parent not to receive a signal when the child terminated. +ultimately, the effect of this flag was subsumed under the +.br clone_thread +flag and by the time linux 2.6.0 was released, this flag had no effect. +starting in linux 2.6.2, the need to give this flag together with +.b clone_thread +disappeared. +.ip +this flag is still defined, but it is usually ignored when calling +.br clone (). +however, see the description of +.br clone_pidfd +for some exceptions. +.tp +.br clone_files " (since linux 2.0)" +if +.b clone_files +is set, the calling process and the child process share the same file +descriptor table. +any file descriptor created by the calling process or by the child +process is also valid in the other process. +similarly, if one of the processes closes a file descriptor, +or changes its associated flags (using the +.br fcntl (2) +.b f_setfd +operation), the other process is also affected. +if a process sharing a file descriptor table calls +.br execve (2), +its file descriptor table is duplicated (unshared). +.ip +if +.b clone_files +is not set, the child process inherits a copy of all file descriptors +opened in the calling process at the time of the clone call. +subsequent operations that open or close file descriptors, +or change file descriptor flags, +performed by either the calling +process or the child process do not affect the other process. +note, however, +that the duplicated file descriptors in the child refer to the same +open file descriptions as the corresponding file descriptors +in the calling process, +and thus share file offsets and file status flags (see +.br open (2)). +.tp +.br clone_fs " (since linux 2.0)" +if +.b clone_fs +is set, the caller and the child process share the same filesystem +information. +this includes the root of the filesystem, the current +working directory, and the umask. +any call to +.br chroot (2), +.br chdir (2), +or +.br umask (2) +performed by the calling process or the child process also affects the +other process. +.ip +if +.b clone_fs +is not set, the child process works on a copy of the filesystem +information of the calling process at the time of the clone call. +calls to +.br chroot (2), +.br chdir (2), +or +.br umask (2) +performed later by one of the processes do not affect the other process. +.tp +.br clone_into_cgroup " (since linux 5.7)" +.\" commit ef2c41cf38a7559bbf91af42d5b6a4429db8fc68 +by default, a child process is placed in the same version 2 +cgroup as its parent. +the +.b clone_into_cgroup +flag allows the child process to be created in a different version 2 cgroup. +(note that +.br clone_into_cgroup +has effect only for version 2 cgroups.) +.ip +in order to place the child process in a different cgroup, +the caller specifies +.br clone_into_cgroup +in +.i cl_args.flags +and passes a file descriptor that refers to a version 2 cgroup in the +.i cl_args.cgroup +field. +(this file descriptor can be obtained by opening a cgroup v2 directory +using either the +.b o_rdonly +or the +.b o_path +flag.) +note that all of the usual restrictions (described in +.br cgroups (7)) +on placing a process into a version 2 cgroup apply. +.ip +among the possible use cases for +.br clone_into_cgroup +are the following: +.rs +.ip * 3 +spawning a process into a cgroup different from the parent's cgroup +makes it possible for a service manager to directly spawn new +services into dedicated cgroups. +this eliminates the accounting +jitter that would be caused if the child process was first created in the +same cgroup as the parent and then +moved into the target cgroup. +furthermore, spawning the child process directly into a target cgroup +is significantly cheaper than moving the child process into +the target cgroup after it has been created. +.ip * +the +.br clone_into_cgroup +flag also allows the creation of +frozen child processes by spawning them into a frozen cgroup. +(see +.br cgroups (7) +for a description of the freezer controller.) +.ip * +for threaded applications (or even thread implementations which +make use of cgroups to limit individual threads), it is possible to +establish a fixed cgroup layout before spawning each thread +directly into its target cgroup. +.re +.tp +.br clone_io " (since linux 2.6.25)" +if +.b clone_io +is set, then the new process shares an i/o context with +the calling process. +if this flag is not set, then (as with +.br fork (2)) +the new process has its own i/o context. +.ip +.\" the following based on text from jens axboe +the i/o context is the i/o scope of the disk scheduler (i.e., +what the i/o scheduler uses to model scheduling of a process's i/o). +if processes share the same i/o context, +they are treated as one by the i/o scheduler. +as a consequence, they get to share disk time. +for some i/o schedulers, +.\" the anticipatory and cfq scheduler +if two processes share an i/o context, +they will be allowed to interleave their disk access. +if several threads are doing i/o on behalf of the same process +.rb ( aio_read (3), +for instance), they should employ +.br clone_io +to get better i/o performance. +.\" with cfq and as. +.ip +if the kernel is not configured with the +.b config_block +option, this flag is a no-op. +.tp +.br clone_newcgroup " (since linux 4.6)" +create the process in a new cgroup namespace. +if this flag is not set, then (as with +.br fork (2)) +the process is created in the same cgroup namespaces as the calling process. +.ip +for further information on cgroup namespaces, see +.br cgroup_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newcgroup . +.\" +.tp +.br clone_newipc " (since linux 2.6.19)" +if +.b clone_newipc +is set, then create the process in a new ipc namespace. +if this flag is not set, then (as with +.br fork (2)), +the process is created in the same ipc namespace as +the calling process. +.ip +for further information on ipc namespaces, see +.br ipc_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newipc . +this flag can't be specified in conjunction with +.br clone_sysvsem . +.tp +.br clone_newnet " (since linux 2.6.24)" +(the implementation of this flag was completed only +by about kernel version 2.6.29.) +.ip +if +.b clone_newnet +is set, then create the process in a new network namespace. +if this flag is not set, then (as with +.br fork (2)) +the process is created in the same network namespace as +the calling process. +.ip +for further information on network namespaces, see +.br network_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newnet . +.tp +.br clone_newns " (since linux 2.4.19)" +if +.b clone_newns +is set, the cloned child is started in a new mount namespace, +initialized with a copy of the namespace of the parent. +if +.b clone_newns +is not set, the child lives in the same mount +namespace as the parent. +.ip +for further information on mount namespaces, see +.br namespaces (7) +and +.br mount_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newns . +it is not permitted to specify both +.b clone_newns +and +.b clone_fs +.\" see https://lwn.net/articles/543273/ +in the same clone call. +.tp +.br clone_newpid " (since linux 2.6.24)" +.\" this explanation draws a lot of details from +.\" http://lwn.net/articles/259217/ +.\" authors: pavel emelyanov +.\" and kir kolyshkin +.\" +.\" the primary kernel commit is 30e49c263e36341b60b735cbef5ca37912549264 +.\" author: pavel emelyanov +if +.b clone_newpid +is set, then create the process in a new pid namespace. +if this flag is not set, then (as with +.br fork (2)) +the process is created in the same pid namespace as +the calling process. +.ip +for further information on pid namespaces, see +.br namespaces (7) +and +.br pid_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newpid . +this flag can't be specified in conjunction with +.br clone_thread +or +.br clone_parent . +.tp +.br clone_newuser +(this flag first became meaningful for +.br clone () +in linux 2.6.23, +the current +.br clone () +semantics were merged in linux 3.5, +and the final pieces to make the user namespaces completely usable were +merged in linux 3.8.) +.ip +if +.b clone_newuser +is set, then create the process in a new user namespace. +if this flag is not set, then (as with +.br fork (2)) +the process is created in the same user namespace as the calling process. +.ip +for further information on user namespaces, see +.br namespaces (7) +and +.br user_namespaces (7). +.ip +before linux 3.8, use of +.br clone_newuser +required that the caller have three capabilities: +.br cap_sys_admin , +.br cap_setuid , +and +.br cap_setgid . +.\" before linux 2.6.29, it appears that only cap_sys_admin was needed +starting with linux 3.8, +no privileges are needed to create a user namespace. +.ip +this flag can't be specified in conjunction with +.br clone_thread +or +.br clone_parent . +for security reasons, +.\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71 +.\" https://lwn.net/articles/543273/ +.\" the fix actually went into 3.9 and into 3.8.3. however, user namespaces +.\" were, for practical purposes, unusable in earlier 3.8.x because of the +.\" various filesystems that didn't support userns. +.br clone_newuser +cannot be specified in conjunction with +.br clone_fs . +.tp +.br clone_newuts " (since linux 2.6.19)" +if +.b clone_newuts +is set, then create the process in a new uts namespace, +whose identifiers are initialized by duplicating the identifiers +from the uts namespace of the calling process. +if this flag is not set, then (as with +.br fork (2)) +the process is created in the same uts namespace as +the calling process. +.ip +for further information on uts namespaces, see +.br uts_namespaces (7). +.ip +only a privileged process +.rb ( cap_sys_admin ) +can employ +.br clone_newuts . +.tp +.br clone_parent " (since linux 2.3.12)" +if +.b clone_parent +is set, then the parent of the new child (as returned by +.br getppid (2)) +will be the same as that of the calling process. +.ip +if +.b clone_parent +is not set, then (as with +.br fork (2)) +the child's parent is the calling process. +.ip +note that it is the parent process, as returned by +.br getppid (2), +which is signaled when the child terminates, so that +if +.b clone_parent +is set, then the parent of the calling process, rather than the +calling process itself, is signaled. +.ip +the +.b clone_parent +flag can't be used in clone calls by the +global init process (pid 1 in the initial pid namespace) +and init processes in other pid namespaces. +this restriction prevents the creation of multi-rooted process trees +as well as the creation of unreapable zombies in the initial pid namespace. +.tp +.br clone_parent_settid " (since linux 2.5.49)" +store the child thread id at the location pointed to by +.i parent_tid +.rb ( clone ()) +or +.i cl_args.parent_tid +.rb ( clone3 ()) +in the parent's memory. +(in linux 2.5.32-2.5.48 there was a flag +.b clone_settid +that did this.) +the store operation completes before the clone call +returns control to user space. +.tp +.br clone_pid " (linux 2.0 to 2.5.15)" +if +.b clone_pid +is set, the child process is created with the same process id as +the calling process. +this is good for hacking the system, but otherwise +of not much use. +from linux 2.3.21 onward, this flag could be +specified only by the system boot process (pid 0). +the flag disappeared completely from the kernel sources in linux 2.5.16. +subsequently, the kernel silently ignored this bit if it was specified in the +.ir flags +mask. +much later, the same bit was recycled for use as the +.b clone_pidfd +flag. +.tp +.br clone_pidfd " (since linux 5.2)" +.\" commit b3e5838252665ee4cfa76b82bdf1198dca81e5be +if this flag is specified, +a pid file descriptor referring to the child process is allocated +and placed at a specified location in the parent's memory. +the close-on-exec flag is set on this new file descriptor. +pid file descriptors can be used for the purposes described in +.br pidfd_open (2). +.rs +.ip * 3 +when using +.br clone3 (), +the pid file descriptor is placed at the location pointed to by +.ir cl_args.pidfd . +.ip * +when using +.br clone (), +the pid file descriptor is placed at the location pointed to by +.ir parent_tid . +since the +.i parent_tid +argument is used to return the pid file descriptor, +.b clone_pidfd +cannot be used with +.b clone_parent_settid +when calling +.br clone (). +.re +.ip +it is currently not possible to use this flag together with +.b clone_thread. +this means that the process identified by the pid file descriptor +will always be a thread group leader. +.ip +if the obsolete +.b clone_detached +flag is specified alongside +.br clone_pidfd +when calling +.br clone (), +an error is returned. +an error also results if +.b clone_detached +is specified when calling +.br clone3 (). +this error behavior ensures that the bit corresponding to +.br clone_detached +can be reused for further pid file descriptor features in the future. +.tp +.br clone_ptrace " (since linux 2.2)" +if +.b clone_ptrace +is specified, and the calling process is being traced, +then trace the child also (see +.br ptrace (2)). +.tp +.br clone_settls " (since linux 2.5.32)" +the tls (thread local storage) descriptor is set to +.ir tls . +.ip +the interpretation of +.i tls +and the resulting effect is architecture dependent. +on x86, +.i tls +is interpreted as a +.ir "struct user_desc\ *" +(see +.br set_thread_area (2)). +on x86-64 it is the new value to be set for the %fs base register +(see the +.b arch_set_fs +argument to +.br arch_prctl (2)). +on architectures with a dedicated tls register, it is the new value +of that register. +.ip +use of this flag requires detailed knowledge and generally it +should not be used except in libraries implementing threading. +.tp +.br clone_sighand " (since linux 2.0)" +if +.b clone_sighand +is set, the calling process and the child process share the same table of +signal handlers. +if the calling process or child process calls +.br sigaction (2) +to change the behavior associated with a signal, the behavior is +changed in the other process as well. +however, the calling process and child +processes still have distinct signal masks and sets of pending +signals. +so, one of them may block or unblock signals using +.br sigprocmask (2) +without affecting the other process. +.ip +if +.b clone_sighand +is not set, the child process inherits a copy of the signal handlers +of the calling process at the time of the clone call. +calls to +.br sigaction (2) +performed later by one of the processes have no effect on the other +process. +.ip +since linux 2.6.0, +.\" precisely: linux 2.6.0-test6 +the +.i flags +mask must also include +.b clone_vm +if +.b clone_sighand +is specified. +.tp +.br clone_stopped " (since linux 2.6.0)" +.\" precisely: linux 2.6.0-test2 +if +.b clone_stopped +is set, then the child is initially stopped (as though it was sent a +.b sigstop +signal), and must be resumed by sending it a +.b sigcont +signal. +.ip +this flag was +.i deprecated +from linux 2.6.25 onward, +and was +.i removed +altogether in linux 2.6.38. +since then, the kernel silently ignores it without error. +.\" glibc 2.8 removed this defn from bits/sched.h +starting with linux 4.6, the same bit was reused for the +.br clone_newcgroup +flag. +.tp +.br clone_sysvsem " (since linux 2.5.10)" +if +.b clone_sysvsem +is set, then the child and the calling process share +a single list of system v semaphore adjustment +.ri ( semadj ) +values (see +.br semop (2)). +in this case, the shared list accumulates +.i semadj +values across all processes sharing the list, +and semaphore adjustments are performed only when the last process +that is sharing the list terminates (or ceases sharing the list using +.br unshare (2)). +if this flag is not set, then the child has a separate +.i semadj +list that is initially empty. +.tp +.br clone_thread " (since linux 2.4.0)" +.\" precisely: linux 2.6.0-test8 +if +.b clone_thread +is set, the child is placed in the same thread group as the calling process. +to make the remainder of the discussion of +.b clone_thread +more readable, the term "thread" is used to refer to the +processes within a thread group. +.ip +thread groups were a feature added in linux 2.4 to support the +posix threads notion of a set of threads that share a single pid. +internally, this shared pid is the so-called +thread group identifier (tgid) for the thread group. +since linux 2.4, calls to +.br getpid (2) +return the tgid of the caller. +.ip +the threads within a group can be distinguished by their (system-wide) +unique thread ids (tid). +a new thread's tid is available as the function result +returned to the caller, +and a thread can obtain +its own tid using +.br gettid (2). +.ip +when a clone call is made without specifying +.br clone_thread , +then the resulting thread is placed in a new thread group +whose tgid is the same as the thread's tid. +this thread is the +.i leader +of the new thread group. +.ip +a new thread created with +.b clone_thread +has the same parent process as the process that made the clone call +(i.e., like +.br clone_parent ), +so that calls to +.br getppid (2) +return the same value for all of the threads in a thread group. +when a +.b clone_thread +thread terminates, the thread that created it is not sent a +.b sigchld +(or other termination) signal; +nor can the status of such a thread be obtained +using +.br wait (2). +(the thread is said to be +.ir detached .) +.ip +after all of the threads in a thread group terminate +the parent process of the thread group is sent a +.b sigchld +(or other termination) signal. +.ip +if any of the threads in a thread group performs an +.br execve (2), +then all threads other than the thread group leader are terminated, +and the new program is executed in the thread group leader. +.ip +if one of the threads in a thread group creates a child using +.br fork (2), +then any thread in the group can +.br wait (2) +for that child. +.ip +since linux 2.5.35, the +.i flags +mask must also include +.b clone_sighand +if +.b clone_thread +is specified +(and note that, since linux 2.6.0, +.\" precisely: linux 2.6.0-test6 +.br clone_sighand +also requires +.br clone_vm +to be included). +.ip +signal dispositions and actions are process-wide: +if an unhandled signal is delivered to a thread, then +it will affect (terminate, stop, continue, be ignored in) +all members of the thread group. +.ip +each thread has its own signal mask, as set by +.br sigprocmask (2). +.ip +a signal may be process-directed or thread-directed. +a process-directed signal is targeted at a thread group (i.e., a tgid), +and is delivered to an arbitrarily selected thread from among those +that are not blocking the signal. +a signal may be process-directed because it was generated by the kernel +for reasons other than a hardware exception, or because it was sent using +.br kill (2) +or +.br sigqueue (3). +a thread-directed signal is targeted at (i.e., delivered to) +a specific thread. +a signal may be thread directed because it was sent using +.br tgkill (2) +or +.br pthread_sigqueue (3), +or because the thread executed a machine language instruction that triggered +a hardware exception +(e.g., invalid memory access triggering +.br sigsegv +or a floating-point exception triggering +.br sigfpe ). +.ip +a call to +.br sigpending (2) +returns a signal set that is the union of the pending process-directed +signals and the signals that are pending for the calling thread. +.ip +if a process-directed signal is delivered to a thread group, +and the thread group has installed a handler for the signal, then +the handler is invoked in exactly one, arbitrarily selected +member of the thread group that has not blocked the signal. +if multiple threads in a group are waiting to accept the same signal using +.br sigwaitinfo (2), +the kernel will arbitrarily select one of these threads +to receive the signal. +.tp +.br clone_untraced " (since linux 2.5.46)" +if +.b clone_untraced +is specified, then a tracing process cannot force +.b clone_ptrace +on this child process. +.tp +.br clone_vfork " (since linux 2.2)" +if +.b clone_vfork +is set, the execution of the calling process is suspended +until the child releases its virtual memory +resources via a call to +.br execve (2) +or +.br _exit (2) +(as with +.br vfork (2)). +.ip +if +.b clone_vfork +is not set, then both the calling process and the child are schedulable +after the call, and an application should not rely on execution occurring +in any particular order. +.tp +.br clone_vm " (since linux 2.0)" +if +.b clone_vm +is set, the calling process and the child process run in the same memory +space. +in particular, memory writes performed by the calling process +or by the child process are also visible in the other process. +moreover, any memory mapping or unmapping performed with +.br mmap (2) +or +.br munmap (2) +by the child or calling process also affects the other process. +.ip +if +.b clone_vm +is not set, the child process runs in a separate copy of the memory +space of the calling process at the time of the clone call. +memory writes or file mappings/unmappings performed by one of the +processes do not affect the other, as with +.br fork (2). +.ip +if the +.br clone_vm +flag is specified and the +.br clone_vfork +flag is not specified, +then any alternate signal stack that was established by +.br sigaltstack (2) +is cleared in the child process. +.sh return value +.\" gettid(2) returns current->pid; +.\" getpid(2) returns current->tgid; +on success, the thread id of the child process is returned +in the caller's thread of execution. +on failure, \-1 is returned +in the caller's context, no child process is created, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b eagain +too many processes are already running; see +.br fork (2). +.tp +.br ebusy " (" clone3 "() only)" +.b clone_into_cgroup +was specified in +.ir cl_args.flags , +but the file descriptor specified in +.ir cl_args.cgroup +refers to a version 2 cgroup in which a domain controller is enabled. +.tp +.br eexist " (" clone3 "() only)" +one (or more) of the pids specified in +.i set_tid +already exists in the corresponding pid namespace. +.tp +.b einval +both +.b clone_sighand +and +.b clone_clear_sighand +were specified in the +.i flags +mask. +.tp +.b einval +.b clone_sighand +was specified in the +.i flags +mask, but +.b clone_vm +was not. +(since linux 2.6.0.) +.\" precisely: linux 2.6.0-test6 +.tp +.b einval +.b clone_thread +was specified in the +.i flags +mask, but +.b clone_sighand +was not. +(since linux 2.5.35.) +.\" .tp +.\" .b einval +.\" precisely one of +.\" .b clone_detached +.\" and +.\" .b clone_thread +.\" was specified. +.\" (since linux 2.6.0-test6.) +.tp +.b einval +.b clone_thread +was specified in the +.i flags +mask, but the current process previously called +.br unshare (2) +with the +.b clone_newpid +flag or used +.br setns (2) +to reassociate itself with a pid namespace. +.tp +.b einval +.\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71 +both +.b clone_fs +and +.b clone_newns +were specified in the +.ir flags +mask. +.tp +.br einval " (since linux 3.9)" +both +.b clone_newuser +and +.b clone_fs +were specified in the +.ir flags +mask. +.tp +.b einval +both +.b clone_newipc +and +.b clone_sysvsem +were specified in the +.ir flags +mask. +.tp +.b einval +one (or both) of +.br clone_newpid +or +.br clone_newuser +and one (or both) of +.br clone_thread +or +.br clone_parent +were specified in the +.ir flags +mask. +.tp +.br einval " (since linux 2.6.32)" +.\" commit 123be07b0b399670a7cc3d82fef0cb4f93ef885c +.br clone_parent +was specified, and the caller is an init process. +.tp +.b einval +returned by the glibc +.br clone () +wrapper function when +.ir fn +or +.ir stack +is specified as null. +.tp +.b einval +.br clone_newipc +was specified in the +.ir flags +mask, +but the kernel was not configured with the +.b config_sysvipc +and +.br config_ipc_ns +options. +.tp +.b einval +.br clone_newnet +was specified in the +.ir flags +mask, +but the kernel was not configured with the +.b config_net_ns +option. +.tp +.b einval +.br clone_newpid +was specified in the +.ir flags +mask, +but the kernel was not configured with the +.b config_pid_ns +option. +.tp +.b einval +.br clone_newuser +was specified in the +.ir flags +mask, +but the kernel was not configured with the +.b config_user_ns +option. +.tp +.b einval +.br clone_newuts +was specified in the +.ir flags +mask, +but the kernel was not configured with the +.b config_uts_ns +option. +.tp +.b einval +.i stack +is not aligned to a suitable boundary for this architecture. +for example, on aarch64, +.i stack +must be a multiple of 16. +.tp +.br einval " (" clone3 "() only)" +.b clone_detached +was specified in the +.i flags +mask. +.tp +.br einval " (" clone "() only)" +.b clone_pidfd +was specified together with +.b clone_detached +in the +.i flags +mask. +.tp +.b einval +.b clone_pidfd +was specified together with +.b clone_thread +in the +.i flags +mask. +.tp +.br "einval " "(" clone "() only)" +.b clone_pidfd +was specified together with +.b clone_parent_settid +in the +.i flags +mask. +.tp +.br einval " (" clone3 "() only)" +.i set_tid_size +is greater than the number of nested pid namespaces. +.tp +.br einval " (" clone3 "() only)" +one of the pids specified in +.i set_tid +was an invalid. +.tp +.br einval " (aarch64 only, linux 4.6 and earlier)" +.i stack +was not aligned to a 128-bit boundary. +.tp +.b enomem +cannot allocate sufficient memory to allocate a task structure for the +child, or to copy those parts of the caller's context that need to be +copied. +.tp +.br enospc " (since linux 3.7)" +.\" commit f2302505775fd13ba93f034206f1e2a587017929 +.b clone_newpid +was specified in the +.i flags +mask, +but the limit on the nesting depth of pid namespaces +would have been exceeded; see +.br pid_namespaces (7). +.tp +.br enospc " (since linux 4.9; beforehand " eusers ) +.b clone_newuser +was specified in the +.ir flags +mask, and the call would cause the limit on the number of +nested user namespaces to be exceeded. +see +.br user_namespaces (7). +.ip +from linux 3.11 to linux 4.8, the error diagnosed in this case was +.br eusers . +.tp +.br enospc " (since linux 4.9)" +one of the values in the +.i flags +mask specified the creation of a new user namespace, +but doing so would have caused the limit defined by the corresponding file in +.ir /proc/sys/user +to be exceeded. +for further details, see +.br namespaces (7). +.tp +.br eopnotsupp " (" clone3 "() only)" +.b clone_into_cgroup +was specified in +.ir cl_args.flags , +but the file descriptor specified in +.ir cl_args.cgroup +refers to a version 2 cgroup that is in the +.ir "domain invalid" +state. +.tp +.b eperm +.br clone_newcgroup , +.br clone_newipc , +.br clone_newnet , +.br clone_newns , +.br clone_newpid , +or +.br clone_newuts +was specified by an unprivileged process (process without \fbcap_sys_admin\fp). +.tp +.b eperm +.b clone_pid +was specified by a process other than process 0. +(this error occurs only on linux 2.5.15 and earlier.) +.tp +.b eperm +.br clone_newuser +was specified in the +.ir flags +mask, +but either the effective user id or the effective group id of the caller +does not have a mapping in the parent namespace (see +.br user_namespaces (7)). +.tp +.br eperm " (since linux 3.9)" +.\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d +.b clone_newuser +was specified in the +.i flags +mask and the caller is in a chroot environment +.\" fixme what is the rationale for this restriction? +(i.e., the caller's root directory does not match the root directory +of the mount namespace in which it resides). +.tp +.br eperm " (" clone3 "() only)" +.i set_tid_size +was greater than zero, and the caller lacks the +.b cap_sys_admin +capability in one or more of the user namespaces that own the +corresponding pid namespaces. +.tp +.br erestartnointr " (since linux 2.6.17)" +.\" commit 4a2c7a7837da1b91468e50426066d988050e4d56 +system call was interrupted by a signal and will be restarted. +(this can be seen only during a trace.) +.tp +.br eusers " (linux 3.11 to linux 4.8)" +.b clone_newuser +was specified in the +.ir flags +mask, +and the limit on the number of nested user namespaces would be exceeded. +see the discussion of the +.br enospc +error above. +.sh versions +the +.br clone3 () +system call first appeared in linux 5.3. +.\" there is no entry for +.\" .br clone () +.\" in libc5. +.\" glibc2 provides +.\" .br clone () +.\" as described in this manual page. +.sh conforming to +these system calls +are linux-specific and should not be used in programs +intended to be portable. +.sh notes +one use of these systems calls +is to implement threads: multiple flows of control in a program that +run concurrently in a shared address space. +.pp +note that the glibc +.br clone () +wrapper function makes some changes +in the memory pointed to by +.i stack +(changes required to set the stack up correctly for the child) +.i before +invoking the +.br clone () +system call. +so, in cases where +.br clone () +is used to recursively create children, +do not use the buffer employed for the parent's stack +as the stack of the child. +.pp +the +.br kcmp (2) +system call can be used to test whether two processes share various +resources such as a file descriptor table, +system v semaphore undo operations, or a virtual address space. +.pp +handlers registered using +.br pthread_atfork (3) +are not executed during a clone call. +.pp +in the linux 2.4.x series, +.b clone_thread +generally does not make the parent of the new thread the same +as the parent of the calling process. +however, for kernel versions 2.4.7 to 2.4.18 the +.b clone_thread +flag implied the +.b clone_parent +flag (as in linux 2.6.0 and later). +.pp +on i386, +.br clone () +should not be called through vsyscall, but directly through +.ir "int $0x80" . +.\" +.ss c library/kernel differences +the raw +.br clone () +system call corresponds more closely to +.br fork (2) +in that execution in the child continues from the point of the +call. +as such, the +.i fn +and +.i arg +arguments of the +.br clone () +wrapper function are omitted. +.pp +in contrast to the glibc wrapper, the raw +.br clone () +system call accepts null as a +.i stack +argument (and +.br clone3 () +likewise allows +.i cl_args.stack +to be null). +in this case, the child uses a duplicate of the parent's stack. +(copy-on-write semantics ensure that the child gets separate copies +of stack pages when either process modifies the stack.) +in this case, for correct operation, the +.b clone_vm +option should not be specified. +(if the child +.i shares +the parent's memory because of the use of the +.br clone_vm +flag, +then no copy-on-write duplication occurs and chaos is likely to result.) +.pp +the order of the arguments also differs in the raw system call, +and there are variations in the arguments across architectures, +as detailed in the following paragraphs. +.pp +the raw system call interface on x86-64 and some other architectures +(including sh, tile, and alpha) is: +.pp +.in +4n +.ex +.bi "long clone(unsigned long " flags ", void *" stack , +.bi " int *" parent_tid ", int *" child_tid , +.bi " unsigned long " tls ); +.ee +.in +.pp +on x86-32, and several other common architectures +(including score, arm, arm 64, pa-risc, arc, power pc, xtensa, +and mips), +.\" config_clone_backwards +the order of the last two arguments is reversed: +.pp +.in +4n +.ex +.bi "long clone(unsigned long " flags ", void *" stack , +.bi " int *" parent_tid ", unsigned long " tls , +.bi " int *" child_tid ); +.ee +.in +.pp +on the cris and s390 architectures, +.\" config_clone_backwards2 +the order of the first two arguments is reversed: +.pp +.in +4n +.ex +.bi "long clone(void *" stack ", unsigned long " flags , +.bi " int *" parent_tid ", int *" child_tid , +.bi " unsigned long " tls ); +.ee +.in +.pp +on the microblaze architecture, +.\" config_clone_backwards3 +an additional argument is supplied: +.pp +.in +4n +.ex +.bi "long clone(unsigned long " flags ", void *" stack , +.bi " int " stack_size , "\fr /* size of stack */" +.bi " int *" parent_tid ", int *" child_tid , +.bi " unsigned long " tls ); +.ee +.in +.\" +.ss blackfin, m68k, and sparc +.\" mike frysinger noted in a 2013 mail: +.\" these arches don't define __arch_want_sys_clone: +.\" blackfin ia64 m68k sparc +the argument-passing conventions on +blackfin, m68k, and sparc are different from the descriptions above. +for details, see the kernel (and glibc) source. +.ss ia64 +on ia64, a different interface is used: +.pp +.in +4n +.ex +.bi "int __clone2(int (*" "fn" ")(void *)," +.bi " void *" stack_base ", size_t " stack_size , +.bi " int " flags ", void *" "arg" ", ..." +.bi " /* pid_t *" parent_tid ", struct user_desc *" tls , +.bi " pid_t *" child_tid " */ );" +.ee +.in +.pp +the prototype shown above is for the glibc wrapper function; +for the system call itself, +the prototype can be described as follows (it is identical to the +.br clone () +prototype on microblaze): +.pp +.in +4n +.ex +.bi "long clone2(unsigned long " flags ", void *" stack_base , +.bi " int " stack_size , "\fr /* size of stack */" +.bi " int *" parent_tid ", int *" child_tid , +.bi " unsigned long " tls ); +.ee +.in +.pp +.br __clone2 () +operates in the same way as +.br clone (), +except that +.i stack_base +points to the lowest address of the child's stack area, +and +.i stack_size +specifies the size of the stack pointed to by +.ir stack_base . +.ss linux 2.4 and earlier +in linux 2.4 and earlier, +.br clone () +does not take arguments +.ir parent_tid , +.ir tls , +and +.ir child_tid . +.sh bugs +gnu c library versions 2.3.4 up to and including 2.24 +contained a wrapper function for +.br getpid (2) +that performed caching of pids. +this caching relied on support in the glibc wrapper for +.br clone (), +but limitations in the implementation +meant that the cache was not up to date in some circumstances. +in particular, +if a signal was delivered to the child immediately after the +.br clone () +call, then a call to +.br getpid (2) +in a handler for the signal could return the pid +of the calling process ("the parent"), +if the clone wrapper had not yet had a chance to update the pid +cache in the child. +(this discussion ignores the case where the child was created using +.br clone_thread , +when +.br getpid (2) +.i should +return the same value in the child and in the process that called +.br clone (), +since the caller and the child are in the same thread group. +the stale-cache problem also does not occur if the +.i flags +argument includes +.br clone_vm .) +to get the truth, it was sometimes necessary to use code such as the following: +.pp +.in +4n +.ex +#include + +pid_t mypid; + +mypid = syscall(sys_getpid); +.ee +.in +.\" see also the following bug reports +.\" https://bugzilla.redhat.com/show_bug.cgi?id=417521 +.\" http://sourceware.org/bugzilla/show_bug.cgi?id=6910 +.pp +because of the stale-cache problem, as well as other problems noted in +.br getpid (2), +the pid caching feature was removed in glibc 2.25. +.sh examples +the following program demonstrates the use of +.br clone () +to create a child process that executes in a separate uts namespace. +the child changes the hostname in its uts namespace. +both parent and child then display the system hostname, +making it possible to see that the hostname +differs in the uts namespaces of the parent and child. +for an example of the use of this program, see +.br setns (2). +.pp +within the sample program, we allocate the memory that is to +be used for the child's stack using +.br mmap (2) +rather than +.br malloc (3) +for the following reasons: +.ip * 3 +.br mmap (2) +allocates a block of memory that starts on a page +boundary and is a multiple of the page size. +this is useful if we want to establish a guard page (a page with protection +.br prot_none ) +at the end of the stack using +.br mprotect (2). +.ip * +we can specify the +.br map_stack +flag to request a mapping that is suitable for a stack. +for the moment, this flag is a no-op on linux, +but it exists and has effect on some other systems, +so we should include it for portability. +.ss program source +.ex +#define _gnu_source +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define errexit(msg) do { perror(msg); exit(exit_failure); \e + } while (0) + +static int /* start function for cloned child */ +childfunc(void *arg) +{ + struct utsname uts; + + /* change hostname in uts namespace of child. */ + + if (sethostname(arg, strlen(arg)) == \-1) + errexit("sethostname"); + + /* retrieve and display hostname. */ + + if (uname(&uts) == \-1) + errexit("uname"); + printf("uts.nodename in child: %s\en", uts.nodename); + + /* keep the namespace open for a while, by sleeping. + this allows some experimentation\-\-for example, another + process might join the namespace. */ + + sleep(200); + + return 0; /* child terminates now */ +} + +#define stack_size (1024 * 1024) /* stack size for cloned child */ + +int +main(int argc, char *argv[]) +{ + char *stack; /* start of stack buffer */ + char *stacktop; /* end of stack buffer */ + pid_t pid; + struct utsname uts; + + if (argc < 2) { + fprintf(stderr, "usage: %s \en", argv[0]); + exit(exit_success); + } + + /* allocate memory to be used for the stack of the child. */ + + stack = mmap(null, stack_size, prot_read | prot_write, + map_private | map_anonymous | map_stack, \-1, 0); + if (stack == map_failed) + errexit("mmap"); + + stacktop = stack + stack_size; /* assume stack grows downward */ + + /* create child that has its own uts namespace; + child commences execution in childfunc(). */ + + pid = clone(childfunc, stacktop, clone_newuts | sigchld, argv[1]); + if (pid == \-1) + errexit("clone"); + printf("clone() returned %jd\en", (intmax_t) pid); + + /* parent falls through to here */ + + sleep(1); /* give child time to change its hostname */ + + /* display hostname in parent\(aqs uts namespace. this will be + different from hostname in child\(aqs uts namespace. */ + + if (uname(&uts) == \-1) + errexit("uname"); + printf("uts.nodename in parent: %s\en", uts.nodename); + + if (waitpid(pid, null, 0) == \-1) /* wait for child */ + errexit("waitpid"); + printf("child has terminated\en"); + + exit(exit_success); +} +.ee +.sh see also +.br fork (2), +.br futex (2), +.br getpid (2), +.br gettid (2), +.br kcmp (2), +.br mmap (2), +.br pidfd_open (2), +.br set_thread_area (2), +.br set_tid_address (2), +.br setns (2), +.br tkill (2), +.br unshare (2), +.br wait (2), +.br capabilities (7), +.br namespaces (7), +.br pthreads (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/rpc.3 + +.\" copyright 2003,2004 andi kleen, suse labs. +.\" and copyright 2007 lee schermerhorn, hewlett packard +.\" +.\" %%%license_start(verbatim_prof) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" 2006-02-03, mtk, substantial wording changes and other improvements +.\" 2007-08-27, lee schermerhorn +.\" more precise specification of behavior. +.\" +.th get_mempolicy 2 2021-03-22 linux "linux programmer's manual" +.sh name +get_mempolicy \- retrieve numa memory policy for a thread +.sh synopsis +.b "#include " +.nf +.pp +.bi "long get_mempolicy(int *" mode ", unsigned long *" nodemask , +.bi " unsigned long " maxnode ", void *" addr , +.bi " unsigned long " flags ); +.pp +link with \fi\-lnuma\fp. +.fi +.pp +.ir note : +there is no glibc wrapper for this system call; see notes. +.sh description +.br get_mempolicy () +retrieves the numa policy of the calling thread or of a memory address, +depending on the setting of +.ir flags . +.pp +a numa machine has different +memory controllers with different distances to specific cpus. +the memory policy defines from which node memory is allocated for +the thread. +.pp +if +.i flags +is specified as 0, +then information about the calling thread's default policy +(as set by +.br set_mempolicy (2)) +is returned, in the buffers pointed to by +.i mode +and +.ir nodemask . +the value returned in these arguments +may be used to restore the thread's policy to its state at +the time of the call to +.br get_mempolicy () +using +.br set_mempolicy (2). +when +.i flags +is 0, +.i addr +must be specified as null. +.pp +if +.i flags +specifies +.br mpol_f_mems_allowed +(available since linux 2.6.24), the +.i mode +argument is ignored and the set of nodes (memories) that the +thread is allowed to specify in subsequent calls to +.br mbind (2) +or +.br set_mempolicy (2) +(in the absence of any +.ir "mode flags" ) +is returned in +.ir nodemask . +it is not permitted to combine +.b mpol_f_mems_allowed +with either +.b mpol_f_addr +or +.br mpol_f_node . +.pp +if +.i flags +specifies +.br mpol_f_addr , +then information is returned about the policy governing the memory +address given in +.ir addr . +this policy may be different from the thread's default policy if +.br mbind (2) +or one of the helper functions described in +.br numa (3) +has been used to establish a policy for the memory range containing +.ir addr . +.pp +if the +.i mode +argument is not null, then +.br get_mempolicy () +will store the policy mode and any optional +.i "mode flags" +of the requested numa policy in the location pointed to by this argument. +if +.i nodemask +is not null, then the nodemask associated with the policy will be stored +in the location pointed to by this argument. +.i maxnode +specifies the number of node ids +that can be stored into +.ir nodemask \(emthat +is, the maximum node id plus one. +the value specified by +.i maxnode +is always rounded to a multiple of +.ir "sizeof(unsigned\ long)*8" . +.pp +if +.i flags +specifies both +.b mpol_f_node +and +.br mpol_f_addr , +.br get_mempolicy () +will return the node id of the node on which the address +.i addr +is allocated into the location pointed to by +.ir mode . +if no page has yet been allocated for the specified address, +.br get_mempolicy () +will allocate a page as if the thread had performed a read +(load) access to that address, and return the id of the node +where that page was allocated. +.pp +if +.i flags +specifies +.br mpol_f_node , +but not +.br mpol_f_addr , +and the thread's current policy is +.br mpol_interleave , +then +.br get_mempolicy () +will return in the location pointed to by a non-null +.i mode +argument, +the node id of the next node that will be used for +interleaving of internal kernel pages allocated on behalf of the thread. +.\" note: code returns next interleave node via 'mode' argument -lee schermerhorn +these allocations include pages for memory-mapped files in +process memory ranges mapped using the +.br mmap (2) +call with the +.b map_private +flag for read accesses, and in memory ranges mapped with the +.b map_shared +flag for all accesses. +.pp +other flag values are reserved. +.pp +for an overview of the possible policies see +.br set_mempolicy (2). +.sh return value +on success, +.br get_mempolicy () +returns 0; +on error, \-1 is returned and +.i errno +is set to indicate the error. +.sh errors +.tp +.b efault +part of all of the memory range specified by +.i nodemask +and +.i maxnode +points outside your accessible address space. +.tp +.b einval +the value specified by +.i maxnode +is less than the number of node ids supported by the system. +or +.i flags +specified values other than +.b mpol_f_node +or +.br mpol_f_addr ; +or +.i flags +specified +.b mpol_f_addr +and +.i addr +is null, +or +.i flags +did not specify +.b mpol_f_addr +and +.i addr +is not null. +or, +.i flags +specified +.b mpol_f_node +but not +.b mpol_f_addr +and the current thread policy is not +.br mpol_interleave . +or, +.i flags +specified +.b mpol_f_mems_allowed +with either +.b mpol_f_addr +or +.br mpol_f_node . +(and there are other +.b einval +cases.) +.sh versions +the +.br get_mempolicy () +system call was added to the linux kernel in version 2.6.7. +.sh conforming to +this system call is linux-specific. +.sh notes +glibc does not provide a wrapper for this system call. +for information on library support, see +.br numa (7). +.sh see also +.br getcpu (2), +.br mbind (2), +.br mmap (2), +.br set_mempolicy (2), +.br numa (3), +.br numa (7), +.br numactl (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th mblen 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +mblen \- determine number of bytes in next multibyte character +.sh synopsis +.nf +.b #include +.pp +.bi "int mblen(const char *" s ", size_t " n ); +.fi +.sh description +if +.i s +is not null, the +.br mblen () +function inspects at most +.i n +bytes of the multibyte string starting at +.i s +and extracts the +next complete multibyte character. +it uses a static anonymous shift state known only to the +.br mblen () +function. +if the multibyte character is not the null wide +character, it returns the number of bytes that were consumed from +.ir s . +if the multibyte character is the null wide character, it returns 0. +.pp +if the +.ir n +bytes starting at +.i s +do not contain a complete multibyte +character, +.br mblen () +returns \-1. +this can happen even if +.i n +is greater than or equal to +.ir mb_cur_max , +if the multibyte string contains redundant shift sequences. +.pp +if the multibyte string starting at +.i s +contains an invalid multibyte +sequence before the next complete character, +.br mblen () +also returns \-1. +.pp +if +.i s +is null, the +.br mblen () +function +.\" the dinkumware doc and the single unix specification say this, but +.\" glibc doesn't implement this. +resets the shift state, known to only this function, to the initial state, and +returns nonzero if the encoding has nontrivial shift state, or zero if the +encoding is stateless. +.sh return value +the +.br mblen () +function returns the number of +bytes parsed from the multibyte +sequence starting at +.ir s , +if a non-null wide character was recognized. +it returns 0, if a null wide character was recognized. +it returns \-1, if an +invalid multibyte sequence was encountered or if it couldn't parse a complete +multibyte character. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br mblen () +t} thread safety mt-unsafe race +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh notes +the behavior of +.br mblen () +depends on the +.b lc_ctype +category of the +current locale. +.pp +the function +.br mbrlen (3) +provides a better interface to the same +functionality. +.sh see also +.br mbrlen (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/strfromd.3 + +.so man2/eventfd.2 + +.so man3/printf.3 + +.\" copyright (c) 2004 andries brouwer (aeb@cwi.nl) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th exit_group 2 2021-06-20 "linux" "linux programmer's manual" +.sh name +exit_group \- exit all threads in a process +.sh synopsis +.nf +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "noreturn void syscall(sys_exit_group, int " status ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br exit_group (), +necessitating the use of +.br syscall (2). +.sh description +this system call is equivalent to +.br _exit (2) +except that it terminates not only the calling thread, but all threads +in the calling process's thread group. +.sh return value +this system call does not return. +.sh versions +this call is present since linux 2.5.35. +.sh conforming to +this call is linux-specific. +.sh notes +since glibc 2.3, this is the system call invoked when the +.br _exit (2) +wrapper function is called. +.sh see also +.br exit (2) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/exec.3 + +.\" copyright (c) 1993 by thomas koenig (ig25@rz.uni-karlsruhe.de) +.\" and copyright (c) 2008 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified sat jul 24 18:40:56 1993 by rik faith (faith@cs.unc.edu) +.\" modified 1995 by mike battersby (mib@deakin.edu.au) +.\" +.th raise 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +raise \- send a signal to the caller +.sh synopsis +.nf +.b #include +.pp +.bi "int raise(int " sig ); +.fi +.sh description +the +.br raise () +function sends a signal to the calling process or thread. +in a single-threaded program it is equivalent to +.pp +.in +4n +.ex +kill(getpid(), sig); +.ee +.in +.pp +in a multithreaded program it is equivalent to +.pp +.in +4n +.ex +pthread_kill(pthread_self(), sig); +.ee +.in +.pp +if the signal causes a handler to be called, +.br raise () +will return only after the signal handler has returned. +.sh return value +.br raise () +returns 0 on success, and nonzero for failure. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br raise () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c89, c99. +.sh notes +since version 2.3.3, glibc implements +.br raise () +by calling +.br tgkill (2), +.\" 2.3.2 used the obsolete tkill(), if available. +if the kernel supports that system call. +older glibc versions implemented +.br raise () +using +.br kill (2). +.sh see also +.br getpid (2), +.br kill (2), +.br sigaction (2), +.br signal (2), +.br pthread_kill (3), +.br signal (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1993 by thomas koenig (ig25@rz.uni-karlsruhe.de) +.\" and copyright (c) 2002, 2006, 2020 by michael kerrisk +.\" and copyright (c) 2008 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified sat jul 24 17:34:08 1993 by rik faith (faith@cs.unc.edu) +.\" modified sun jan 7 01:41:27 1996 by andries brouwer (aeb@cwi.nl) +.\" modified sun apr 14 12:02:29 1996 by andries brouwer (aeb@cwi.nl) +.\" modified sat nov 13 16:28:23 1999 by andries brouwer (aeb@cwi.nl) +.\" modified 10 apr 2002, by michael kerrisk +.\" modified 7 jun 2002, by michael kerrisk +.\" added information on real-time signals +.\" modified 13 jun 2002, by michael kerrisk +.\" noted that sigstkflt is in fact unused +.\" 2004-12-03, modified mtk, added notes on rlimit_sigpending +.\" 2006-04-24, mtk, added text on changing signal dispositions, +.\" signal mask, and pending signals. +.\" 2008-07-04, mtk: +.\" added section on system call restarting (sa_restart) +.\" added section on stop/cont signals interrupting syscalls. +.\" 2008-10-05, mtk: various additions +.\" +.th signal 7 2021-03-22 "linux" "linux programmer's manual" +.sh name +signal \- overview of signals +.sh description +linux supports both posix reliable signals (hereinafter +"standard signals") and posix real-time signals. +.ss signal dispositions +each signal has a current +.ir disposition , +which determines how the process behaves when it is delivered +the signal. +.pp +the entries in the "action" column of the table below specify +the default disposition for each signal, as follows: +.ip term +default action is to terminate the process. +.ip ign +default action is to ignore the signal. +.ip core +default action is to terminate the process and dump core (see +.br core (5)). +.ip stop +default action is to stop the process. +.ip cont +default action is to continue the process if it is currently stopped. +.pp +a process can change the disposition of a signal using +.br sigaction (2) +or +.br signal (2). +(the latter is less portable when establishing a signal handler; +see +.br signal (2) +for details.) +using these system calls, a process can elect one of the +following behaviors to occur on delivery of the signal: +perform the default action; ignore the signal; +or catch the signal with a +.ir "signal handler" , +a programmer-defined function that is automatically invoked +when the signal is delivered. +.pp +by default, a signal handler is invoked on the +normal process stack. +it is possible to arrange that the signal handler +uses an alternate stack; see +.br sigaltstack (2) +for a discussion of how to do this and when it might be useful. +.pp +the signal disposition is a per-process attribute: +in a multithreaded application, the disposition of a +particular signal is the same for all threads. +.pp +a child created via +.br fork (2) +inherits a copy of its parent's signal dispositions. +during an +.br execve (2), +the dispositions of handled signals are reset to the default; +the dispositions of ignored signals are left unchanged. +.ss sending a signal +the following system calls and library functions allow +the caller to send a signal: +.tp +.br raise (3) +sends a signal to the calling thread. +.tp +.br kill (2) +sends a signal to a specified process, +to all members of a specified process group, +or to all processes on the system. +.tp +.br pidfd_send_signal (2) +sends a signal to a process identified by a pid file descriptor. +.tp +.br killpg (3) +sends a signal to all of the members of a specified process group. +.tp +.br pthread_kill (3) +sends a signal to a specified posix thread in the same process as +the caller. +.tp +.br tgkill (2) +sends a signal to a specified thread within a specific process. +(this is the system call used to implement +.br pthread_kill (3).) +.tp +.br sigqueue (3) +sends a real-time signal with accompanying data to a specified process. +.ss waiting for a signal to be caught +the following system calls suspend execution of the calling +thread until a signal is caught +(or an unhandled signal terminates the process): +.tp +.br pause (2) +suspends execution until any signal is caught. +.tp +.br sigsuspend (2) +temporarily changes the signal mask (see below) and suspends +execution until one of the unmasked signals is caught. +.\" +.ss synchronously accepting a signal +rather than asynchronously catching a signal via a signal handler, +it is possible to synchronously accept the signal, that is, +to block execution until the signal is delivered, +at which point the kernel returns information about the +signal to the caller. +there are two general ways to do this: +.ip * 2 +.br sigwaitinfo (2), +.br sigtimedwait (2), +and +.br sigwait (3) +suspend execution until one of the signals in a specified +set is delivered. +each of these calls returns information about the delivered signal. +.ip * +.br signalfd (2) +returns a file descriptor that can be used to read information +about signals that are delivered to the caller. +each +.br read (2) +from this file descriptor blocks until one of the signals +in the set specified in the +.br signalfd (2) +call is delivered to the caller. +the buffer returned by +.br read (2) +contains a structure describing the signal. +.ss signal mask and pending signals +a signal may be +.ir blocked , +which means that it will not be delivered until it is later unblocked. +between the time when it is generated and when it is delivered +a signal is said to be +.ir pending . +.pp +each thread in a process has an independent +.ir "signal mask" , +which indicates the set of signals that the thread is currently blocking. +a thread can manipulate its signal mask using +.br pthread_sigmask (3). +in a traditional single-threaded application, +.br sigprocmask (2) +can be used to manipulate the signal mask. +.pp +a child created via +.br fork (2) +inherits a copy of its parent's signal mask; +the signal mask is preserved across +.br execve (2). +.pp +a signal may be process-directed or thread-directed. +a process-directed signal is one that is targeted at (and thus pending for) +the process as a whole. +a signal may be process-directed +because it was generated by the kernel for reasons +other than a hardware exception, or because it was sent using +.br kill (2) +or +.br sigqueue (3). +a thread-directed signal is one that is targeted at a specific thread. +a signal may be thread-directed because it was generated as a consequence +of executing a specific machine-language instruction +that triggered a hardware exception (e.g., +.b sigsegv +for an invalid memory access, or +.b sigfpe +for a math error), or because it was +targeted at a specific thread using +interfaces such as +.br tgkill (2) +or +.br pthread_kill (3). +.pp +a process-directed signal may be delivered to any one of the +threads that does not currently have the signal blocked. +.\" joseph c. sible notes: +.\" on linux, if the main thread has the signal unblocked, then the kernel +.\" will always deliver the signal there, citing this kernel code +.\" +.\" per this comment in kernel/signal.c since time immemorial: +.\" +.\" /* +.\" * now find a thread we can wake up to take the signal off the queue. +.\" * +.\" * if the main thread wants the signal, it gets first crack. +.\" * probably the least surprising to the average bear. +.\" */ +.\" +.\" but this does not mean the signal will be delivered only in the +.\" main thread, since if a handler is already executing in the main thread +.\" (and thus the signal is blocked in that thread), then a further +.\" might be delivered in a different thread. +.\" +if more than one of the threads has the signal unblocked, then the +kernel chooses an arbitrary thread to which to deliver the signal. +.pp +a thread can obtain the set of signals that it currently has pending +using +.br sigpending (2). +this set will consist of the union of the set of pending +process-directed signals and the set of signals pending for +the calling thread. +.pp +a child created via +.br fork (2) +initially has an empty pending signal set; +the pending signal set is preserved across an +.br execve (2). +.\" +.ss execution of signal handlers +whenever there is a transition from kernel-mode to user-mode execution +(e.g., on return from a system call or scheduling of a thread onto the cpu), +the kernel checks whether there is a pending unblocked signal +for which the process has established a signal handler. +if there is such a pending signal, the following steps occur: +.ip 1. 3 +the kernel performs the necessary preparatory steps for execution of +the signal handler: +.rs +.ip a) 3 +the signal is removed from the set of pending signals. +.ip b) +if the signal handler was installed by a call to +.br sigaction (2) +that specified the +.br sa_onstack +flag and the thread has defined an alternate signal stack (using +.br sigaltstack (2)), +then that stack is installed. +.ip c) +various pieces of signal-related context are saved +into a special frame that is created on the stack. +the saved information includes: +.rs +.ip + 2 +the program counter register +(i.e., the address of the next instruction in the main program that +should be executed when the signal handler returns); +.ip + +architecture-specific register state required for resuming the +interrupted program; +.ip + +the thread's current signal mask; +.ip + +the thread's alternate signal stack settings. +.re +.ip +(if the signal handler was installed using the +.br sigaction (2) +.b sa_siginfo +flag, then the above information is accessible via the +.i ucontext_t +object that is pointed to by the third argument of the signal handler.) +.ip d) +any signals specified in +.i act\->sa_mask +when registering the handler with +.br sigprocmask (2) +are added to the thread's signal mask. +the signal being delivered is also +added to the signal mask, unless +.b sa_nodefer +was specified when registering the handler. +these signals are thus blocked while the handler executes. +.re +.ip 2. +the kernel constructs a frame for the signal handler on the stack. +the kernel sets the program counter for the thread to point to the first +instruction of the signal handler function, +and configures the return address for that function to point to a piece +of user-space code known as the signal trampoline (described in +.br sigreturn (2)). +.ip 3. +the kernel passes control back to user-space, where execution +commences at the start of the signal handler function. +.ip 4. +when the signal handler returns, control passes to the signal trampoline code. +.ip 5. +the signal trampoline calls +.br sigreturn (2), +a system call that uses the information in the stack frame created in step 1 +to restore the thread to its state before the signal handler was +called. +the thread's signal mask and alternate signal stack settings +are restored as part of this procedure. +upon completion of the call to +.br sigreturn (2), +the kernel transfers control back to user space, +and the thread recommences execution at the point where it was +interrupted by the signal handler. +.pp +note that if the signal handler does not return +(e.g., control is transferred out of the handler using +.br siglongjmp (3), +or the handler executes a new program with +.br execve (2)), +then the final step is not performed. +in particular, in such scenarios it is the programmer's responsibility +to restore the state of the signal mask (using +.br sigprocmask (2)), +if it is desired to unblock the signals that were blocked on entry +to the signal handler. +(note that +.br siglongjmp (3) +may or may not restore the signal mask, depending on the +.i savesigs +value that was specified in the corresponding call to +.br sigsetjmp (3).) +.pp +from the kernel's point of view, +execution of the signal handler code is exactly the same as the execution +of any other user-space code. +that is to say, the kernel does not record any special state information +indicating that the thread is currently executing inside a signal handler. +all necessary state information is maintained in user-space registers +and the user-space stack. +the depth to which nested signal handlers may be invoked is thus +limited only by the user-space stack (and sensible software design!). +.\" +.ss standard signals +linux supports the standard signals listed below. +the second column of the table indicates which standard (if any) +specified the signal: "p1990" indicates that the signal is described +in the original posix.1-1990 standard; +"p2001" indicates that the signal was added in susv2 and posix.1-2001. +.ts +l c c l +____ +lb c c l. +signal standard action comment +sigabrt p1990 core abort signal from \fbabort\fp(3) +sigalrm p1990 term timer signal from \fbalarm\fp(2) +sigbus p2001 core bus error (bad memory access) +sigchld p1990 ign child stopped or terminated +sigcld \- ign a synonym for \fbsigchld\fp +sigcont p1990 cont continue if stopped +sigemt \- term emulator trap +sigfpe p1990 core floating-point exception +sighup p1990 term hangup detected on controlling terminal + or death of controlling process +sigill p1990 core illegal instruction +siginfo \- a synonym for \fbsigpwr\fp +sigint p1990 term interrupt from keyboard +sigio \- term i/o now possible (4.2bsd) +sigiot \- core iot trap. a synonym for \fbsigabrt\fp +sigkill p1990 term kill signal +siglost \- term file lock lost (unused) +sigpipe p1990 term broken pipe: write to pipe with no + readers; see \fbpipe\fp(7) +sigpoll p2001 term pollable event (sys v); + synonym for \fbsigio\fp +sigprof p2001 term profiling timer expired +sigpwr \- term power failure (system v) +sigquit p1990 core quit from keyboard +sigsegv p1990 core invalid memory reference +sigstkflt \- term stack fault on coprocessor (unused) +sigstop p1990 stop stop process +sigtstp p1990 stop stop typed at terminal +sigsys p2001 core bad system call (svr4); + see also \fbseccomp\fp(2) +sigterm p1990 term termination signal +sigtrap p2001 core trace/breakpoint trap +sigttin p1990 stop terminal input for background process +sigttou p1990 stop terminal output for background process +sigunused \- core synonymous with \fbsigsys\fp +sigurg p2001 ign urgent condition on socket (4.2bsd) +sigusr1 p1990 term user-defined signal 1 +sigusr2 p1990 term user-defined signal 2 +sigvtalrm p2001 term virtual alarm clock (4.2bsd) +sigxcpu p2001 core cpu time limit exceeded (4.2bsd); + see \fbsetrlimit\fp(2) +sigxfsz p2001 core file size limit exceeded (4.2bsd); + see \fbsetrlimit\fp(2) +sigwinch \- ign window resize signal (4.3bsd, sun) +.te +.pp +the signals +.b sigkill +and +.b sigstop +cannot be caught, blocked, or ignored. +.pp +up to and including linux 2.2, the default behavior for +.br sigsys ", " sigxcpu ", " sigxfsz , +and (on architectures other than sparc and mips) +.b sigbus +was to terminate the process (without a core dump). +(on some other unix systems the default action for +.br sigxcpu " and " sigxfsz +is to terminate the process without a core dump.) +linux 2.4 conforms to the posix.1-2001 requirements for these signals, +terminating the process with a core dump. +.pp +.b sigemt +is not specified in posix.1-2001, but nevertheless appears +on most other unix systems, +where its default action is typically to terminate +the process with a core dump. +.pp +.b sigpwr +(which is not specified in posix.1-2001) is typically ignored +by default on those other unix systems where it appears. +.pp +.b sigio +(which is not specified in posix.1-2001) is ignored by default +on several other unix systems. +.\" +.ss queueing and delivery semantics for standard signals +if multiple standard signals are pending for a process, +the order in which the signals are delivered is unspecified. +.pp +standard signals do not queue. +if multiple instances of a standard signal are generated while +that signal is blocked, +then only one instance of the signal is marked as pending +(and the signal will be delivered just once when it is unblocked). +in the case where a standard signal is already pending, the +.i siginfo_t +structure (see +.br sigaction (2)) +associated with that signal is not overwritten +on arrival of subsequent instances of the same signal. +thus, the process will receive the information +associated with the first instance of the signal. +.\" +.ss signal numbering for standard signals +the numeric value for each signal is given in the table below. +as shown in the table, many signals have different numeric values +on different architectures. +the first numeric value in each table row shows the signal number +on x86, arm, and most other architectures; +the second value is for alpha and sparc; the third is for mips; +and the last is for parisc. +a dash (\-) denotes that a signal is absent on the corresponding architecture. +.ts +l c c c c l +l c c c c l +______ +lb c c c c l. +signal x86/arm alpha/ mips parisc notes + most others sparc +sighup \01 \01 \01 \01 +sigint \02 \02 \02 \02 +sigquit \03 \03 \03 \03 +sigill \04 \04 \04 \04 +sigtrap \05 \05 \05 \05 +sigabrt \06 \06 \06 \06 +sigiot \06 \06 \06 \06 +sigbus \07 10 10 10 +sigemt \- \07 \07 - +sigfpe \08 \08 \08 \08 +sigkill \09 \09 \09 \09 +sigusr1 10 30 16 16 +sigsegv 11 11 11 11 +sigusr2 12 31 17 17 +sigpipe 13 13 13 13 +sigalrm 14 14 14 14 +sigterm 15 15 15 15 +sigstkflt 16 \- \- \07 +sigchld 17 20 18 18 +sigcld \- \- 18 \- +sigcont 18 19 25 26 +sigstop 19 17 23 24 +sigtstp 20 18 24 25 +sigttin 21 21 26 27 +sigttou 22 22 27 28 +sigurg 23 16 21 29 +sigxcpu 24 24 30 12 +sigxfsz 25 25 31 30 +sigvtalrm 26 26 28 20 +sigprof 27 27 29 21 +sigwinch 28 28 20 23 +sigio 29 23 22 22 +sigpoll same as sigio +sigpwr 30 29/\- 19 19 +siginfo \- 29/\- \- \- +siglost \- \-/29 \- \- +sigsys 31 12 12 31 +sigunused 31 \- \- 31 +.te +.pp +note the following: +.ip * 3 +where defined, +.b sigunused +is synonymous with +.br sigsys . +since glibc 2.26, +.b sigunused +is no longer defined on any architecture. +.ip * +signal 29 is +.br siginfo / sigpwr +(synonyms for the same value) on alpha but +.b siglost +on sparc. +.\" +.ss real-time signals +starting with version 2.2, +linux supports real-time signals as originally defined in the posix.1b +real-time extensions (and now included in posix.1-2001). +the range of supported real-time signals is defined by the macros +.b sigrtmin +and +.br sigrtmax . +posix.1-2001 requires that an implementation support at least +.b _posix_rtsig_max +(8) real-time signals. +.pp +the linux kernel supports a range of 33 different real-time +signals, numbered 32 to 64. +however, the glibc posix threads implementation internally uses +two (for nptl) or three (for linuxthreads) real-time signals +(see +.br pthreads (7)), +and adjusts the value of +.b sigrtmin +suitably (to 34 or 35). +because the range of available real-time signals varies according +to the glibc threading implementation (and this variation can occur +at run time according to the available kernel and glibc), +and indeed the range of real-time signals varies across unix systems, +programs should +.ir "never refer to real-time signals using hard-coded numbers" , +but instead should always refer to real-time signals using the notation +.br sigrtmin +n, +and include suitable (run-time) checks that +.br sigrtmin +n +does not exceed +.br sigrtmax . +.pp +unlike standard signals, real-time signals have no predefined meanings: +the entire set of real-time signals can be used for application-defined +purposes. +.pp +the default action for an unhandled real-time signal is to terminate the +receiving process. +.pp +real-time signals are distinguished by the following: +.ip 1. 4 +multiple instances of real-time signals can be queued. +by contrast, if multiple instances of a standard signal are delivered +while that signal is currently blocked, then only one instance is queued. +.ip 2. 4 +if the signal is sent using +.br sigqueue (3), +an accompanying value (either an integer or a pointer) can be sent +with the signal. +if the receiving process establishes a handler for this signal using the +.b sa_siginfo +flag to +.br sigaction (2), +then it can obtain this data via the +.i si_value +field of the +.i siginfo_t +structure passed as the second argument to the handler. +furthermore, the +.i si_pid +and +.i si_uid +fields of this structure can be used to obtain the pid +and real user id of the process sending the signal. +.ip 3. 4 +real-time signals are delivered in a guaranteed order. +multiple real-time signals of the same type are delivered in the order +they were sent. +if different real-time signals are sent to a process, they are delivered +starting with the lowest-numbered signal. +(i.e., low-numbered signals have highest priority.) +by contrast, if multiple standard signals are pending for a process, +the order in which they are delivered is unspecified. +.pp +if both standard and real-time signals are pending for a process, +posix leaves it unspecified which is delivered first. +linux, like many other implementations, gives priority +to standard signals in this case. +.pp +according to posix, an implementation should permit at least +.b _posix_sigqueue_max +(32) real-time signals to be queued to +a process. +however, linux does things differently. +in kernels up to and including 2.6.7, linux imposes +a system-wide limit on the number of queued real-time signals +for all processes. +this limit can be viewed and (with privilege) changed via the +.i /proc/sys/kernel/rtsig\-max +file. +a related file, +.ir /proc/sys/kernel/rtsig\-nr , +can be used to find out how many real-time signals are currently queued. +in linux 2.6.8, these +.i /proc +interfaces were replaced by the +.b rlimit_sigpending +resource limit, which specifies a per-user limit for queued +signals; see +.br setrlimit (2) +for further details. +.pp +the addition of real-time signals required the widening +of the signal set structure +.ri ( sigset_t ) +from 32 to 64 bits. +consequently, various system calls were superseded by new system calls +that supported the larger signal sets. +the old and new system calls are as follows: +.ts +lb lb +l l. +linux 2.0 and earlier linux 2.2 and later +\fbsigaction\fp(2) \fbrt_sigaction\fp(2) +\fbsigpending\fp(2) \fbrt_sigpending\fp(2) +\fbsigprocmask\fp(2) \fbrt_sigprocmask\fp(2) +\fbsigreturn\fp(2) \fbrt_sigreturn\fp(2) +\fbsigsuspend\fp(2) \fbrt_sigsuspend\fp(2) +\fbsigtimedwait\fp(2) \fbrt_sigtimedwait\fp(2) +.te +.\" +.ss interruption of system calls and library functions by signal handlers +if a signal handler is invoked while a system call or library +function call is blocked, then either: +.ip * 2 +the call is automatically restarted after the signal handler returns; or +.ip * +the call fails with the error +.br eintr . +.pp +which of these two behaviors occurs depends on the interface and +whether or not the signal handler was established using the +.br sa_restart +flag (see +.br sigaction (2)). +the details vary across unix systems; +below, the details for linux. +.pp +if a blocked call to one of the following interfaces is interrupted +by a signal handler, then the call is automatically restarted +after the signal handler returns if the +.br sa_restart +flag was used; otherwise the call fails with the error +.br eintr : +.\" the following system calls use erestartsys, +.\" so that they are restartable +.ip * 2 +.br read (2), +.br readv (2), +.br write (2), +.br writev (2), +and +.br ioctl (2) +calls on "slow" devices. +a "slow" device is one where the i/o call may block for an +indefinite time, for example, a terminal, pipe, or socket. +if an i/o call on a slow device has already transferred some +data by the time it is interrupted by a signal handler, +then the call will return a success status +(normally, the number of bytes transferred). +note that a (local) disk is not a slow device according to this definition; +i/o operations on disk devices are not interrupted by signals. +.ip * +.br open (2), +if it can block (e.g., when opening a fifo; see +.br fifo (7)). +.ip * +.br wait (2), +.br wait3 (2), +.br wait4 (2), +.br waitid (2), +and +.br waitpid (2). +.ip * +socket interfaces: +.\" if a timeout (setsockopt()) is in effect on the socket, then these +.\" system calls switch to using eintr. consequently, they and are not +.\" automatically restarted, and they show the stop/cont behavior +.\" described below. (verified from 2.6.26 source, and by experiment; mtk) +.br accept (2), +.br connect (2), +.br recv (2), +.br recvfrom (2), +.br recvmmsg (2), +.br recvmsg (2), +.br send (2), +.br sendto (2), +and +.br sendmsg (2), +.\" fixme what about sendmmsg()? +unless a timeout has been set on the socket (see below). +.ip * +file locking interfaces: +.br flock (2) +and +the +.br f_setlkw +and +.br f_ofd_setlkw +operations of +.br fcntl (2) +.ip * +posix message queue interfaces: +.br mq_receive (3), +.br mq_timedreceive (3), +.br mq_send (3), +and +.br mq_timedsend (3). +.ip * +.br futex (2) +.b futex_wait +(since linux 2.6.22; +.\" commit 72c1bbf308c75a136803d2d76d0e18258be14c7a +beforehand, always failed with +.br eintr ). +.ip * +.br getrandom (2). +.ip * +.br pthread_mutex_lock (3), +.br pthread_cond_wait (3), +and related apis. +.ip * +.br futex (2) +.br futex_wait_bitset . +.ip * +posix semaphore interfaces: +.br sem_wait (3) +and +.br sem_timedwait (3) +(since linux 2.6.22; +.\" as a consequence of the 2.6.22 changes in the futex() implementation +beforehand, always failed with +.br eintr ). +.ip * +.br read (2) +from an +.br inotify (7) +file descriptor +(since linux 3.8; +.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06 +beforehand, always failed with +.br eintr ). +.pp +the following interfaces are never restarted after +being interrupted by a signal handler, +regardless of the use of +.br sa_restart ; +they always fail with the error +.b eintr +when interrupted by a signal handler: +.\" these are the system calls that give eintr or erestartnohand +.\" on interruption by a signal handler. +.ip * 2 +"input" socket interfaces, when a timeout +.rb ( so_rcvtimeo ) +has been set on the socket using +.br setsockopt (2): +.br accept (2), +.br recv (2), +.br recvfrom (2), +.br recvmmsg (2) +(also with a non-null +.ir timeout +argument), +and +.br recvmsg (2). +.ip * +"output" socket interfaces, when a timeout +.rb ( so_rcvtimeo ) +has been set on the socket using +.br setsockopt (2): +.br connect (2), +.br send (2), +.br sendto (2), +and +.br sendmsg (2). +.\" fixme what about sendmmsg()? +.ip * +interfaces used to wait for signals: +.br pause (2), +.br sigsuspend (2), +.br sigtimedwait (2), +and +.br sigwaitinfo (2). +.ip * +file descriptor multiplexing interfaces: +.br epoll_wait (2), +.br epoll_pwait (2), +.br poll (2), +.br ppoll (2), +.br select (2), +and +.br pselect (2). +.ip * +system v ipc interfaces: +.\" on some other systems, sa_restart does restart these system calls +.br msgrcv (2), +.br msgsnd (2), +.br semop (2), +and +.br semtimedop (2). +.ip * +sleep interfaces: +.br clock_nanosleep (2), +.br nanosleep (2), +and +.br usleep (3). +.ip * +.br io_getevents (2). +.pp +the +.br sleep (3) +function is also never restarted if interrupted by a handler, +but gives a success return: the number of seconds remaining to sleep. +.pp +in certain circumstances, the +.br seccomp (2) +user-space notification feature can lead to restarting of system calls +that would otherwise never be restarted by +.br sa_restart ; +for details, see +.br seccomp_unotify (2). +.\" +.ss interruption of system calls and library functions by stop signals +on linux, even in the absence of signal handlers, +certain blocking interfaces can fail with the error +.br eintr +after the process is stopped by one of the stop signals +and then resumed via +.br sigcont . +this behavior is not sanctioned by posix.1, and doesn't occur +on other systems. +.pp +the linux interfaces that display this behavior are: +.ip * 2 +"input" socket interfaces, when a timeout +.rb ( so_rcvtimeo ) +has been set on the socket using +.br setsockopt (2): +.br accept (2), +.br recv (2), +.br recvfrom (2), +.br recvmmsg (2) +(also with a non-null +.ir timeout +argument), +and +.br recvmsg (2). +.ip * +"output" socket interfaces, when a timeout +.rb ( so_rcvtimeo ) +has been set on the socket using +.br setsockopt (2): +.br connect (2), +.br send (2), +.br sendto (2), +and +.\" fixme what about sendmmsg()? +.br sendmsg (2), +if a send timeout +.rb ( so_sndtimeo ) +has been set. +.ip * 2 +.br epoll_wait (2), +.br epoll_pwait (2). +.ip * +.br semop (2), +.br semtimedop (2). +.ip * +.br sigtimedwait (2), +.br sigwaitinfo (2). +.ip * +linux 3.7 and earlier: +.br read (2) +from an +.br inotify (7) +file descriptor +.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06 +.ip * +linux 2.6.21 and earlier: +.br futex (2) +.br futex_wait , +.br sem_timedwait (3), +.br sem_wait (3). +.ip * +linux 2.6.8 and earlier: +.br msgrcv (2), +.br msgsnd (2). +.ip * +linux 2.4 and earlier: +.br nanosleep (2). +.sh conforming to +posix.1, except as noted. +.sh notes +for a discussion of async-signal-safe functions, see +.br signal\-safety (7). +.pp +the +.i /proc/[pid]/task/[tid]/status +file contains various fields that show the signals +that a thread is blocking +.ri ( sigblk ), +catching +.ri ( sigcgt ), +or ignoring +.ri ( sigign ). +(the set of signals that are caught or ignored will be the same +across all threads in a process.) +other fields show the set of pending signals that are directed to the thread +.ri ( sigpnd ) +as well as the set of pending signals that are directed +to the process as a whole +.ri ( shdpnd ). +the corresponding fields in +.i /proc/[pid]/status +show the information for the main thread. +see +.br proc (5) +for further details. +.sh bugs +there are six signals that can be delivered +as a consequence of a hardware exception: +.br sigbus , +.br sigemt , +.br sigfpe , +.br sigill , +.br sigsegv , +and +.br sigtrap . +which of these signals is delivered, +for any given hardware exception, +is not documented and does not always make sense. +.pp +for example, an invalid memory access that causes delivery of +.b sigsegv +on one cpu architecture may cause delivery of +.b sigbus +on another architecture, or vice versa. +.pp +for another example, using the x86 +.i int +instruction with a forbidden argument +(any number other than 3 or 128) +causes delivery of +.br sigsegv , +even though +.b sigill +would make more sense, +because of how the cpu reports the forbidden operation to the kernel. +.sh see also +.br kill (1), +.br clone (2), +.br getrlimit (2), +.br kill (2), +.br pidfd_send_signal (2), +.br restart_syscall (2), +.br rt_sigqueueinfo (2), +.br setitimer (2), +.br setrlimit (2), +.br sgetmask (2), +.br sigaction (2), +.br sigaltstack (2), +.br signal (2), +.br signalfd (2), +.br sigpending (2), +.br sigprocmask (2), +.br sigreturn (2), +.br sigsuspend (2), +.br sigwaitinfo (2), +.br abort (3), +.br bsd_signal (3), +.br killpg (3), +.br longjmp (3), +.br pthread_sigqueue (3), +.br raise (3), +.br sigqueue (3), +.br sigset (3), +.br sigsetops (3), +.br sigvec (3), +.br sigwait (3), +.br strsignal (3), +.br swapcontext (3), +.br sysv_signal (3), +.br core (5), +.br proc (5), +.br nptl (7), +.br pthreads (7), +.br sigevent (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2008 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_attr_setschedpolicy 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_attr_setschedpolicy, pthread_attr_getschedpolicy \- set/get +scheduling policy attribute in thread attributes object +.sh synopsis +.nf +.b #include +.pp +.bi "int pthread_attr_setschedpolicy(pthread_attr_t *" attr ", int " policy ); +.bi "int pthread_attr_getschedpolicy(const pthread_attr_t *restrict " attr , +.bi " int *restrict " policy ); +.pp +compile and link with \fi\-pthread\fp. +.fi +.sh description +the +.br pthread_attr_setschedpolicy () +function sets the scheduling policy attribute of the +thread attributes object referred to by +.ir attr +to the value specified in +.ir policy . +this attribute determines the scheduling policy of +a thread created using the thread attributes object +.ir attr . +.pp +the supported values for +.i policy +are +.br sched_fifo , +.br sched_rr , +and +.br sched_other , +with the semantics described in +.br sched (7). +.\" fixme . pthread_setschedparam() places no restriction on the policy, +.\" but pthread_attr_setschedpolicy() restricts policy to rr/fifo/other +.\" http://sourceware.org/bugzilla/show_bug.cgi?id=7013 +.pp +the +.br pthread_attr_getschedpolicy () +returns the scheduling policy attribute of the thread attributes object +.ir attr +in the buffer pointed to by +.ir policy . +.pp +in order for the policy setting made by +.br pthread_attr_setschedpolicy () +to have effect when calling +.br pthread_create (3), +the caller must use +.br pthread_attr_setinheritsched (3) +to set the inherit-scheduler attribute of the attributes object +.i attr +to +.br pthread_explicit_sched . +.sh return value +on success, these functions return 0; +on error, they return a nonzero error number. +.sh errors +.br pthread_attr_setschedpolicy () +can fail with the following error: +.tp +.b einval +invalid value in +.ir policy . +.pp +posix.1 also documents an optional +.b enotsup +error ("attempt was made to set the attribute to an unsupported value") for +.br pthread_attr_setschedpolicy (). +.\" .sh versions +.\" available since glibc 2.0. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_attr_setschedpolicy (), +.br pthread_attr_getschedpolicy () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh examples +see +.br pthread_setschedparam (3). +.sh see also +.ad l +.nh +.br pthread_attr_init (3), +.br pthread_attr_setinheritsched (3), +.br pthread_attr_setschedparam (3), +.br pthread_create (3), +.br pthread_setschedparam (3), +.br pthread_setschedprio (3), +.br pthreads (7), +.br sched (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/unlocked_stdio.3 + +.so man2/pkey_alloc.2 + +.\" manpage for /etc/dir_colors, config file for dircolors(1) +.\" extracted from color-ls 3.12.0.3 dircolors(1) manpage +.\" +.\" %%%license_start(ldpv1) +.\" this file may be copied under the conditions described +.\" in the ldp general public license, version 1, september 1998 +.\" that should have been distributed together with this file. +.\" %%%license_end +.\" +.\" modified sat dec 22 22:25:33 2001 by martin schulze +.\" +.th dir_colors 5 2020-08-13 "gnu" "linux user manual" +.sh name +dir_colors \- configuration file for dircolors(1) +.sh description +the program +.br ls (1) +uses the environment variable +.b ls_colors +to determine the colors in which the filenames are to be displayed. +this environment variable is usually set by a command like +.pp +.rs +eval \`dircolors some_path/dir_colors\` +.re +.pp +found in a system default shell initialization file, like +.i /etc/profile +or +.ir /etc/csh.cshrc . +(see also +.br dircolors (1).) +usually, the file used here is +.i /etc/dir_colors +and can be overridden by a +.i .dir_colors +file in one's home directory. +.pp +this configuration file consists of several statements, one per line. +anything right of a hash mark (#) is treated as a comment, if the +hash mark is at the beginning of a line or is preceded by at least one +whitespace. +blank lines are ignored. +.pp +the +.i global +section of the file consists of any statement before the first +.b term +statement. +any statement in the global section of the file is +considered valid for all terminal types. +following the global section +is one or more +.i terminal-specific +sections, preceded by one or more +.b term +statements which specify the terminal types (as given by the +.b term +environment variable) the following declarations apply to. +it is always possible to override a global declaration by a subsequent +terminal-specific one. +.pp +the following statements are recognized; case is insignificant: +.tp +.b term \fiterminal-type\fr +starts a terminal-specific section and specifies which terminal it +applies to. +multiple +.b term +statements can be used to create a section which applies for several +terminal types. +.tp +.b color yes|all|no|none|tty +(slackware only; ignored by gnu +.br dircolors (1).) +specifies that colorization should always be enabled (\fiyes\fr or +\fiall\fr), never enabled (\fino\fr or \finone\fr), or enabled only if +the output is a terminal (\fitty\fr). +the default is \fino\fr. +.tp +.b eightbit yes|no +(slackware only; ignored by gnu +.br dircolors (1).) +specifies that eight-bit iso 8859 characters should be enabled by +default. +for compatibility reasons, this can also be specified as 1 for +\fiyes\fr or 0 for \fino\fr. +the default is \fino\fr. +.tp +.b options \fioptions\fr +(slackware only; ignored by gnu +.br dircolors (1).) +adds command-line options to the default +.b ls +command line. +the options can be any valid +.b ls +command-line options, and should include the leading minus sign. +note that +.b dircolors +does not verify the validity of these options. +.tp +.b normal \ficolor-sequence\fr +specifies the color used for normal (nonfilename) text. +.ip +synonym: +.br norm . +.tp +.b file \ficolor-sequence\fr +specifies the color used for a regular file. +.tp +.b dir \ficolor-sequence\fr +specifies the color used for directories. +.tp +.b link \ficolor-sequence\fr +specifies the color used for a symbolic link. +.ip +synonyms: +.br lnk , +.br symlink . +.tp +.b orphan \ficolor-sequence\fr +specifies the color used for an orphaned symbolic link (one which +points to a nonexistent file). +if this is unspecified, +.b ls +will use the +.b link +color instead. +.tp +.b missing \ficolor-sequence\fr +specifies the color used for a missing file (a nonexistent file which +nevertheless has a symbolic link pointing to it). +if this is unspecified, +.b ls +will use the +.b file +color instead. +.tp +.b fifo \ficolor-sequence\fr +specifies the color used for a fifo (named pipe). +.ip +synonym: +.br pipe . +.tp +.b sock \ficolor-sequence\fr +specifies the color used for a socket. +.tp +.b door \ficolor-sequence\fr +(supported since fileutils 4.1) +specifies the color used for a door (solaris 2.5 and later). +.tp +.b blk \ficolor-sequence\fr +specifies the color used for a block device special file. +.ip +synonym: +.br block . +.tp +.b chr \ficolor-sequence\fr +specifies the color used for a character device special file. +.ip +synonym: +.br char . +.tp +.b exec \ficolor-sequence\fr +specifies the color used for a file with the executable attribute set. +.tp +.b suid \ficolor-sequence\fr +specifies the color used for a file with the set-user-id attribute set. +.ip +synonym: +.br setuid . +.tp +.b sgid \ficolor-sequence\fr +specifies the color used for a file with the set-group-id attribute set. +.ip +synonym: +.br setgid . +.tp +.b sticky \ficolor-sequence\fr +specifies the color used for a directory with the sticky attribute set. +.tp +.b sticky_other_writable \ficolor-sequence\fr +specifies the color used for an other-writable directory with the executable attribute set. +.ip +synonym: +.br owt . +.tp +.b other_writable \ficolor-sequence\fr +specifies the color used for an other-writable directory without the executable attribute set. +.ip +synonym: +.br owr . +.tp +.b leftcode \ficolor-sequence\fr +specifies the +.i "left code" +for non-iso\ 6429 terminals (see below). +.ip +synonym: +.br left . +.tp +.b rightcode \ficolor-sequence\fr +specifies the +.i "right code" +for non-iso\ 6429 terminals (see below). +.ip +synonym: +.br right . +.tp +.b endcode \ficolor-sequence\fr +specifies the +.i "end code" +for non-iso\ 6429 terminals (see below). +.ip +synonym: +.br end . +.tp +\fb*\fiextension\fr \ficolor-sequence\fr +specifies the color used for any file that ends in \fiextension\fr. +.tp +\fb .\fiextension\fr \ficolor-sequence\fr +same as \fb*\fr.\fiextension\fr. +specifies the color used for any file that +ends in .\fiextension\fr. +note that the period is included in the +extension, which makes it impossible to specify an extension not +starting with a period, such as +.b \(ti +for +.b emacs +backup files. +this form should be considered obsolete. +.ss iso 6429 (ansi) color sequences +most color-capable ascii terminals today use iso 6429 (ansi) color sequences, +and many common terminals without color capability, including +.b xterm +and the widely used and cloned dec vt100, will recognize iso 6429 color +codes and harmlessly eliminate them from the output or emulate them. +.b ls +uses iso 6429 codes by default, assuming colorization is enabled. +.pp +iso 6429 color sequences are composed of sequences of numbers +separated by semicolons. +the most common codes are: +.rs +.ts +l l. + 0 to restore default color + 1 for brighter colors + 4 for underlined text + 5 for flashing text +30 for black foreground +31 for red foreground +32 for green foreground +33 for yellow (or brown) foreground +34 for blue foreground +35 for purple foreground +36 for cyan foreground +37 for white (or gray) foreground +40 for black background +41 for red background +42 for green background +43 for yellow (or brown) background +44 for blue background +45 for purple background +46 for cyan background +47 for white (or gray) background +.te +.re +.pp +not all commands will work on all systems or display devices. +.pp +.b ls +uses the following defaults: +.ts +lb l l. +normal 0 normal (nonfilename) text +file 0 regular file +dir 32 directory +link 36 symbolic link +orphan undefined orphaned symbolic link +missing undefined missing file +fifo 31 named pipe (fifo) +sock 33 socket +blk 44;37 block device +chr 44;37 character device +exec 35 executable file +.te +.pp +a few terminal programs do not recognize the default +properly. +if all text gets colorized after you do a directory +listing, change the +.b normal +and +.b file +codes to the numerical codes for your normal foreground and background +colors. +.ss other terminal types (advanced configuration) +if you have a color-capable (or otherwise highlighting) terminal (or +printer!) which uses a different set of codes, you can still generate +a suitable setup. +to do so, you will have to use the +.br leftcode , +.br rightcode , +and +.b endcode +definitions. +.pp +when writing out a filename, +.b ls +generates the following output sequence: +.b leftcode +.i typecode +.b rightcode +.i filename +.br endcode , +where the +.i typecode +is the color sequence that depends on the type or name of file. +if the +.b endcode +is undefined, the sequence +.b "leftcode normal rightcode" +will be used instead. +the purpose of the left- and rightcodes is +merely to reduce the amount of typing necessary (and to hide ugly +escape codes away from the user). +if they are not appropriate for +your terminal, you can eliminate them by specifying the respective +keyword on a line by itself. +.pp +.b note: +if the +.b endcode +is defined in the global section of the setup file, it +.i cannot +be undefined in a terminal-specific section of the file. +this means any +.b normal +definition will have no effect. +a different +.b endcode +can, however, be specified, which would have the same effect. +.ss escape sequences +to specify control- or blank characters in the color sequences or +filename extensions, either c-style \e-escaped notation or +.br stty \-style +\(ha-notation can be used. +the c-style notation +includes the following characters: +.rs +.ts +lb l. +\ea bell (ascii 7) +\eb backspace (ascii 8) +\ee escape (ascii 27) +\ef form feed (ascii 12) +\en newline (ascii 10) +\er carriage return (ascii 13) +\et tab (ascii 9) +\ev vertical tab (ascii 11) +\e? delete (ascii 127) +\e\finnn any character (octal notation) +\ex\finnn any character (hexadecimal notation) +\e_ space +\e\e backslash (\e) +\e\(ha caret (\(ha) +\e# hash mark (#) +.te +.re +.pp +note that escapes are necessary to enter a space, backslash, +caret, or any control character anywhere in the string, as well as a +hash mark as the first character. +.sh files +.tp +.i /etc/dir_colors +system-wide configuration file. +.tp +.i \(ti/.dir_colors +per-user configuration file. +.pp +this page describes the +.b dir_colors +file format as used in the fileutils-4.1 package; +other versions may differ slightly. +.sh notes +the default +.b leftcode +and +.b rightcode +definitions, which are used by iso 6429 terminals are: +.rs +.ts +lb l. +leftcode \ee[ +rightcode m +.te +.re +.pp +the default +.b endcode +is undefined. +.sh see also +.br dircolors (1), +.br ls (1), +.br stty (1), +.br xterm (1) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/getrlimit.2 + +.so man3/ldexp.3 + +.\" copyright (c) 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sat jul 24 18:48:06 1993 by rik faith (faith@cs.unc.edu) +.\" modified fri jun 23 01:26:34 1995 by andries brouwer (aeb@cwi.nl) +.\" (prompted by scott burkett ) +.\" modified sun mar 28 23:44:38 1999 by andries brouwer (aeb@cwi.nl) +.\" +.th mktemp 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +mktemp \- make a unique temporary filename +.sh synopsis +.nf +.b #include +.pp +.bi "char *mktemp(char *" template ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br mktemp (): +.nf + since glibc 2.12: + (_xopen_source >= 500) && ! (_posix_c_source >= 200112l) + || /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _svid_source || _bsd_source + before glibc 2.12: + _bsd_source || _svid_source || _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended +.fi +.sh description +.ir "never use this function" ; +see bugs. +.pp +the +.br mktemp () +function generates a unique temporary filename +from \fitemplate\fp. +the last six characters of \fitemplate\fp must +be xxxxxx and these are replaced with a string that makes the +filename unique. +since it will be modified, +.i template +must not be a string constant, but should be declared as a character array. +.sh return value +the +.br mktemp () +function always returns \fitemplate\fp. +if a unique name was created, the last six bytes of \fitemplate\fp will +have been modified in such a way that the resulting name is unique +(i.e., does not exist already) +if a unique name could not be created, +\fitemplate\fp is made an empty string, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b einval +the last six characters of \fitemplate\fp were not xxxxxx. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br mktemp () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +4.3bsd, posix.1-2001. +posix.1-2008 removes the specification of +.br mktemp (). +.\" .sh notes +.\" the prototype is in +.\" .i +.\" for libc4, libc5, glibc1; glibc2 follows the single unix specification +.\" and has the prototype in +.\" .ir . +.sh bugs +never use +.br mktemp (). +some implementations follow 4.3bsd +and replace xxxxxx by the current process id and a single letter, +so that at most 26 different names can be returned. +since on the one hand the names are easy to guess, and on the other +hand there is a race between testing whether the name exists and +opening the file, every use of +.br mktemp () +is a security risk. +the race is avoided by +.br mkstemp (3) +and +.br mkdtemp (3). +.sh see also +.br mktemp (1), +.br mkdtemp (3), +.br mkstemp (3), +.br tempnam (3), +.br tmpfile (3), +.br tmpnam (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/ctanh.3 + +.\" copyright 1995 robert k. nichols (robert.k.nichols@att.com) +.\" copyright 1999-2005 kai mäkisara (kai.makisara@kolumbus.fi) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.th st 4 2020-04-11 "linux" "linux programmer's manual" +.sh name +st \- scsi tape device +.sh synopsis +.nf +.b #include +.pp +.bi "int ioctl(int " fd ", int " request " [, (void *)" arg3 "]);" +.bi "int ioctl(int " fd ", mtioctop, (struct mtop *)" mt_cmd ); +.bi "int ioctl(int " fd ", mtiocget, (struct mtget *)" mt_status ); +.bi "int ioctl(int " fd ", mtiocpos, (struct mtpos *)" mt_pos ); +.fi +.sh description +the +.b st +driver provides the interface to a variety of scsi tape devices. +currently, the driver takes control of all detected devices of type +\(lqsequential-access\(rq. +the +.b st +driver uses major device number 9. +.pp +each device uses eight minor device numbers. +the lowermost five bits +in the minor numbers are assigned sequentially in the order of +detection. +in the 2.6 kernel, the bits above the eight lowermost bits are +concatenated to the five lowermost bits to form the tape number. +the minor numbers can be grouped into +two sets of four numbers: the principal (auto-rewind) minor device numbers, +.ir n , +and the \(lqno-rewind\(rq device numbers, +.ri ( n " + 128)." +devices opened using the principal device number will be sent a +.br rewind +command when they are closed. +devices opened using the \(lqno-rewind\(rq device number will not. +(note that using an auto-rewind device for positioning the tape with, +for instance, mt does not lead to the desired result: the tape is +rewound after the mt command and the next command starts from the +beginning of the tape). +.pp +within each group, four minor numbers are available to define +devices with different characteristics (block size, compression, +density, etc.) +when the system starts up, only the first device is available. +the other three are activated when the default +characteristics are defined (see below). +(by changing compile-time +constants, it is possible to change the balance between the maximum +number of tape drives and the number of minor numbers for each +drive. +the default allocation allows control of 32 tape drives. +for instance, it is possible to control up to 64 tape drives +with two minor numbers for different options.) +.pp +devices are typically created by: +.pp +.in +4n +.ex +mknod \-m 666 /dev/st0 c 9 0 +mknod \-m 666 /dev/st0l c 9 32 +mknod \-m 666 /dev/st0m c 9 64 +mknod \-m 666 /dev/st0a c 9 96 +mknod \-m 666 /dev/nst0 c 9 128 +mknod \-m 666 /dev/nst0l c 9 160 +mknod \-m 666 /dev/nst0m c 9 192 +mknod \-m 666 /dev/nst0a c 9 224 +.ee +.in +.pp +there is no corresponding block device. +.pp +the driver uses an internal buffer that has to be large enough to hold +at least one tape block. +in kernels before 2.1.121, the buffer is +allocated as one contiguous block. +this limits the block size to the +largest contiguous block of memory the kernel allocator can provide. +the limit is currently 128\ kb for 32-bit architectures and +256\ kb for 64-bit architectures. +in newer kernels the driver +allocates the buffer in several parts if necessary. +by default, the +maximum number of parts is 16. +this means that the maximum block size +is very large (2\ mb if allocation of 16 blocks of 128\ kb succeeds). +.pp +the driver's internal buffer size is determined by a compile-time +constant which can be overridden with a kernel startup option. +in addition to this, the driver tries to allocate a larger temporary +buffer at run time if necessary. +however, run-time allocation of large +contiguous blocks of memory may fail and it is advisable not to rely +too much on dynamic buffer allocation with kernels older than 2.1.121 +(this applies also to demand-loading the driver with kerneld or kmod). +.pp +the driver does not specifically support any tape drive brand or +model. +after system start-up the tape device options are defined by +the drive firmware. +for example, if the drive firmware selects fixed-block mode, +the tape device uses fixed-block mode. +the options can +be changed with explicit +.br ioctl (2) +calls and remain in effect when the device is closed and reopened. +setting the options affects both the auto-rewind and the nonrewind +device. +.pp +different options can be specified for the different devices within +the subgroup of four. +the options take effect when the device is +opened. +for example, the system administrator can define +one device that writes in fixed-block mode with a certain block size, +and one which writes in variable-block mode (if the drive supports +both modes). +.pp +the driver supports +.b tape partitions +if they are supported by the drive. +(note that the tape partitions +have nothing to do with disk partitions. +a partitioned tape can be +seen as several logical tapes within one medium.) +partition support has to be enabled with an +.br ioctl (2). +the tape +location is preserved within each partition across partition changes. +the partition used for subsequent tape operations is +selected with an +.br ioctl (2). +the partition switch is executed together with +the next tape operation in order to avoid unnecessary tape +movement. +the maximum number of partitions on a tape is defined by a +compile-time constant (originally four). +the driver contains an +.br ioctl (2) +that can format a tape with either one or two partitions. +.pp +device +.i /dev/tape +is usually created as a hard or soft link to the default tape device +on the system. +.pp +starting from kernel 2.6.2, the driver exports in the sysfs directory +.i /sys/class/scsi_tape +the attached devices and some parameters assigned to the devices. +.ss data transfer +the driver supports operation in both fixed-block mode and +variable-block mode (if supported by the drive). +in fixed-block mode the drive +writes blocks of the specified size and the block size is not +dependent on the byte counts of the write system calls. +in variable-block mode one tape block is written for each write call +and the byte +count determines the size of the corresponding tape block. +note that +the blocks on the tape don't contain any information about the +writing mode: when reading, the only important thing is to use +commands that accept the block sizes on the tape. +.pp +in variable-block mode the read byte count does not have to match +the tape block size exactly. +if the byte count is larger than the +next block on tape, the driver returns the data and the function +returns the actual block size. +if the block size is larger than the +byte count, an error is returned. +.pp +in fixed-block mode the read byte counts can be arbitrary if +buffering is enabled, or a multiple of the tape block size if +buffering is disabled. +kernels before 2.1.121 allow writes with +arbitrary byte count if buffering is enabled. +in all other cases +(kernel before 2.1.121 with buffering disabled or newer kernel) the +write byte count must be a multiple of the tape block size. +.pp +in the 2.6 kernel, the driver tries to use direct transfers between the user +buffer and the device. +if this is not possible, the driver's internal buffer +is used. +the reasons for not using direct transfers include improper alignment +of the user buffer (default is 512 bytes but this can be changed by the hba +driver), one or more pages of the user buffer not reachable by the +scsi adapter, and so on. +.pp +a filemark is automatically written to tape if the last tape operation +before close was a write. +.pp +when a filemark is encountered while reading, the following +happens. +if there are data remaining in the buffer when the filemark +is found, the buffered data is returned. +the next read returns zero +bytes. +the following read returns data from the next file. +the end of +recorded data is signaled by returning zero bytes for two consecutive +read calls. +the third read returns an error. +.ss ioctls +the driver supports three +.br ioctl (2) +requests. +requests not recognized by the +.b st +driver are passed to the +.b scsi +driver. +the definitions below are from +.ir /usr/include/linux/mtio.h : +.ss mtioctop \(em perform a tape operation +this request takes an argument of type +.ir "(struct mtop\ *)" . +not all drives support all operations. +the driver returns an +.b eio +error if the drive rejects an operation. +.pp +.in +4n +.ex +/* structure for mtioctop \- mag tape op command: */ +struct mtop { + short mt_op; /* operations defined below */ + int mt_count; /* how many of them */ +}; +.ee +.in +.pp +magnetic tape operations for normal tape use: +.tp +.b mtbsf +backward space over +.i mt_count +filemarks. +.tp +.b mtbsfm +backward space over +.i mt_count +filemarks. +reposition the tape to the eot side of the last filemark. +.tp +.b mtbsr +backward space over +.i mt_count +records (tape blocks). +.tp +.b mtbss +backward space over +.i mt_count +setmarks. +.tp +.b mtcompression +enable compression of tape data within the drive if +.i mt_count +is nonzero and disable compression if +.i mt_count +is zero. +this command uses the mode page 15 supported by most dats. +.tp +.b mteom +go to the end of the recorded media (for appending files). +.tp +.b mterase +erase tape. +with 2.6 kernel, short erase (mark tape empty) is performed if the +argument is zero. +otherwise, long erase (erase all) is done. +.tp +.b mtfsf +forward space over +.i mt_count +filemarks. +.tp +.b mtfsfm +forward space over +.i mt_count +filemarks. +reposition the tape to the bot side of the last filemark. +.tp +.b mtfsr +forward space over +.i mt_count +records (tape blocks). +.tp +.b mtfss +forward space over +.i mt_count +setmarks. +.tp +.b mtload +execute the scsi load command. +a special case is available for some hp +autoloaders. +if +.i mt_count +is the constant +.b mt_st_hploader_offset +plus a number, the number is +sent to the drive to control the autoloader. +.tp +.b mtlock +lock the tape drive door. +.tp +.b mtmkpart +format the tape into one or two partitions. +if +.i mt_count +is positive, it gives the size of partition 1 and partition +0 contains the rest of the tape. +if +.i mt_count +is zero, the tape is formatted into one partition. +from kernel version 4.6, +.\" commit 8038e6456a3e6f5c4759e0d73c4f9165b90c93e7 +a negative +.i mt_count +specifies the size of partition 0 and +the rest of the tape contains partition 1. +the physical ordering of partitions depends on the drive. +this command is not allowed for a drive unless the partition support +is enabled for the drive (see +.br mt_st_can_partitions +below). +.tp +.b mtnop +no op\(emflushes the driver's buffer as a side effect. +should be used before reading status with +.br mtiocget . +.tp +.b mtoffl +rewind and put the drive off line. +.tp +.b mtreset +reset drive. +.tp +.b mtreten +re-tension tape. +.tp +.b mtrew +rewind. +.tp +.b mtseek +seek to the tape block number specified in +.ir mt_count . +this operation requires either a scsi-2 drive that supports the +.b locate +command (device-specific address) +or a tandberg-compatible scsi-1 drive (tandberg, archive +viper, wangtek, ...). +the block number should be one that was previously returned by +.br mtiocpos +if device-specific addresses are used. +.tp +.b mtsetblk +set the drive's block length to the value specified in +.ir mt_count . +a block length of zero sets the drive to variable block size mode. +.tp +.b mtsetdensity +set the tape density to the code in +.ir mt_count . +the density codes supported by a drive can be found from the drive +documentation. +.tp +.b mtsetpart +the active partition is switched to +.ir mt_count . +the partitions are numbered from zero. +this command is not allowed for +a drive unless the partition support is enabled for the drive (see +.b mt_st_can_partitions +below). +.tp +.b mtunload +execute the scsi unload command (does not eject the tape). +.tp +.b mtunlock +unlock the tape drive door. +.tp +.b mtweof +write +.i mt_count +filemarks. +.tp +.b mtwsm +write +.i mt_count +setmarks. +.pp +magnetic tape operations for setting of device options (by the superuser): +.tp +.b mtsetdrvbuffer +set various drive and driver options according to bits encoded in +.ir mt_count . +these consist of the drive's buffering mode, a set of boolean driver +options, the buffer write threshold, defaults for the block size and +density, and timeouts (only in kernels 2.1 and later). +a single operation can affect only one item in the list below (the +booleans counted as one item.) +.ip +a value having zeros in the high-order 4 bits will be used to set the +drive's buffering mode. +the buffering modes are: +.rs 12 +.ip 0 4 +the drive will not report +.br good +status on write commands until the data +blocks are actually written to the medium. +.ip 1 +the drive may report +.br good +status on write commands as soon as all the +data has been transferred to the drive's internal buffer. +.ip 2 +the drive may report +.br good +status on write commands as soon as (a) all +the data has been transferred to the drive's internal buffer, and +(b) all buffered data from different initiators has been successfully +written to the medium. +.re +.ip +to control the write threshold the value in +.i mt_count +must include the constant +.br mt_st_write_threshold +bitwise ored with a block count in the low 28 bits. +the block count refers to 1024-byte blocks, not the physical block +size on the tape. +the threshold cannot exceed the driver's internal buffer size (see +description, above). +.ip +to set and clear the boolean options +the value in +.i mt_count +must include one of the constants +.br mt_st_booleans , +.br mt_st_setbooleans , +.br mt_st_clearbooleans , +or +.br mt_st_defbooleans +bitwise ored with +whatever combination of the following options is desired. +using +.br mt_st_booleans +the options can be set to the values +defined in the corresponding bits. +with +.br mt_st_setbooleans +the options can be selectively set and with +.br mt_st_defbooleans +selectively cleared. +.ip "" +the default options for a tape device are set with +.br mt_st_defbooleans . +a nonactive tape device (e.g., device with +minor 32 or 160) is activated when the default options for it are +defined the first time. +an activated device inherits from the device +activated at start-up the options not set explicitly. +.ip "" +the boolean options are: +.rs +.tp +.br mt_st_buffer_writes " (default: true)" +buffer all write operations in fixed-block mode. +if this option is false and the drive uses a fixed block size, then +all write operations must be for a multiple of the block size. +this option must be set false to write reliable multivolume archives. +.tp +.br mt_st_async_writes " (default: true)" +when this option is true, write operations return immediately without +waiting for the data to be transferred to the drive if the data fits +into the driver's buffer. +the write threshold determines how full the buffer must be before a +new scsi write command is issued. +any errors reported by the drive will be held until the next +operation. +this option must be set false to write reliable multivolume archives. +.tp +.br mt_st_read_ahead " (default: true)" +this option causes the driver to provide read buffering and +read-ahead in fixed-block mode. +if this option is false and the drive uses a fixed block size, then +all read operations must be for a multiple of the block size. +.tp +.br mt_st_two_fm " (default: false)" +this option modifies the driver behavior when a file is closed. +the normal action is to write a single filemark. +if the option is true, the driver will write two filemarks and +backspace over the second one. +.ip +note: +this option should not be set true for qic tape drives since they are +unable to overwrite a filemark. +these drives detect the end of recorded data by testing for blank tape +rather than two consecutive filemarks. +most other current drives also +detect the end of recorded data and using two filemarks is usually +necessary only when interchanging tapes with some other systems. +.tp +.br mt_st_debugging " (default: false)" +this option turns on various debugging messages from the driver +(effective only if the driver was compiled with +.b debug +defined nonzero). +.tp +.br mt_st_fast_eom " (default: false)" +this option causes the +.b mteom +operation to be sent directly to the +drive, potentially speeding up the operation but causing the driver to +lose track of the current file number normally returned by the +.b mtiocget +request. +if +.b mt_st_fast_eom +is false, the driver will respond to an +.b mteom +request by forward spacing over files. +.tp +.br mt_st_auto_lock " (default: false)" +when this option is true, the drive door is locked when the device file is +opened and unlocked when it is closed. +.tp +.br mt_st_def_writes " (default: false)" +the tape options (block size, mode, compression, etc.) may change +when changing from one device linked to a drive to another device +linked to the same drive depending on how the devices are +defined. +this option defines when the changes are enforced by the +driver using scsi-commands and when the drives auto-detection +capabilities are relied upon. +if this option is false, the driver +sends the scsi-commands immediately when the device is changed. +if the +option is true, the scsi-commands are not sent until a write is +requested. +in this case, the drive firmware is allowed to detect the +tape structure when reading and the scsi-commands are used only to +make sure that a tape is written according to the correct specification. +.tp +.br mt_st_can_bsr " (default: false)" +when read-ahead is used, the tape must sometimes be spaced backward to the +correct position when the device is closed and the scsi command to +space backward over records is used for this purpose. +some older +drives can't process this command reliably and this option can be used +to instruct the driver not to use the command. +the end result is that, +with read-ahead and fixed-block mode, the tape may not be correctly +positioned within a file when the device is closed. +with 2.6 kernel, the +default is true for drives supporting scsi-3. +.tp +.br mt_st_no_blklims " (default: false)" +some drives don't accept the +.b "read block limits" +scsi command. +if this is used, the driver does not use the command. +the drawback is +that the driver can't check before sending commands if the selected +block size is acceptable to the drive. +.tp +.br mt_st_can_partitions " (default: false)" +this option enables support for several partitions within a +tape. +the option applies to all devices linked to a drive. +.tp +.br mt_st_scsi2logical " (default: false)" +this option instructs the driver to use the logical block addresses +defined in the scsi-2 standard when performing the seek and tell +operations (both with +.b mtseek +and +.b mtiocpos +commands and when changing tape +partition). +otherwise, the device-specific addresses are used. +it is highly advisable to set this option if the drive supports the +logical addresses because they count also filemarks. +there are some +drives that support only the logical block addresses. +.tp +.br mt_st_sysv " (default: false)" +when this option is enabled, the tape devices use the system v +semantics. +otherwise, the bsd semantics are used. +the most important +difference between the semantics is what happens when a device used +for reading is closed: in system v semantics the tape is spaced forward +past the next filemark if this has not happened while using the +device. +in bsd semantics the tape position is not changed. +.tp +.br mt_no_wait " (default: false)" +enables immediate mode (i.e., don't wait for the command to finish) for some +commands (e.g., rewind). +.pp +an example: +.pp +.in +4n +.ex +struct mtop mt_cmd; +mt_cmd.mt_op = mtsetdrvbuffer; +mt_cmd.mt_count = mt_st_booleans | + mt_st_buffer_writes | mt_st_async_writes; +ioctl(fd, mtioctop, mt_cmd); +.ee +.in +.re +.ip "" +the default block size for a device can be set with +.b mt_st_def_blksize +and the default density code can be set with +.br mt_st_defdensity . +the values for the parameters are or'ed +with the operation code. +.ip "" +with kernels 2.1.x and later, the timeout values can be set with the +subcommand +.b mt_st_set_timeout +ored with the timeout in seconds. +the long timeout (used for rewinds and other commands +that may take a long time) can be set with +.br mt_st_set_long_timeout . +the kernel defaults are very long to +make sure that a successful command is not timed out with any +drive. +because of this, the driver may seem stuck even if it is only +waiting for the timeout. +these commands can be used to set more +practical values for a specific drive. +the timeouts set for one device +apply for all devices linked to the same drive. +.ip "" +starting from kernels 2.4.19 and 2.5.43, the driver supports a status +bit which indicates whether the drive requests cleaning. +the method used by the +drive to return cleaning information is set using the +.b mt_st_sel_cln +subcommand. +if the value is zero, the cleaning +bit is always zero. +if the value is one, the tapealert data defined +in the scsi-3 standard is used (not yet implemented). +values 2\(en17 are +reserved. +if the lowest eight bits are >= 18, bits from the extended +sense data are used. +the bits 9\(en16 specify a mask to select the bits +to look at and the bits 17\(en23 specify the bit pattern to look for. +if the bit pattern is zero, one or more bits under the mask indicate +the cleaning request. +if the pattern is nonzero, the pattern must match +the masked sense data byte. +.ss mtiocget \(em get status +this request takes an argument of type +.ir "(struct mtget\ *)" . +.pp +.in +4n +.ex +/* structure for mtiocget \- mag tape get status command */ +struct mtget { + long mt_type; + long mt_resid; + /* the following registers are device dependent */ + long mt_dsreg; + long mt_gstat; + long mt_erreg; + /* the next two fields are not always used */ + daddr_t mt_fileno; + daddr_t mt_blkno; +}; +.ee +.in +.tp +\fimt_type\fp +the header file defines many values for +.ir mt_type , +but the current driver reports only the generic types +.b mt_isscsi1 +(generic scsi-1 tape) +and +.b mt_isscsi2 +(generic scsi-2 tape). +.tp +\fimt_resid\fp +contains the current tape partition number. +.tp +\fimt_dsreg\fp +reports the drive's current settings for block size (in the low 24 +bits) and density (in the high 8 bits). +these fields are defined by +.br mt_st_blksize_shift , +.br mt_st_blksize_mask , +.br mt_st_density_shift , +and +.br mt_st_density_mask . +.tp +\fimt_gstat\fp +reports generic (device independent) status information. +the header file defines macros for testing these status bits: +.rs +.hp 4 +\fbgmt_eof\fp(\fix\fp): +the tape is positioned just after a filemark +(always false after an +.b mtseek +operation). +.hp +\fbgmt_bot\fp(\fix\fp): +the tape is positioned at the beginning of the first file (always false +after an +.b mtseek +operation). +.hp +\fbgmt_eot\fp(\fix\fp): +a tape operation has reached the physical end of tape. +.hp +\fbgmt_sm\fp(\fix\fp): +the tape is currently positioned at a setmark +(always false after an +.b mtseek +operation). +.hp +\fbgmt_eod\fp(\fix\fp): +the tape is positioned at the end of recorded data. +.hp +\fbgmt_wr_prot\fp(\fix\fp): +the drive is write-protected. +for some drives this can also mean that the drive does not support +writing on the current medium type. +.hp +\fbgmt_online\fp(\fix\fp): +the last +.br open (2) +found the drive with a tape in place and ready for operation. +.hp +\fbgmt_d_6250\fp(\fix\fp), \fbgmt_d_1600\fp(\fix\fp), \fbgmt_d_800\fp(\fix\fp): +this \(lqgeneric\(rq status information reports the current +density setting for 9-track \(12" tape drives only. +.hp +\fbgmt_dr_open\fp(\fix\fp): +the drive does not have a tape in place. +.hp +\fbgmt_im_rep_en\fp(\fix\fp): +immediate report mode. +this bit is set if there are no guarantees that +the data has been physically written to the tape when the write call +returns. +it is set zero only when the driver does not buffer data and +the drive is set not to buffer data. +.hp +\fbgmt_cln\fp(\fix\fp): +the drive has requested cleaning. +implemented in kernels since 2.4.19 and 2.5.43. +.re +.tp +\fimt_erreg\fp +the only field defined in +.i mt_erreg +is the recovered error count in the low 16 bits (as defined by +.br mt_st_softerr_shift +and +.br mt_st_softerr_mask ). +due to inconsistencies in the way drives report recovered errors, this +count is often not maintained (most drives do not by default report +soft errors but this can be changed with a scsi mode select command). +.tp +\fimt_fileno\fp +reports the current file number (zero-based). +this value is set to \-1 when the file number is unknown (e.g., after +.br mtbss +or +.br mtseek ). +.tp +\fimt_blkno\fp +reports the block number (zero-based) within the current file. +this value is set to \-1 when the block number is unknown (e.g., after +.br mtbsf , +.br mtbss , +or +.br mtseek ). +.ss mtiocpos \(em get tape position +this request takes an argument of type +.i "(struct mtpos\ *)" +and reports the drive's notion of the current tape block number, +which is not the same as +.i mt_blkno +returned by +.br mtiocget . +this drive must be a scsi-2 drive that supports the +.b "read position" +command (device-specific address) +or a tandberg-compatible scsi-1 drive (tandberg, archive +viper, wangtek, ... ). +.pp +.in +4n +.ex +/* structure for mtiocpos \- mag tape get position command */ +struct mtpos { + long mt_blkno; /* current block number */ +}; +.ee +.in +.sh return value +.tp +.b eacces +an attempt was made to write or erase a write-protected tape. +(this error is not detected during +.br open (2).) +.tp +.b ebusy +the device is already in use or the driver was unable to allocate a +buffer. +.tp +.b efault +the command parameters point to memory not belonging to the calling +process. +.tp +.b einval +an +.br ioctl (2) +had an invalid argument, or a requested block size was invalid. +.tp +.b eio +the requested operation could not be completed. +.tp +.b enomem +the byte count in +.br read (2) +is smaller than the next physical block on the tape. +(before 2.2.18 and 2.4.0 the extra bytes have been +.\" precisely: linux 2.6.0-test6 +silently ignored.) +.tp +.b enospc +a write operation could not be completed because the tape reached +end-of-medium. +.tp +.b enosys +unknown +.br ioctl (2). +.tp +.b enxio +during opening, the tape device does not exist. +.tp +.b eoverflow +an attempt was made to read or write a variable-length block that is +larger than the driver's internal buffer. +.tp +.b erofs +open is attempted with +.b o_wronly +or +.b o_rdwr +when the tape in the drive is write-protected. +.sh files +.tp +.i /dev/st* +the auto-rewind scsi tape devices +.tp +.i /dev/nst* +the nonrewind scsi tape devices +.\" .sh author +.\" the driver has been written by kai m\(:akisara (kai.makisara@metla.fi) +.\" starting from a driver written by dwayne forsyth. +.\" several other +.\" people have also contributed to the driver. +.sh notes +.ip 1. 4 +when exchanging data between systems, both systems have to agree on +the physical tape block size. +the parameters of a drive after startup +are often not the ones most operating systems use with these +devices. +most systems use drives in variable-block mode if the drive +supports that mode. +this applies to most modern drives, including +dats, 8mm helical scan drives, dlts, etc. +it may be advisable to use +these drives in variable-block mode also in linux (i.e., use +.b mtsetblk +or +.b mtsetdefblk +at system startup to set the mode), at least when +exchanging data with a foreign system. +the drawback of +this is that a fairly large tape block size has to be used to get +acceptable data transfer rates on the scsi bus. +.ip 2. +many programs (e.g., +.br tar (1)) +allow the user to specify the blocking +factor on the command line. +note that this determines the physical block +size on tape only in variable-block mode. +.ip 3. +in order to use scsi tape drives, the basic scsi driver, +a scsi-adapter driver and the scsi tape driver must be either +configured into the kernel or loaded as modules. +if the scsi-tape +driver is not present, the drive is recognized but the tape support +described in this page is not available. +.ip 4. +the driver writes error messages to the console/log. +the sense +codes written into some messages are automatically translated to text +if verbose scsi messages are enabled in kernel configuration. +.ip 5. +the driver's internal buffering allows good throughput in fixed-block +mode also with small +.br read (2) +and +.br write (2) +byte counts. +with direct transfers +this is not possible and may cause a surprise when moving to the 2.6 +kernel. +the solution is to tell the software to use larger transfers (often +telling it to use larger blocks). +if this is not possible, direct transfers can be disabled. +.sh see also +.br mt (1) +.pp +the file +.i drivers/scsi/readme.st +or +.i documentation/scsi/st.txt +(kernel >= 2.6) in the linux kernel source tree contains +the most recent information about the driver and its configuration +possibilities +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getspnam.3 + +.\" copyright (c) bruno haible +.\" +.\" %%%license_start(gplv2+_doc_onepara) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" %%%license_end +.\" +.\" references consulted: +.\" gnu glibc-2 source code and manual +.\" dinkumware c library reference http://www.dinkumware.com/ +.\" opengroup's single unix specification http://www.unix-systems.org/online.html +.\" iso/iec 9899:1999 +.\" +.th wcspbrk 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +wcspbrk \- search a wide-character string for any of a set of wide characters +.sh synopsis +.nf +.b #include +.pp +.bi "wchar_t *wcspbrk(const wchar_t *" wcs ", const wchar_t *" accept ); +.fi +.sh description +the +.br wcspbrk () +function is the wide-character equivalent +of the +.br strpbrk (3) +function. +it searches for the first occurrence in the wide-character +string pointed to by +.i wcs +of any of the +characters in the wide-character +string pointed to by +.ir accept . +.sh return value +the +.br wcspbrk () +function returns a pointer to the first occurrence in +.i wcs +of any of the characters listed in +.ir accept . +if +.i wcs +contains none of these characters, null is returned. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br wcspbrk () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c99. +.sh see also +.br strpbrk (3), +.br wcschr (3), +.br wcscspn (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/utf-8.7 + +.\" copyright (c) 1993 by thomas koenig (ig25@rz.uni-karlsruhe.de) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified sat jul 24 18:42:59 1993 by rik faith (faith@cs.unc.edu) +.th puts 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +fputc, fputs, putc, putchar, puts \- output of characters and strings +.sh synopsis +.nf +.b #include +.pp +.bi "int fputc(int " c ", file *" stream ); +.bi "int putc(int " c ", file *" stream ); +.bi "int putchar(int " c ); +.pp +.bi "int fputs(const char *restrict " s ", file *restrict " stream ); +.bi "int puts(const char *" s ); +.fi +.sh description +.br fputc () +writes the character +.ir c , +cast to an +.ir "unsigned char" , +to +.ir stream . +.pp +.br putc () +is equivalent to +.br fputc () +except that it may be implemented as a macro which evaluates +.i stream +more than once. +.pp +.bi "putchar(" c ) +is equivalent to +.bi "putc(" c ", " stdout ) \fr. +.pp +.br fputs () +writes the string +.i s +to +.ir stream , +without its terminating null byte (\(aq\e0\(aq). +.pp +.br puts () +writes the string +.i s +and a trailing newline +to +.ir stdout . +.pp +calls to the functions described here can be mixed with each other and with +calls to other output functions from the +.i stdio +library for the same output stream. +.pp +for nonlocking counterparts, see +.br unlocked_stdio (3). +.sh return value +.br fputc (), +.br putc (), +and +.br putchar () +return the character written as an +.i unsigned char +cast to an +.i int +or +.b eof +on error. +.pp +.br puts () +and +.br fputs () +return a nonnegative number on success, or +.b eof +on error. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br fputc (), +.br fputs (), +.br putc (), +.br putchar (), +.br puts () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, c89, c99. +.sh bugs +it is not advisable to mix calls to output functions from the +.i stdio +library with low-level calls to +.br write (2) +for the file descriptor associated with the same output stream; the results +will be undefined and very probably not what you want. +.sh see also +.br write (2), +.br ferror (3), +.br fgets (3), +.br fopen (3), +.br fputwc (3), +.br fputws (3), +.br fseek (3), +.br fwrite (3), +.br putwchar (3), +.br scanf (3), +.br unlocked_stdio (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-6.7 + +.so man3/slist.3 + +.\" copyright (c) 2014 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th uselocale 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +uselocale \- set/get the locale for the calling thread +.sh synopsis +.nf +.b #include +.pp +.bi "locale_t uselocale(locale_t " newloc ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br uselocale (): +.nf + since glibc 2.10: + _xopen_source >= 700 + before glibc 2.10: + _gnu_source +.fi +.sh description +the +.br uselocale () +function sets the current locale for the calling thread, +and returns the thread's previously current locale. +after a successful call to +.br uselocale (), +any calls by this thread to functions that depend on the locale +will operate as though the locale has been set to +.ir newloc . +.pp +the +.i newloc +argument can have one of the following values: +.tp +a handle returned by a call to \fbnewlocale\fp(3) or \fbduplocale\fp(3) +the calling thread's current locale is set to the specified locale. +.tp +the special locale object handle \fblc_global_locale\fp +the calling thread's current locale is set to the global locale determined by +.br setlocale (3). +.tp +.i "(locale_t) 0" +the calling thread's current locale is left unchanged +(and the current locale is returned as the function result). +.sh return value +on success, +.br uselocale () +returns the locale handle that was set by the previous call to +.br uselocale () +in this thread, or +.b lc_global_locale +if there was no such previous call. +on error, it returns +.ir "(locale_t)\ 0" , +and sets +.i errno +to indicate the error. +.sh errors +.tp +.b einval +.i newloc +does not refer to a valid locale object. +.sh versions +the +.br uselocale () +function first appeared in version 2.3 of the gnu c library. +.sh conforming to +posix.1-2008. +.sh notes +unlike +.br setlocale (3), +.br uselocale () +does not allow selective replacement of individual locale categories. +to employ a locale that differs in only a few categories from the current +locale, use calls to +.br duplocale (3) +and +.br newlocale (3) +to obtain a locale object equivalent to the current locale and +modify the desired categories in that object. +.sh examples +see +.br newlocale (3) +and +.br duplocale (3). +.sh see also +.br locale (1), +.br duplocale (3), +.br freelocale (3), +.br newlocale (3), +.br setlocale (3), +.br locale (5), +.br locale (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 1980, 1991 regents of the university of california. +.\" all rights reserved. +.\" +.\" this code is derived from software contributed to berkeley by +.\" the american national standards committee x3, on information +.\" processing systems. +.\" +.\" %%%license_start(bsd_4_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. all advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" this product includes software developed by the university of +.\" california, berkeley and its contributors. +.\" 4. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" @(#)setbuf.3 6.10 (berkeley) 6/29/91 +.\" +.\" converted for linux, mon nov 29 14:55:24 1993, faith@cs.unc.edu +.\" added section to bugs, sun mar 12 22:28:33 met 1995, +.\" thomas.koenig@ciw.uni-karlsruhe.de +.\" correction, sun, 11 apr 1999 15:55:18, +.\" martin vicente +.\" correction, 2000-03-03, andreas jaeger +.\" added return value for setvbuf, aeb, +.\" +.th setbuf 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +setbuf, setbuffer, setlinebuf, setvbuf \- stream buffering operations +.sh synopsis +.nf +.b #include +.pp +.bi "int setvbuf(file *restrict " stream ", char *restrict " buf , +.bi " int " mode ", size_t " size ); +.pp +.bi "void setbuf(file *restrict " stream ", char *restrict " buf ); +.bi "void setbuffer(file *restrict " stream ", char *restrict " buf , +.bi " size_t " size ); +.bi "void setlinebuf(file *" stream ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br setbuffer (), +.br setlinebuf (): +.nf + since glibc 2.19: + _default_source + glibc 2.19 and earlier: + _bsd_source +.fi +.sh description +the three types of buffering available are unbuffered, block buffered, and +line buffered. +when an output stream is unbuffered, information appears on +the destination file or terminal as soon as written; when it is block +buffered, many characters are saved up and written as a block; when it is +line buffered, characters are saved up until a newline is output or input is +read from any stream attached to a terminal device (typically \fistdin\fp). +the function +.br fflush (3) +may be used to force the block out early. +(see +.br fclose (3).) +.pp +normally all files are block buffered. +if a stream refers to a terminal (as +.i stdout +normally does), it is line buffered. +the standard error stream +.i stderr +is always unbuffered by default. +.pp +the +.br setvbuf () +function may be used on any open stream to change its buffer. +the +.i mode +argument must be one of the following three macros: +.rs +.tp +.b _ionbf +unbuffered +.tp +.b _iolbf +line buffered +.tp +.b _iofbf +fully buffered +.re +.pp +except for unbuffered files, the +.i buf +argument should point to a buffer at least +.i size +bytes long; this buffer will be used instead of the current buffer. +if the argument +.i buf +is null, +only the mode is affected; a new buffer will be allocated on the next read +or write operation. +the +.br setvbuf () +function may be used only after opening a stream and before any other +operations have been performed on it. +.pp +the other three calls are, in effect, simply aliases for calls to +.br setvbuf (). +the +.br setbuf () +function is exactly equivalent to the call +.pp +.in +4n +setvbuf(stream, buf, buf ? _iofbf : _ionbf, bufsiz); +.in +.pp +the +.br setbuffer () +function is the same, except that the size of the buffer is up to the +caller, rather than being determined by the default +.br bufsiz . +the +.br setlinebuf () +function is exactly equivalent to the call: +.pp +.in +4n +setvbuf(stream, null, _iolbf, 0); +.in +.sh return value +the function +.br setvbuf () +returns 0 on success. +it returns nonzero on failure +.ri ( mode +is invalid or the request cannot be honored). +it may set +.i errno +on failure. +.pp +the other functions do not return a value. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br setbuf (), +.br setbuffer (), +.br setlinebuf (), +.br setvbuf () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +the +.br setbuf () +and +.br setvbuf () +functions conform to c89 and c99. +.sh notes +posix notes +.\" https://www.austingroupbugs.net/view.php?id=397#c799 +.\" 0000397: setbuf and errno +that the value of +.i errno +is unspecified after a call to +.br setbuf () +and further notes that, since the value of +.i errno +is not required to be unchanged after a successful call to +.br setbuf (), +applications should instead use +.br setvbuf () +in order to detect errors. +.sh bugs +.\" the +.\" .br setbuffer () +.\" and +.\" .br setlinebuf () +.\" functions are not portable to versions of bsd before 4.2bsd, and +.\" are available under linux since libc 4.5.21. +.\" on 4.2bsd and 4.3bsd systems, +.\" .br setbuf () +.\" always uses a suboptimal buffer size and should be avoided. +.\".pp +you must make sure that the space that +.i buf +points to still exists by the time +.i stream +is closed, which also happens at program termination. +for example, the following is invalid: +.pp +.ex +#include + +int +main(void) +{ + char buf[bufsiz]; + setbuf(stdout, buf); + printf("hello, world!\en"); + return 0; +} +.ee +.sh see also +.br stdbuf (1), +.br fclose (3), +.br fflush (3), +.br fopen (3), +.br fread (3), +.br malloc (3), +.br printf (3), +.br puts (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-4.7 + +.so man7/system_data_types.7 + +.\" this manpage is copyright (c) 1992 drew eckhardt; +.\" and copyright (c) 1993 michael haardt, ian jackson. +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified wed jul 21 19:42:57 1993 by rik faith +.\" modified sun jul 21 21:25:26 1996 by andries brouwer +.\" modified wed nov 6 03:46:05 1996 by eric s. raymond +.\" +.th alarm 2 2017-05-03 "linux" "linux programmer's manual" +.sh name +alarm \- set an alarm clock for delivery of a signal +.sh synopsis +.nf +.b #include +.pp +.bi "unsigned int alarm(unsigned int " seconds ); +.fi +.sh description +.br alarm () +arranges for a +.b sigalrm +signal to be delivered to the calling process in +.i seconds +seconds. +.pp +if +.i seconds +is zero, any pending alarm is canceled. +.pp +in any event any previously set +.br alarm () +is canceled. +.sh return value +.br alarm () +returns the number of seconds remaining until any previously scheduled +alarm was due to be delivered, or zero if there was no previously +scheduled alarm. +.sh conforming to +posix.1-2001, posix.1-2008, svr4, 4.3bsd. +.sh notes +.br alarm () +and +.br setitimer (2) +share the same timer; calls to one will interfere with use of the +other. +.pp +alarms created by +.br alarm () +are preserved across +.br execve (2) +and are not inherited by children created via +.br fork (2). +.pp +.br sleep (3) +may be implemented using +.br sigalrm ; +mixing calls to +.br alarm () +and +.br sleep (3) +is a bad idea. +.pp +scheduling delays can, as ever, cause the execution of the process to +be delayed by an arbitrary amount of time. +.sh see also +.br gettimeofday (2), +.br pause (2), +.br select (2), +.br setitimer (2), +.br sigaction (2), +.br signal (2), +.br timer_create (2), +.br timerfd_create (2), +.br sleep (3), +.br time (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/system_data_types.7 + +.so man3/erf.3 + +.\" %%%license_start(public_domain) +.\" this page is in the public domain. - aeb +.\" %%%license_end +.\" +.\" 2004-12-17, mtk, added description of ptsname_r() + errors +.\" +.th ptsname 3 2021-03-22 "" "linux programmer's manual" +.sh name +ptsname, ptsname_r \- get the name of the slave pseudoterminal +.sh synopsis +.nf +.b #include +.pp +.bi "char *ptsname(int " fd ");" +.bi "int ptsname_r(int " fd ", char *" buf ", size_t " buflen ");" +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br ptsname (): +.nf + since glibc 2.24: + _xopen_source >= 500 +.\" || (_xopen_source && _xopen_source_extended) + glibc 2.23 and earlier: + _xopen_source +.fi +.pp +.br ptsname_r (): +.nf + _gnu_source +.fi +.sh description +the +.br ptsname () +function returns the name of the slave pseudoterminal device +corresponding to the master referred to by the file descriptor +.ir fd . +.pp +the +.br ptsname_r () +function is the reentrant equivalent of +.br ptsname (). +it returns the name of the slave pseudoterminal device as a +null-terminated string in the buffer pointed to by +.ir buf . +the +.i buflen +argument specifies the number of bytes available in +.ir buf . +.sh return value +on success, +.br ptsname () +returns a pointer to a string in static storage which will be +overwritten by subsequent calls. +this pointer must not be freed. +on failure, null is returned. +.pp +on success, +.br ptsname_r () +returns 0. +on failure, an error number is returned to indicate the error. +.\" in glibc, the error number is not only returned as the return value +.\" but also stored in errno. but this is not true for musl libc. +.sh errors +.tp +.b einval +.rb ( ptsname_r () +only) +.i buf +is null. +(this error is returned only for +.\" glibc commit 8f0a947cf55f3b0c4ebdf06953c57eff67a22fa9 +glibc 2.25 and earlier.) +.tp +.b enotty +.i fd +does not refer to a pseudoterminal master device. +.tp +.b erange +.rb ( ptsname_r () +only) +.i buf +is too small. +.sh versions +.br ptsname () +is provided in glibc since version 2.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br ptsname () +t} thread safety mt-unsafe race:ptsname +t{ +.br ptsname_r () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +.br ptsname (): + posix.1-2001, posix.1-2008. +.pp +.br ptsname () +is part of the unix 98 pseudoterminal support (see +.br pts (4)). +.pp +.br ptsname_r () +is a linux extension, that is proposed for inclusion +.\" fixme . for later review when issue 8 is one day released +.\" http://austingroupbugs.net/tag_view_page.php?tag_id=8 +.\" http://austingroupbugs.net/view.php?id=508 +in the next major revision of posix.1 (issue 8). +a version of this function is documented on tru64 and hp-ux, but +on those implementations, \-1 is returned on error, with +.i errno +set to indicate the error. +avoid using this function in portable programs. +.sh see also +.br grantpt (3), +.br posix_openpt (3), +.br ttyname (3), +.br unlockpt (3), +.br pts (4), +.br pty (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/setresuid.2 + +.so man3/getutent.3 + +.so man7/system_data_types.7 + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" and copyright 2008, linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified 1993-07-24 by rik faith (faith@cs.unc.edu) +.\" modified 2002-07-25 by walter harms +.\" (walter.harms@informatik.uni-oldenburg.de) +.\" +.th asin 3 2021-03-22 "" "linux programmer's manual" +.sh name +asin, asinf, asinl \- arc sine function +.sh synopsis +.nf +.b #include +.pp +.bi "double asin(double " x ); +.bi "float asinf(float " x ); +.bi "long double asinl(long double " x ); +.fi +.pp +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br asinf (), +.br asinl (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +these functions calculate the principal value of the arc sine of +.ir x ; +that is the value whose sine is +.ir x . +.sh return value +on success, these functions return the principal value of the arc sine of +.ir x +in radians; the return value is in the range [\-pi/2,\ pi/2]. +.pp +if +.i x +is a nan, a nan is returned. +.pp +if +.i x +is +0 (\-0), ++0 (\-0) is returned. +.pp +if +.i x +is outside the range [\-1,\ 1], +a domain error occurs, +and a nan is returned. +.\" +.\" posix.1-2001 documents an optional range error for subnormal x; +.\" glibc 2.8 does not do this. +.sh errors +see +.br math_error (7) +for information on how to determine whether an error has occurred +when calling these functions. +.pp +the following errors can occur: +.tp +domain error: \fix\fp is outside the range [\-1,\ 1] +.i errno +is set to +.br edom . +an invalid floating-point exception +.rb ( fe_invalid ) +is raised. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br asin (), +.br asinf (), +.br asinl () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +c99, posix.1-2001, posix.1-2008. +.pp +the variant returning +.i double +also conforms to +svr4, 4.3bsd, c89. +.sh see also +.br acos (3), +.br atan (3), +.br atan2 (3), +.br casin (3), +.br cos (3), +.br sin (3), +.br tan (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/getpwent.3 + +.so man3/log10.3 + +.so man3/fseek.3 + +.so man7/iso_8859-4.7 + +.\" $netbsd: rcmd.3,v 1.9 1996/05/28 02:07:39 mrg exp $ +.\" +.\" copyright (c) 1983, 1991, 1993 +.\" the regents of the university of california. all rights reserved. +.\" +.\" %%%license_start(bsd_4_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. all advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" this product includes software developed by the university of +.\" california, berkeley and its contributors. +.\" 4. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" @(#)rcmd.3 8.1 (berkeley) 6/4/93 +.\" +.\" contributed as linux man page by david a. holland, 970908 +.\" i have not checked whether the linux situation is exactly the same. +.\" +.\" 2007-12-08, mtk, converted from mdoc to man macros +.\" +.th rcmd 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +rcmd, rresvport, iruserok, ruserok, rcmd_af, +rresvport_af, iruserok_af, ruserok_af \- routines for returning a +stream to a remote command +.sh synopsis +.nf +.br "#include " "/* or on some systems */" +.pp +.bi "int rcmd(char **restrict " ahost ", unsigned short " inport , +.bi " const char *restrict " locuser , +.bi " const char *restrict " remuser , +.bi " const char *restrict " cmd ", int *restrict " fd2p ); +.pp +.bi "int rresvport(int *" port ); +.pp +.bi "int iruserok(uint32_t " raddr ", int " superuser , +.bi " const char *" ruser ", const char *" luser ); +.bi "int ruserok(const char *" rhost ", int " superuser , +.bi " const char *" ruser ", const char *" luser ); +.pp +.bi "int rcmd_af(char **restrict " ahost ", unsigned short " inport , +.bi " const char *restrict " locuser , +.bi " const char *restrict " remuser , +.bi " const char *restrict " cmd ", int *restrict " fd2p , +.bi " sa_family_t " af ); +.pp +.bi "int rresvport_af(int *" port ", sa_family_t " af ); +.pp +.bi "int iruserok_af(const void *restrict " raddr ", int " superuser , +.bi " const char *restrict " ruser ", const char *restrict " luser , +.bi " sa_family_t " af ); +.bi "int ruserok_af(const char *" rhost ", int " superuser , +.bi " const char *" ruser ", const char *" luser , +.bi " sa_family_t " af ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.ad l +.pp +.br rcmd (), +.br rcmd_af (), +.br rresvport (), +.br rresvport_af (), +.br iruserok (), +.br iruserok_af (), +.br ruserok (), +.br ruserok_af (): +.nf + since glibc 2.19: + _default_source + glibc 2.19 and earlier: + _bsd_source +.fi +.ad +.sh description +the +.br rcmd () +function is used by the superuser to execute a command on +a remote machine using an authentication scheme based +on privileged port numbers. +the +.br rresvport () +function +returns a file descriptor to a socket +with an address in the privileged port space. +the +.br iruserok () +and +.br ruserok () +functions are used by servers +to authenticate clients requesting service with +.br rcmd (). +all four functions are used by the +.br rshd (8) +server (among others). +.ss rcmd() +the +.br rcmd () +function +looks up the host +.i *ahost +using +.br gethostbyname (3), +returning \-1 if the host does not exist. +otherwise, +.i *ahost +is set to the standard name of the host +and a connection is established to a server +residing at the well-known internet port +.ir inport . +.pp +if the connection succeeds, +a socket in the internet domain of type +.br sock_stream +is returned to the caller, and given to the remote +command as +.ir stdin +and +.ir stdout . +if +.i fd2p +is nonzero, then an auxiliary channel to a control +process will be set up, and a file descriptor for it will be placed +in +.ir *fd2p . +the control process will return diagnostic +output from the command (unit 2) on this channel, and will also +accept bytes on this channel as being unix signal numbers, to be +forwarded to the process group of the command. +if +.i fd2p +is 0, then the +.ir stderr +(unit 2 of the remote +command) will be made the same as the +.ir stdout +and no +provision is made for sending arbitrary signals to the remote process, +although you may be able to get its attention by using out-of-band data. +.pp +the protocol is described in detail in +.br rshd (8). +.ss rresvport() +the +.br rresvport () +function is used to obtain a socket with a privileged +port bound to it. +this socket is suitable for use by +.br rcmd () +and several other functions. +privileged ports are those in the range 0 to 1023. +only a privileged process +(on linux, a process that has the +.b cap_net_bind_service +capability in the user namespace governing its network namespace) +is allowed to bind to a privileged port. +in the glibc implementation, +this function restricts its search to the ports from 512 to 1023. +the +.i port +argument is value-result: +the value it supplies to the call is used as the starting point +for a circular search of the port range; +on (successful) return, it contains the port number that was bound to. +.\" +.ss iruserok() and ruserok() +the +.br iruserok () +and +.br ruserok () +functions take a remote host's ip address or name, respectively, +two usernames and a flag indicating whether the local user's +name is that of the superuser. +then, if the user is +.i not +the superuser, it checks the +.ir /etc/hosts.equiv +file. +if that lookup is not done, or is unsuccessful, the +.ir .rhosts +in the local user's home directory is checked to see if the request for +service is allowed. +.pp +if this file does not exist, is not a regular file, is owned by anyone +other than the user or the superuser, is writable by anyone other +than the owner, or is hardlinked anywhere, the check automatically fails. +zero is returned if the machine name is listed in the +.ir hosts.equiv +file, or the host and remote username are found in the +.ir .rhosts +file; otherwise +.br iruserok () +and +.br ruserok () +return \-1. +if the local domain (as obtained from +.br gethostname (2)) +is the same as the remote domain, only the machine name need be specified. +.pp +if the ip address of the remote host is known, +.br iruserok () +should be used in preference to +.br ruserok (), +as it does not require trusting the dns server for the remote host's domain. +.ss *_af() variants +all of the functions described above work with ipv4 +.rb ( af_inet ) +sockets. +the "_af" variants take an extra argument that allows the +socket address family to be specified. +for these functions, the +.i af +argument can be specified as +.br af_inet +or +.br af_inet6 . +in addition, +.br rcmd_af () +supports the use of +.br af_unspec . +.sh return value +the +.br rcmd () +function +returns a valid socket descriptor on success. +it returns \-1 on error and prints a diagnostic message on the standard error. +.pp +the +.br rresvport () +function +returns a valid, bound socket descriptor on success. +on failure, it returns \-1 and sets +.i errno +to indicate the error. +the error code +.br eagain +is overloaded to mean: "all network ports in use". +.pp +for information on the return from +.br ruserok () +and +.br iruserok (), +see above. +.sh versions +the functions +.br iruserok_af (), +.br rcmd_af (), +.br rresvport_af (), +and +.br ruserok_af () +functions are provide in glibc since version 2.2. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br rcmd (), +.br rcmd_af () +t} thread safety mt-unsafe +t{ +.br rresvport (), +.br rresvport_af () +t} thread safety mt-safe +t{ +.br iruserok (), +.br ruserok (), +.br iruserok_af (), +.br ruserok_af () +t} thread safety mt-safe locale +.te +.hy +.ad +.sp 1 +.sh conforming to +not in posix.1. +present on the bsds, solaris, and many other systems. +these +functions appeared in +4.2bsd. +the "_af" variants are more recent additions, +and are not present on as wide a range of systems. +.sh bugs +.br iruserok () +and +.br iruserok_af () +are declared in glibc headers only since version 2.12. +.\" bug filed 25 nov 2007: +.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=5399 +.sh see also +.br rlogin (1), +.br rsh (1), +.br rexec (3), +.br rexecd (8), +.br rlogind (8), +.br rshd (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2003 free software foundation, inc. +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" this file is distributed according to the gnu general public license. +.\" %%%license_end +.\" +.th io_setup 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +io_setup \- create an asynchronous i/o context +.sh synopsis +.nf +.br "#include " " /* defines needed types */" +.pp +.bi "long io_setup(unsigned int " nr_events ", aio_context_t *" ctx_idp ); +.fi +.pp +.ir note : +there is no glibc wrapper for this system call; see notes. +.sh description +.ir note : +this page describes the raw linux system call interface. +the wrapper function provided by +.i libaio +uses a different type for the +.i ctx_idp +argument. +see notes. +.pp +the +.br io_setup () +system call +creates an asynchronous i/o context suitable for concurrently processing +\finr_events\fp operations. +the +.i ctx_idp +argument must not point to an aio context that already exists, and must +be initialized to 0 prior to the call. +on successful creation of the aio context, \fi*ctx_idp\fp is filled in +with the resulting handle. +.sh return value +on success, +.br io_setup () +returns 0. +for the failure return, see notes. +.sh errors +.tp +.b eagain +the specified \finr_events\fp exceeds the limit of available events, +as defined in +.ir /proc/sys/fs/aio\-max\-nr +(see +.br proc (5)). +.tp +.b efault +an invalid pointer is passed for \fictx_idp\fp. +.tp +.b einval +\fictx_idp\fp is not initialized, or the specified \finr_events\fp +exceeds internal limits. +\finr_events\fp should be greater than 0. +.tp +.b enomem +insufficient kernel resources are available. +.tp +.b enosys +.br io_setup () +is not implemented on this architecture. +.sh versions +the asynchronous i/o system calls first appeared in linux 2.5. +.sh conforming to +.br io_setup () +is linux-specific and should not be used in programs +that are intended to be portable. +.sh notes +glibc does not provide a wrapper for this system call. +you could invoke it using +.br syscall (2). +but instead, you probably want to use the +.br io_setup () +wrapper function provided by +.\" http://git.fedorahosted.org/git/?p=libaio.git +.ir libaio . +.pp +note that the +.i libaio +wrapper function uses a different type +.ri ( "io_context_t\ *" ) +.\" but glibc is confused, since uses 'io_context_t' to declare +.\" the system call. +for the +.i ctx_idp +argument. +note also that the +.i libaio +wrapper does not follow the usual c library conventions for indicating errors: +on error it returns a negated error number +(the negative of one of the values listed in errors). +if the system call is invoked via +.br syscall (2), +then the return value follows the usual conventions for +indicating an error: \-1, with +.i errno +set to a (positive) value that indicates the error. +.sh see also +.br io_cancel (2), +.br io_destroy (2), +.br io_getevents (2), +.br io_submit (2), +.br aio (7) +.\" .sh author +.\" kent yoder. +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/xdr.3 + +.so man3/stailq.3 + +.so man3/regex.3 + +.\" copyright (c) 2006 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th mq_unlink 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +mq_unlink \- remove a message queue +.sh synopsis +.nf +.b #include +.pp +.bi "int mq_unlink(const char *" name ); +.fi +.pp +link with \fi\-lrt\fp. +.sh description +.br mq_unlink () +removes the specified message queue +.ir name . +the message queue name is removed immediately. +the queue itself is destroyed once any other processes that have +the queue open close their descriptors referring to the queue. +.sh return value +on success +.br mq_unlink () +returns 0; on error, \-1 is returned, with +.i errno +set to indicate the error. +.sh errors +.tp +.b eacces +the caller does not have permission to unlink this message queue. +.tp +.b enametoolong +.i name +was too long. +.tp +.b enoent +there is no message queue with the given +.ir name . +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br mq_unlink () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh see also +.br mq_close (3), +.br mq_getattr (3), +.br mq_notify (3), +.br mq_open (3), +.br mq_receive (3), +.br mq_send (3), +.br mq_overview (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/sigsetops.3 + +.\" copyright (c) 1993 +.\" the regents of the university of california. all rights reserved. +.\" and copyright (c) 2020 by alejandro colomar +.\" +.\" %%%license_start(bsd_3_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" +.th slist 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +slist_empty, +slist_entry, +slist_first, +slist_foreach, +.\"slist_foreach_from, +.\"slist_foreach_from_safe, +.\"slist_foreach_safe, +slist_head, +slist_head_initializer, +slist_init, +slist_insert_after, +slist_insert_head, +slist_next, +slist_remove, +.\"slist_remove_after, +slist_remove_head +.\"slist_swap +\- implementation of a singly linked list +.sh synopsis +.nf +.b #include +.pp +.b slist_entry(type); +.pp +.b slist_head(headname, type); +.bi "slist_head slist_head_initializer(slist_head " head ); +.bi "void slist_init(slist_head *" head ); +.pp +.bi "int slist_empty(slist_head *" head ); +.pp +.bi "void slist_insert_head(slist_head *" head , +.bi " struct type *" elm ", slist_entry " name ); +.bi "void slist_insert_after(struct type *" listelm , +.bi " struct type *" elm ", slist_entry " name ); +.pp +.bi "struct type *slist_first(slist_head *" head ); +.bi "struct type *slist_next(struct type *" elm ", slist_entry " name ); +.pp +.bi "slist_foreach(struct type *" var ", slist_head *" head ", slist_entry " name ); +.\" .bi "slist_foreach_from(struct type *" var ", slist_head *" head , +.\" .bi " slist_entry " name ); +.\" .pp +.\" .bi "slist_foreach_safe(struct type *" var ", slist_head *" head , +.\" .bi " slist_entry " name ", struct type *" temp_var ); +.\" .bi "slist_foreach_from_safe(struct type *" var ", slist_head *" head , +.\" .bi " slist_entry " name ", struct type *" temp_var ); +.pp +.bi "void slist_remove(slist_head *" head ", struct type *" elm , +.bi " slist_entry " name ); +.bi "void slist_remove_head(slist_head *" head , +.bi " slist_entry " name ); +.\" .bi "void slist_remove_after(struct type *" elm , +.\" .bi " slist_entry " name ); +.\" .pp +.\" .bi "void slist_swap(slist_head *" head1 ", slist_head *" head2 , +.\" .bi " slist_entry " name ); +.fi +.sh description +these macros define and operate on doubly linked lists. +.pp +in the macro definitions, +.i type +is the name of a user-defined structure, +that must contain a field of type +.ir slist_entry , +named +.ir name . +the argument +.ir headname +is the name of a user-defined structure +that must be declared using the macro +.br slist_head (). +.ss creation +a singly linked list is headed by a structure defined by the +.br slist_head () +macro. +this structure contains a single pointer to the first element on the list. +the elements are singly linked +for minimum space and pointer manipulation overhead +at the expense of o(n) removal for arbitrary elements. +new elements can be added to the list +after an existing element +or at the head of the list. +an +.i slist_head +structure is declared as follows: +.pp +.in +4 +.ex +slist_head(headname, type) head; +.ee +.in +.pp +where +.i struct headname +is the structure to be defined, and +.i struct type +is the type of the elements to be linked into the list. +a pointer to the head of the list can later be declared as: +.pp +.in +4 +.ex +struct headname *headp; +.ee +.in +.pp +(the names +.i head +and +.i headp +are user selectable.) +.pp +.br slist_entry () +declares a structure that connects the elements in +the list. +.pp +.br slist_head_initializer () +evaluates to an initializer for the list +.ir head . +.pp +.br slist_init () +initializes the list referenced by +.ir head . +.pp +.br slist_empty () +evaluates to true if there are no elements in the list. +.ss insertion +.br slist_insert_head () +inserts the new element +.i elm +at the head of the list. +.pp +.br slist_insert_after () +inserts the new element +.i elm +after the element +.ir listelm . +.ss traversal +.br slist_first () +returns the first element in the list, or null if the list is empty. +.pp +.br slist_next () +returns the next element in the list. +.pp +.br slist_foreach () +traverses the list referenced by +.i head +in the forward direction, +assigning each element in turn to +.ir var . +.\" .pp +.\" .br slist_foreach_from () +.\" behaves identically to +.\" .br slist_foreach () +.\" when +.\" .i var +.\" is null, else it treats +.\" .i var +.\" as a previously found slist element and begins the loop at +.\" .i var +.\" instead of the first element in the slist referenced by +.\" .ir head . +.\" .pp +.\" .br slist_foreach_safe () +.\" traverses the list referenced by +.\" .i head +.\" in the forward direction, assigning each element in +.\" turn to +.\" .ir var . +.\" however, unlike +.\" .br slist_foreach () +.\" here it is permitted to both remove +.\" .i var +.\" as well as free it from within the loop safely without interfering with the +.\" traversal. +.\" .pp +.\" .br slist_foreach_from_safe () +.\" behaves identically to +.\" .br slist_foreach_safe () +.\" when +.\" .i var +.\" is null, else it treats +.\" .i var +.\" as a previously found slist element and begins the loop at +.\" .i var +.\" instead of the first element in the slist referenced by +.\" .ir head . +.ss removal +.br slist_remove () +removes the element +.i elm +from the list. +.pp +.br slist_remove_head () +removes the element +.i elm +from the head of the list. +for optimum efficiency, +elements being removed from the head of the list +should explicitly use this macro instead of the generic +.br slist_remove (). +.\" .pp +.\" .br slist_remove_after () +.\" removes the element after +.\" .i elm +.\" from the list. +.\" unlike +.\" .ir slist_remove , +.\" this macro does not traverse the entire list. +.\" .ss other features +.\" .br slist_swap () +.\" swaps the contents of +.\" .i head1 +.\" and +.\" .ir head2 . +.sh return value +.br slist_empty () +returns nonzero if the list is empty, +and zero if the list contains at least one entry. +.pp +.br slist_first (), +and +.br slist_next () +return a pointer to the first or next +.i type +structure, respectively. +.pp +.br slist_head_initializer () +returns an initializer that can be assigned to the list +.ir head . +.sh conforming to +not in posix.1, posix.1-2001, or posix.1-2008. +present on the bsds +(slist macros first appeared in 4.4bsd). +.sh bugs +.br slist_foreach () +doesn't allow +.i var +to be removed or freed within the loop, +as it would interfere with the traversal. +.br slist_foreach_safe (), +which is present on the bsds but is not present in glibc, +fixes this limitation by allowing +.i var +to safely be removed from the list and freed from within the loop +without interfering with the traversal. +.sh examples +.ex +#include +#include +#include +#include + +struct entry { + int data; + slist_entry(entry) entries; /* singly linked list */ +}; + +slist_head(slisthead, entry); + +int +main(void) +{ + struct entry *n1, *n2, *n3, *np; + struct slisthead head; /* singly linked list + head */ + + slist_init(&head); /* initialize the queue */ + + n1 = malloc(sizeof(struct entry)); /* insert at the head */ + slist_insert_head(&head, n1, entries); + + n2 = malloc(sizeof(struct entry)); /* insert after */ + slist_insert_after(n1, n2, entries); + + slist_remove(&head, n2, entry, entries);/* deletion */ + free(n2); + + n3 = slist_first(&head); + slist_remove_head(&head, entries); /* deletion from the head */ + free(n3); + + for (int i = 0; i < 5; i++) { + n1 = malloc(sizeof(struct entry)); + slist_insert_head(&head, n1, entries); + n1\->data = i; + } + + /* forward traversal */ + slist_foreach(np, &head, entries) + printf("%i\en", np\->data); + + while (!slist_empty(&head)) { /* list deletion */ + n1 = slist_first(&head); + slist_remove_head(&head, entries); + free(n1); + } + slist_init(&head); + + exit(exit_success); +} +.ee +.sh see also +.br insque (3), +.br queue (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-1.7 + +.so man3/clog2.3 + +.so man3/des_crypt.3 + +.\" copyright (c), 1994, graeme w. wilford (wilf). +.\" and copyright (c) 2010, 2014, 2015, michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" fri jul 29th 12:56:44 bst 1994 wilf. +.\" changes inspired by patch from richard kettlewell +.\" , aeb 970616. +.\" modified, 27 may 2004, michael kerrisk +.\" added notes on capability requirements +.th setuid 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +setuid \- set user identity +.sh synopsis +.nf +.b #include +.pp +.bi "int setuid(uid_t " uid ); +.fi +.sh description +.br setuid () +sets the effective user id of the calling process. +if the calling process is privileged +(more precisely: if the process has the +.br cap_setuid +capability in its user namespace), +the real uid and saved set-user-id are also set. +.pp +under linux, +.br setuid () +is implemented like the posix version with the +.b _posix_saved_ids +feature. +this allows a set-user-id (other than root) program to drop all of its user +privileges, do some un-privileged work, and then reengage the original +effective user id in a secure manner. +.pp +if the user is root or the program is set-user-id-root, special care must be +taken: +.br setuid () +checks the effective user id of the caller and if it is +the superuser, all process-related user id's are set to +.ir uid . +after this has occurred, it is impossible for the program to regain root +privileges. +.pp +thus, a set-user-id-root program wishing to temporarily drop root +privileges, assume the identity of an unprivileged user, and then regain +root privileges afterward cannot use +.br setuid (). +you can accomplish this with +.br seteuid (2). +.sh return value +on success, zero is returned. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.pp +.ir note : +there are cases where +.br setuid () +can fail even when the caller is uid 0; +it is a grave security error to omit checking for a failure return from +.br setuid (). +.sh errors +.tp +.b eagain +the call would change the caller's real uid (i.e., +.i uid +does not match the caller's real uid), +but there was a temporary failure allocating the +necessary kernel data structures. +.tp +.b eagain +.i uid +does not match the real user id of the caller and this call would +bring the number of processes belonging to the real user id +.i uid +over the caller's +.b rlimit_nproc +resource limit. +since linux 3.1, this error case no longer occurs +(but robust applications should check for this error); +see the description of +.b eagain +in +.br execve (2). +.tp +.b einval +the user id specified in +.i uid +is not valid in this user namespace. +.tp +.b eperm +the user is not privileged (linux: does not have the +.b cap_setuid +capability in its user namespace) and +.i uid +does not match the real uid or saved set-user-id of the calling process. +.sh conforming to +posix.1-2001, posix.1-2008, svr4. +not quite compatible with the 4.4bsd call, which +sets all of the real, saved, and effective user ids. +.\" svr4 documents an additional einval error condition. +.sh notes +linux has the concept of the filesystem user id, normally equal to the +effective user id. +the +.br setuid () +call also sets the filesystem user id of the calling process. +see +.br setfsuid (2). +.pp +if +.i uid +is different from the old effective uid, the process will +be forbidden from leaving core dumps. +.pp +the original linux +.br setuid () +system call supported only 16-bit user ids. +subsequently, linux 2.4 added +.br setuid32 () +supporting 32-bit ids. +the glibc +.br setuid () +wrapper function transparently deals with the variation across kernel versions. +.\" +.ss c library/kernel differences +at the kernel level, user ids and group ids are a per-thread attribute. +however, posix requires that all threads in a process +share the same credentials. +the nptl threading implementation handles the posix requirements by +providing wrapper functions for +the various system calls that change process uids and gids. +these wrapper functions (including the one for +.br setuid ()) +employ a signal-based technique to ensure +that when one thread changes credentials, +all of the other threads in the process also change their credentials. +for details, see +.br nptl (7). +.sh see also +.br getuid (2), +.br seteuid (2), +.br setfsuid (2), +.br setreuid (2), +.br capabilities (7), +.br credentials (7), +.br user_namespaces (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/getresgid.2 + +.so man3/circleq.3 + +.so man3/remquo.3 + +.\" copyright (c) 2009 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_getcpuclockid 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_getcpuclockid \- retrieve id of a thread's cpu time clock +.sh synopsis +.nf +.b #include +.b #include +.pp +.bi "int pthread_getcpuclockid(pthread_t " thread ", clockid_t *" clockid ); +.pp +compile and link with \fi\-pthread\fp. +.fi +.sh description +the +.br pthread_getcpuclockid () +function obtains the id of the cpu-time clock of the thread whose id is +given in +.ir thread , +and returns it in the location pointed to by +.ir clockid . +.\" the clockid is constructed as follows: +.\" *clockid = clock_thread_cputime_id | (pd->tid << clock_idfield_size) +.\" where clock_idfield_size is 3. +.sh return value +on success, this function returns 0; +on error, it returns a nonzero error number. +.sh errors +.tp +.b enoent +.\" clock_thread_cputime_id not defined +per-thread cpu time clocks are not supported by the system. +.\" +.\" looking at nptl/pthread_getcpuclockid.c an erange error would +.\" be possible if kernel thread ids took more than 29 bits (which +.\" they currently cannot). +.tp +.b esrch +no thread with the id +.i thread +could be found. +.sh versions +this function is available in glibc since version 2.2. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_getcpuclockid () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +when +.i thread +refers to the calling thread, +this function returns an identifier that refers to the same clock +manipulated by +.br clock_gettime (2) +and +.br clock_settime (2) +when given the clock id +.br clock_thread_cputime_id . +.sh examples +the program below creates a thread and then uses +.br clock_gettime (2) +to retrieve the total process cpu time, +and the per-thread cpu time consumed by the two threads. +the following shell session shows an example run: +.pp +.in +4n +.ex +$ \fb./a.out\fp +main thread sleeping +subthread starting infinite loop +main thread consuming some cpu time... +process total cpu time: 1.368 +main thread cpu time: 0.376 +subthread cpu time: 0.992 +.ee +.in +.ss program source +\& +.ex +/* link with "\-lrt" */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define handle_error(msg) \e + do { perror(msg); exit(exit_failure); } while (0) + +#define handle_error_en(en, msg) \e + do { errno = en; perror(msg); exit(exit_failure); } while (0) + +static void * +thread_start(void *arg) +{ + printf("subthread starting infinite loop\en"); + for (;;) + continue; +} + +static void +pclock(char *msg, clockid_t cid) +{ + struct timespec ts; + + printf("%s", msg); + if (clock_gettime(cid, &ts) == \-1) + handle_error("clock_gettime"); + printf("%4jd.%03ld\en", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); +} + +int +main(int argc, char *argv[]) +{ + pthread_t thread; + clockid_t cid; + int s; + + s = pthread_create(&thread, null, thread_start, null); + if (s != 0) + handle_error_en(s, "pthread_create"); + + printf("main thread sleeping\en"); + sleep(1); + + printf("main thread consuming some cpu time...\en"); + for (int j = 0; j < 2000000; j++) + getppid(); + + pclock("process total cpu time: ", clock_process_cputime_id); + + s = pthread_getcpuclockid(pthread_self(), &cid); + if (s != 0) + handle_error_en(s, "pthread_getcpuclockid"); + pclock("main thread cpu time: ", cid); + + /* the preceding 4 lines of code could have been replaced by: + pclock("main thread cpu time: ", clock_thread_cputime_id); */ + + s = pthread_getcpuclockid(thread, &cid); + if (s != 0) + handle_error_en(s, "pthread_getcpuclockid"); + pclock("subthread cpu time: 1 ", cid); + + exit(exit_success); /* terminates both threads */ +} +.ee +.sh see also +.br clock_gettime (2), +.br clock_settime (2), +.br timer_create (2), +.br clock_getcpuclockid (3), +.br pthread_self (3), +.br pthreads (7), +.br time (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/unimplemented.2 + +.so man3/getservent.3 + +.so man3/slist.3 + +.so man3/gethostbyname.3 + +.\" copyright (c) 2006 michael kerrisk +.\" +.\" %%%license_start(permissive_misc) +.\" permission is hereby granted, free of charge, to any person obtaining +.\" a copy of this software and associated documentation files (the +.\" "software"), to deal in the software without restriction, including +.\" without limitation the rights to use, copy, modify, merge, publish, +.\" distribute, sublicense, and/or sell copies of the software, and to +.\" permit persons to whom the software is furnished to do so, subject to +.\" the following conditions: +.\" +.\" the above copyright notice and this permission notice shall be +.\" included in all copies or substantial portions of the software. +.\" +.\" the software is provided "as is", without warranty of any kind, +.\" express or implied, including but not limited to the warranties of +.\" merchantability, fitness for a particular purpose and noninfringement. +.\" in no event shall the authors or copyright holders be liable for any +.\" claim, damages or other liability, whether in an action of contract, +.\" tort or otherwise, arising from, out of or in connection with the +.\" software or the use or other dealings in the software. +.\" %%%license_end +.\" +.th invocation_name 3 2017-09-15 "gnu" "linux programmer's manual" +.sh name +program_invocation_name, program_invocation_short_name \- \ +obtain name used to invoke calling program +.sh synopsis +.nf +.br "#define _gnu_source" " /* see feature_test_macros(7) */" +.b #include +.pp +.bi "extern char *" program_invocation_name ; +.bi "extern char *" program_invocation_short_name ; +.fi +.sh description +.i program_invocation_name +contains the name that was used to invoke the calling program. +this is the same as the value of +.i argv[0] +in +.ir main (), +with the difference that the scope of +.i program_invocation_name +is global. +.pp +.i program_invocation_short_name +contains the basename component of name that was used to invoke +the calling program. +that is, it is the same value as +.ir program_invocation_name , +with all text up to and including the final slash (/), if any, removed. +.pp +these variables are automatically initialized by the glibc run-time +startup code. +.sh conforming to +these variables are gnu extensions, and should not be +used in programs intended to be portable. +.sh notes +the linux-specific +.i /proc/[number]/cmdline +file provides access to similar information. +.sh see also +.br proc (5) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +\t +.\" copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de) +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" distributed under gpl +.\" %%%license_end +.\" +.\" corrected, aeb, 2002-05-30 +.\" +.th a64l 3 2021-03-22 "" "linux programmer's manual" +.sh name +a64l, l64a \- convert between long and base-64 +.sh synopsis +.nf +.b #include +.pp +.bi "long a64l(const char *" str64 ); +.bi "char *l64a(long " value ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br a64l (), +.br l64a (): +.nf + _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended + || /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _svid_source +.fi +.sh description +these functions provide a conversion between 32-bit long integers +and little-endian base-64 ascii strings (of length zero to six). +if the string used as argument for +.br a64l () +has length greater than six, only the first six bytes are used. +if the type +.i long +has more than 32 bits, then +.br l64a () +uses only the low order 32 bits of +.ir value , +and +.br a64l () +sign-extends its 32-bit result. +.pp +the 64 digits in the base-64 system are: +.pp +.rs +.nf +\&\(aq.\(aq represents a 0 +\&\(aq/\(aq represents a 1 +0-9 represent 2-11 +a-z represent 12-37 +a-z represent 38-63 +.fi +.re +.pp +so 123 = 59*64\(ha0 + 1*64\(ha1 = "v/". +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br l64a () +t} thread safety mt-unsafe race:l64a +t{ +.br a64l () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +the value returned by +.br l64a () +may be a pointer to a static buffer, possibly overwritten +by later calls. +.pp +the behavior of +.br l64a () +is undefined when +.i value +is negative. +if +.i value +is zero, it returns an empty string. +.pp +these functions are broken in glibc before 2.2.5 +(puts most significant digit first). +.pp +this is not the encoding used by +.br uuencode (1). +.sh see also +.br uuencode (1), +.\" .br itoa (3), +.br strtoul (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/system_data_types.7 + +.so man7/system_data_types.7 + +.so man3/endian.3 + +.\" this manpage is copyright (c) 1992 drew eckhardt; +.\" and copyright (c) 1993 michael haardt, ian jackson. +.\" and copyright (c) 2008 greg banks +.\" and copyright (c) 2006, 2008, 2013, 2014 michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified 1993-07-21 by rik faith +.\" modified 1994-08-21 by michael haardt +.\" modified 1996-04-13 by andries brouwer +.\" modified 1996-05-13 by thomas koenig +.\" modified 1996-12-20 by michael haardt +.\" modified 1999-02-19 by andries brouwer +.\" modified 1998-11-28 by joseph s. myers +.\" modified 1999-06-03 by michael haardt +.\" modified 2002-05-07 by michael kerrisk +.\" modified 2004-06-23 by michael kerrisk +.\" 2004-12-08, mtk, reordered flags list alphabetically +.\" 2004-12-08, martin pool (& mtk), added o_noatime +.\" 2007-09-18, mtk, added description of o_cloexec + other minor edits +.\" 2008-01-03, mtk, with input from trond myklebust +.\" and timo sirainen +.\" rewrite description of o_excl. +.\" 2008-01-11, greg banks : add more detail +.\" on o_direct. +.\" 2008-02-26, michael haardt: reorganized text for o_creat and mode +.\" +.\" fixme . apr 08: the next posix revision has o_exec, o_search, and +.\" o_ttyinit. eventually these may need to be documented. --mtk +.\" +.th open 2 2021-08-27 "linux" "linux programmer's manual" +.sh name +open, openat, creat \- open and possibly create a file +.sh synopsis +.nf +.b #include +.pp +.bi "int open(const char *" pathname ", int " flags ); +.bi "int open(const char *" pathname ", int " flags ", mode_t " mode ); +.pp +.bi "int creat(const char *" pathname ", mode_t " mode ); +.pp +.bi "int openat(int " dirfd ", const char *" pathname ", int " flags ); +.bi "int openat(int " dirfd ", const char *" pathname ", int " flags \ +", mode_t " mode ); +.pp +/* documented separately, in \fbopenat2\fp(2): */ +.bi "int openat2(int " dirfd ", const char *" pathname , +.bi " const struct open_how *" how ", size_t " size ");" +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br openat (): +.nf + since glibc 2.10: + _posix_c_source >= 200809l + before glibc 2.10: + _atfile_source +.fi +.sh description +the +.br open () +system call opens the file specified by +.ir pathname . +if the specified file does not exist, +it may optionally (if +.b o_creat +is specified in +.ir flags ) +be created by +.br open (). +.pp +the return value of +.br open () +is a file descriptor, a small, nonnegative integer that is an index +to an entry in the process's table of open file descriptors. +the file descriptor is used +in subsequent system calls +.rb ( read "(2), " write "(2), " lseek "(2), " fcntl (2), +etc.) to refer to the open file. +the file descriptor returned by a successful call will be +the lowest-numbered file descriptor not currently open for the process. +.pp +by default, the new file descriptor is set to remain open across an +.br execve (2) +(i.e., the +.b fd_cloexec +file descriptor flag described in +.br fcntl (2) +is initially disabled); the +.b o_cloexec +flag, described below, can be used to change this default. +the file offset is set to the beginning of the file (see +.br lseek (2)). +.pp +a call to +.br open () +creates a new +.ir "open file description" , +an entry in the system-wide table of open files. +the open file description records the file offset and the file status flags +(see below). +a file descriptor is a reference to an open file description; +this reference is unaffected if +.i pathname +is subsequently removed or modified to refer to a different file. +for further details on open file descriptions, see notes. +.pp +the argument +.i flags +must include one of the following +.ir "access modes" : +.br o_rdonly ", " o_wronly ", or " o_rdwr . +these request opening the file read-only, write-only, or read/write, +respectively. +.pp +in addition, zero or more file creation flags and file status flags +can be +.ri bitwise- or 'd +in +.ir flags . +the +.i file creation flags +are +.br o_cloexec , +.br o_creat , +.br o_directory , +.br o_excl , +.br o_noctty , +.br o_nofollow , +.br o_tmpfile , +and +.br o_trunc . +the +.i file status flags +are all of the remaining flags listed below. +.\" susv4 divides the flags into: +.\" * access mode +.\" * file creation +.\" * file status +.\" * other (o_cloexec, o_directory, o_nofollow) +.\" though it's not clear what the difference between "other" and +.\" "file creation" flags is. i raised an aardvark to see if this +.\" can be clarified in susv4; 10 oct 2008. +.\" http://thread.gmane.org/gmane.comp.standards.posix.austin.general/64/focus=67 +.\" tc1 (balloted in 2013), resolved this, so that those three constants +.\" are also categorized" as file status flags. +.\" +the distinction between these two groups of flags is that +the file creation flags affect the semantics of the open operation itself, +while the file status flags affect the semantics of subsequent i/o operations. +the file status flags can be retrieved and (in some cases) +modified; see +.br fcntl (2) +for details. +.pp +the full list of file creation flags and file status flags is as follows: +.tp +.b o_append +the file is opened in append mode. +before each +.br write (2), +the file offset is positioned at the end of the file, +as if with +.br lseek (2). +the modification of the file offset and the write operation +are performed as a single atomic step. +.ip +.b o_append +may lead to corrupted files on nfs filesystems if more than one process +appends data to a file at once. +.\" for more background, see +.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453946 +.\" http://nfs.sourceforge.net/ +this is because nfs does not support +appending to a file, so the client kernel has to simulate it, which +can't be done without a race condition. +.tp +.b o_async +enable signal-driven i/o: +generate a signal +.rb ( sigio +by default, but this can be changed via +.br fcntl (2)) +when input or output becomes possible on this file descriptor. +this feature is available only for terminals, pseudoterminals, +sockets, and (since linux 2.6) pipes and fifos. +see +.br fcntl (2) +for further details. +see also bugs, below. +.tp +.br o_cloexec " (since linux 2.6.23)" +.\" note! several other man pages refer to this text +enable the close-on-exec flag for the new file descriptor. +.\" fixme . for later review when issue 8 is one day released... +.\" posix proposes to fix many apis that provide hidden fds +.\" http://austingroupbugs.net/tag_view_page.php?tag_id=8 +.\" http://austingroupbugs.net/view.php?id=368 +specifying this flag permits a program to avoid additional +.br fcntl (2) +.b f_setfd +operations to set the +.b fd_cloexec +flag. +.ip +note that the use of this flag is essential in some multithreaded programs, +because using a separate +.br fcntl (2) +.b f_setfd +operation to set the +.b fd_cloexec +flag does not suffice to avoid race conditions +where one thread opens a file descriptor and +attempts to set its close-on-exec flag using +.br fcntl (2) +at the same time as another thread does a +.br fork (2) +plus +.br execve (2). +depending on the order of execution, +the race may lead to the file descriptor returned by +.br open () +being unintentionally leaked to the program executed by the child process +created by +.br fork (2). +(this kind of race is in principle possible for any system call +that creates a file descriptor whose close-on-exec flag should be set, +and various other linux system calls provide an equivalent of the +.br o_cloexec +flag to deal with this problem.) +.\" this flag fixes only one form of the race condition; +.\" the race can also occur with, for example, file descriptors +.\" returned by accept(), pipe(), etc. +.tp +.b o_creat +if +.i pathname +does not exist, create it as a regular file. +.ip +the owner (user id) of the new file is set to the effective user id +of the process. +.ip +the group ownership (group id) of the new file is set either to +the effective group id of the process (system v semantics) +or to the group id of the parent directory (bsd semantics). +on linux, the behavior depends on whether the +set-group-id mode bit is set on the parent directory: +if that bit is set, then bsd semantics apply; +otherwise, system v semantics apply. +for some filesystems, the behavior also depends on the +.i bsdgroups +and +.i sysvgroups +mount options described in +.br mount (8). +.\" as at 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and +.\" xfs (since 2.6.14). +.ip +the +.i mode +argument specifies the file mode bits to be applied when a new file is created. +if neither +.b o_creat +nor +.b o_tmpfile +is specified in +.ir flags , +then +.i mode +is ignored (and can thus be specified as 0, or simply omitted). +the +.i mode +argument +.b must +be supplied if +.b o_creat +or +.b o_tmpfile +is specified in +.ir flags ; +if it is not supplied, +some arbitrary bytes from the stack will be applied as the file mode. +.ip +the effective mode is modified by the process's +.i umask +in the usual way: in the absence of a default acl, the mode of the +created file is +.ir "(mode\ &\ \(tiumask)" . +.ip +note that +.i mode +applies only to future accesses of the +newly created file; the +.br open () +call that creates a read-only file may well return a read/write +file descriptor. +.ip +the following symbolic constants are provided for +.ir mode : +.rs +.tp 9 +.b s_irwxu +00700 user (file owner) has read, write, and execute permission +.tp +.b s_irusr +00400 user has read permission +.tp +.b s_iwusr +00200 user has write permission +.tp +.b s_ixusr +00100 user has execute permission +.tp +.b s_irwxg +00070 group has read, write, and execute permission +.tp +.b s_irgrp +00040 group has read permission +.tp +.b s_iwgrp +00020 group has write permission +.tp +.b s_ixgrp +00010 group has execute permission +.tp +.b s_irwxo +00007 others have read, write, and execute permission +.tp +.b s_iroth +00004 others have read permission +.tp +.b s_iwoth +00002 others have write permission +.tp +.b s_ixoth +00001 others have execute permission +.re +.ip +according to posix, the effect when other bits are set in +.i mode +is unspecified. +on linux, the following bits are also honored in +.ir mode : +.rs +.tp 9 +.b s_isuid +0004000 set-user-id bit +.tp +.b s_isgid +0002000 set-group-id bit (see +.br inode (7)). +.tp +.b s_isvtx +0001000 sticky bit (see +.br inode (7)). +.re +.tp +.br o_direct " (since linux 2.4.10)" +try to minimize cache effects of the i/o to and from this file. +in general this will degrade performance, but it is useful in +special situations, such as when applications do their own caching. +file i/o is done directly to/from user-space buffers. +the +.b o_direct +flag on its own makes an effort to transfer data synchronously, +but does not give the guarantees of the +.b o_sync +flag that data and necessary metadata are transferred. +to guarantee synchronous i/o, +.b o_sync +must be used in addition to +.br o_direct . +see notes below for further discussion. +.ip +a semantically similar (but deprecated) interface for block devices +is described in +.br raw (8). +.tp +.b o_directory +if \fipathname\fp is not a directory, cause the open to fail. +.\" but see the following and its replies: +.\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2 +.\" [patch] open: o_directory and o_creat together should fail +.\" o_directory | o_creat causes o_directory to be ignored. +this flag was added in kernel version 2.1.126, to +avoid denial-of-service problems if +.br opendir (3) +is called on a +fifo or tape device. +.tp +.b o_dsync +write operations on the file will complete according to the requirements of +synchronized i/o +.i data +integrity completion. +.ip +by the time +.br write (2) +(and similar) +return, the output data +has been transferred to the underlying hardware, +along with any file metadata that would be required to retrieve that data +(i.e., as though each +.br write (2) +was followed by a call to +.br fdatasync (2)). +.ir "see notes below" . +.tp +.b o_excl +ensure that this call creates the file: +if this flag is specified in conjunction with +.br o_creat , +and +.i pathname +already exists, then +.br open () +fails with the error +.br eexist . +.ip +when these two flags are specified, symbolic links are not followed: +.\" posix.1-2001 explicitly requires this behavior. +if +.i pathname +is a symbolic link, then +.br open () +fails regardless of where the symbolic link points. +.ip +in general, the behavior of +.b o_excl +is undefined if it is used without +.br o_creat . +there is one exception: on linux 2.6 and later, +.b o_excl +can be used without +.b o_creat +if +.i pathname +refers to a block device. +if the block device is in use by the system (e.g., mounted), +.br open () +fails with the error +.br ebusy . +.ip +on nfs, +.b o_excl +is supported only when using nfsv3 or later on kernel 2.6 or later. +in nfs environments where +.b o_excl +support is not provided, programs that rely on it +for performing locking tasks will contain a race condition. +portable programs that want to perform atomic file locking using a lockfile, +and need to avoid reliance on nfs support for +.br o_excl , +can create a unique file on +the same filesystem (e.g., incorporating hostname and pid), and use +.br link (2) +to make a link to the lockfile. +if +.br link (2) +returns 0, the lock is successful. +otherwise, use +.br stat (2) +on the unique file to check if its link count has increased to 2, +in which case the lock is also successful. +.tp +.b o_largefile +(lfs) +allow files whose sizes cannot be represented in an +.i off_t +(but can be represented in an +.ir off64_t ) +to be opened. +the +.b _largefile64_source +macro must be defined +(before including +.i any +header files) +in order to obtain this definition. +setting the +.b _file_offset_bits +feature test macro to 64 (rather than using +.br o_largefile ) +is the preferred +method of accessing large files on 32-bit systems (see +.br feature_test_macros (7)). +.tp +.br o_noatime " (since linux 2.6.8)" +do not update the file last access time +.ri ( st_atime +in the inode) +when the file is +.br read (2). +.ip +this flag can be employed only if one of the following conditions is true: +.rs +.ip * 3 +the effective uid of the process +.\" strictly speaking: the filesystem uid +matches the owner uid of the file. +.ip * +the calling process has the +.br cap_fowner +capability in its user namespace and +the owner uid of the file has a mapping in the namespace. +.re +.ip +this flag is intended for use by indexing or backup programs, +where its use can significantly reduce the amount of disk activity. +this flag may not be effective on all filesystems. +one example is nfs, where the server maintains the access time. +.\" the o_noatime flag also affects the treatment of st_atime +.\" by mmap() and readdir(2), mtk, dec 04. +.tp +.b o_noctty +if +.i pathname +refers to a terminal device\(emsee +.br tty (4)\(emit +will not become the process's controlling terminal even if the +process does not have one. +.tp +.b o_nofollow +if the trailing component (i.e., basename) of +.i pathname +is a symbolic link, then the open fails, with the error +.br eloop . +symbolic links in earlier components of the pathname will still be +followed. +(note that the +.b eloop +error that can occur in this case is indistinguishable from the case where +an open fails because there are too many symbolic links found +while resolving components in the prefix part of the pathname.) +.ip +this flag is a freebsd extension, which was added to linux in version 2.1.126, +and has subsequently been standardized in posix.1-2008. +.ip +see also +.br o_path +below. +.\" the headers from glibc 2.0.100 and later include a +.\" definition of this flag; \fikernels before 2.1.126 will ignore it if +.\" used\fp. +.tp +.br o_nonblock " or " o_ndelay +when possible, the file is opened in nonblocking mode. +neither the +.br open () +nor any subsequent i/o operations on the file descriptor which is +returned will cause the calling process to wait. +.ip +note that the setting of this flag has no effect on the operation of +.br poll (2), +.br select (2), +.br epoll (7), +and similar, +since those interfaces merely inform the caller about whether +a file descriptor is "ready", +meaning that an i/o operation performed on +the file descriptor with the +.b o_nonblock +flag +.i clear +would not block. +.ip +note that this flag has no effect for regular files and block devices; +that is, i/o operations will (briefly) block when device activity +is required, regardless of whether +.b o_nonblock +is set. +since +.b o_nonblock +semantics might eventually be implemented, +applications should not depend upon blocking behavior +when specifying this flag for regular files and block devices. +.ip +for the handling of fifos (named pipes), see also +.br fifo (7). +for a discussion of the effect of +.b o_nonblock +in conjunction with mandatory file locks and with file leases, see +.br fcntl (2). +.tp +.br o_path " (since linux 2.6.39)" +.\" commit 1abf0c718f15a56a0a435588d1b104c7a37dc9bd +.\" commit 326be7b484843988afe57566b627fb7a70beac56 +.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d +.\" +.\" http://thread.gmane.org/gmane.linux.man/2790/focus=3496 +.\" subject: re: [patch] open(2): document o_path +.\" newsgroups: gmane.linux.man, gmane.linux.kernel +.\" +obtain a file descriptor that can be used for two purposes: +to indicate a location in the filesystem tree and +to perform operations that act purely at the file descriptor level. +the file itself is not opened, and other file operations (e.g., +.br read (2), +.br write (2), +.br fchmod (2), +.br fchown (2), +.br fgetxattr (2), +.br ioctl (2), +.br mmap (2)) +fail with the error +.br ebadf . +.ip +the following operations +.i can +be performed on the resulting file descriptor: +.rs +.ip * 3 +.br close (2). +.ip * +.br fchdir (2), +if the file descriptor refers to a directory +(since linux 3.5). +.\" commit 332a2e1244bd08b9e3ecd378028513396a004a24 +.ip * +.br fstat (2) +(since linux 3.6). +.ip * +.\" fstat(): commit 55815f70147dcfa3ead5738fd56d3574e2e3c1c2 +.br fstatfs (2) +(since linux 3.12). +.\" fstatfs(): commit 9d05746e7b16d8565dddbe3200faa1e669d23bbf +.ip * +duplicating the file descriptor +.rb ( dup (2), +.br fcntl (2) +.br f_dupfd , +etc.). +.ip * +getting and setting file descriptor flags +.rb ( fcntl (2) +.br f_getfd +and +.br f_setfd ). +.ip * +retrieving open file status flags using the +.br fcntl (2) +.br f_getfl +operation: the returned flags will include the bit +.br o_path . +.ip * +passing the file descriptor as the +.ir dirfd +argument of +.br openat () +and the other "*at()" system calls. +this includes +.br linkat (2) +with +.br at_empty_path +(or via procfs using +.br at_symlink_follow ) +even if the file is not a directory. +.ip * +passing the file descriptor to another process via a unix domain socket +(see +.br scm_rights +in +.br unix (7)). +.re +.ip +when +.b o_path +is specified in +.ir flags , +flag bits other than +.br o_cloexec , +.br o_directory , +and +.br o_nofollow +are ignored. +.ip +opening a file or directory with the +.b o_path +flag requires no permissions on the object itself +(but does require execute permission on the directories in the path prefix). +depending on the subsequent operation, +a check for suitable file permissions may be performed (e.g., +.br fchdir (2) +requires execute permission on the directory referred to +by its file descriptor argument). +by contrast, +obtaining a reference to a filesystem object by opening it with the +.b o_rdonly +flag requires that the caller have read permission on the object, +even when the subsequent operation (e.g., +.br fchdir (2), +.br fstat (2)) +does not require read permission on the object. +.ip +if +.i pathname +is a symbolic link and the +.br o_nofollow +flag is also specified, +then the call returns a file descriptor referring to the symbolic link. +this file descriptor can be used as the +.i dirfd +argument in calls to +.br fchownat (2), +.br fstatat (2), +.br linkat (2), +and +.br readlinkat (2) +with an empty pathname to have the calls operate on the symbolic link. +.ip +if +.i pathname +refers to an automount point that has not yet been triggered, so no +other filesystem is mounted on it, then the call returns a file +descriptor referring to the automount directory without triggering a mount. +.br fstatfs (2) +can then be used to determine if it is, in fact, an untriggered +automount point +.rb ( ".f_type == autofs_super_magic" ). +.ip +one use of +.b o_path +for regular files is to provide the equivalent of posix.1's +.b o_exec +functionality. +this permits us to open a file for which we have execute +permission but not read permission, and then execute that file, +with steps something like the following: +.ip +.in +4n +.ex +char buf[path_max]; +fd = open("some_prog", o_path); +snprintf(buf, path_max, "/proc/self/fd/%d", fd); +execl(buf, "some_prog", (char *) null); +.ee +.in +.ip +an +.b o_path +file descriptor can also be passed as the argument of +.br fexecve (3). +.tp +.b o_sync +write operations on the file will complete according to the requirements of +synchronized i/o +.i file +integrity completion +(by contrast with the +synchronized i/o +.i data +integrity completion +provided by +.br o_dsync .) +.ip +by the time +.br write (2) +(or similar) +returns, the output data and associated file metadata +have been transferred to the underlying hardware +(i.e., as though each +.br write (2) +was followed by a call to +.br fsync (2)). +.ir "see notes below" . +.tp +.br o_tmpfile " (since linux 3.11)" +.\" commit 60545d0d4610b02e55f65d141c95b18ccf855b6e +.\" commit f4e0c30c191f87851c4a53454abb55ee276f4a7e +.\" commit bb458c644a59dbba3a1fe59b27106c5e68e1c4bd +create an unnamed temporary regular file. +the +.i pathname +argument specifies a directory; +an unnamed inode will be created in that directory's filesystem. +anything written to the resulting file will be lost when +the last file descriptor is closed, unless the file is given a name. +.ip +.b o_tmpfile +must be specified with one of +.b o_rdwr +or +.b o_wronly +and, optionally, +.br o_excl . +if +.b o_excl +is not specified, then +.br linkat (2) +can be used to link the temporary file into the filesystem, making it +permanent, using code like the following: +.ip +.in +4n +.ex +char path[path_max]; +fd = open("/path/to/dir", o_tmpfile | o_rdwr, + s_irusr | s_iwusr); + +/* file i/o on \(aqfd\(aq... */ + +linkat(fd, "", at_fdcwd, "/path/for/file", at_empty_path); + +/* if the caller doesn\(aqt have the cap_dac_read_search + capability (needed to use at_empty_path with linkat(2)), + and there is a proc(5) filesystem mounted, then the + linkat(2) call above can be replaced with: + +snprintf(path, path_max, "/proc/self/fd/%d", fd); +linkat(at_fdcwd, path, at_fdcwd, "/path/for/file", + at_symlink_follow); +*/ +.ee +.in +.ip +in this case, +the +.br open () +.i mode +argument determines the file permission mode, as with +.br o_creat . +.ip +specifying +.b o_excl +in conjunction with +.b o_tmpfile +prevents a temporary file from being linked into the filesystem +in the above manner. +(note that the meaning of +.b o_excl +in this case is different from the meaning of +.b o_excl +otherwise.) +.ip +there are two main use cases for +.\" inspired by http://lwn.net/articles/559147/ +.br o_tmpfile : +.rs +.ip * 3 +improved +.br tmpfile (3) +functionality: race-free creation of temporary files that +(1) are automatically deleted when closed; +(2) can never be reached via any pathname; +(3) are not subject to symlink attacks; and +(4) do not require the caller to devise unique names. +.ip * +creating a file that is initially invisible, which is then populated +with data and adjusted to have appropriate filesystem attributes +.rb ( fchown (2), +.br fchmod (2), +.br fsetxattr (2), +etc.) +before being atomically linked into the filesystem +in a fully formed state (using +.br linkat (2) +as described above). +.re +.ip +.b o_tmpfile +requires support by the underlying filesystem; +only a subset of linux filesystems provide that support. +in the initial implementation, support was provided in +the ext2, ext3, ext4, udf, minix, and tmpfs filesystems. +.\" to check for support, grep for "tmpfile" in kernel sources +support for other filesystems has subsequently been added as follows: +xfs (linux 3.15); +.\" commit 99b6436bc29e4f10e4388c27a3e4810191cc4788 +.\" commit ab29743117f9f4c22ac44c13c1647fb24fb2bafe +btrfs (linux 3.16); +.\" commit ef3b9af50bfa6a1f02cd7b3f5124b712b1ba3e3c +f2fs (linux 3.16); +.\" commit 50732df02eefb39ab414ef655979c2c9b64ad21c +and ubifs (linux 4.9) +.tp +.b o_trunc +if the file already exists and is a regular file and the access mode allows +writing (i.e., is +.b o_rdwr +or +.br o_wronly ) +it will be truncated to length 0. +if the file is a fifo or terminal device file, the +.b o_trunc +flag is ignored. +otherwise, the effect of +.b o_trunc +is unspecified. +.ss creat() +a call to +.br creat () +is equivalent to calling +.br open () +with +.i flags +equal to +.br o_creat|o_wronly|o_trunc . +.ss openat() +the +.br openat () +system call operates in exactly the same way as +.br open (), +except for the differences described here. +.pp +the +.i dirfd +argument is used in conjunction with the +.i pathname +argument as follows: +.ip * 3 +if the pathname given in +.i pathname +is absolute, then +.i dirfd +is ignored. +.ip * +if the pathname given in +.i pathname +is relative and +.i dirfd +is the special value +.br at_fdcwd , +then +.i pathname +is interpreted relative to the current working +directory of the calling process (like +.br open ()). +.ip * +if the pathname given in +.i pathname +is relative, then it is interpreted relative to the directory +referred to by the file descriptor +.i dirfd +(rather than relative to the current working directory of +the calling process, as is done by +.br open () +for a relative pathname). +in this case, +.i dirfd +must be a directory that was opened for reading +.rb ( o_rdonly ) +or using the +.b o_path +flag. +.pp +if the pathname given in +.i pathname +is relative, and +.i dirfd +is not a valid file descriptor, an error +.rb ( ebadf ) +results. +(specifying an invalid file descriptor number in +.i dirfd +can be used as a means to ensure that +.i pathname +is absolute.) +.\" +.ss openat2(2) +the +.br openat2 (2) +system call is an extension of +.br openat (), +and provides a superset of the features of +.br openat (). +it is documented separately, in +.br openat2 (2). +.sh return value +on success, +.br open (), +.br openat (), +and +.br creat () +return the new file descriptor (a nonnegative integer). +on error, \-1 is returned and +.i errno +is set to indicate the error. +.sh errors +.br open (), +.br openat (), +and +.br creat () +can fail with the following errors: +.tp +.b eacces +the requested access to the file is not allowed, or search permission +is denied for one of the directories in the path prefix of +.ir pathname , +or the file did not exist yet and write access to the parent directory +is not allowed. +(see also +.br path_resolution (7).) +.tp +.b eacces +.\" commit 30aba6656f61ed44cba445a3c0d38b296fa9e8f5 +where +.b o_creat +is specified, the +.i protected_fifos +or +.i protected_regular +sysctl is enabled, the file already exists and is a fifo or regular file, the +owner of the file is neither the current user nor the owner of the +containing directory, and the containing directory is both world- or +group-writable and sticky. +for details, see the descriptions of +.ir /proc/sys/fs/protected_fifos +and +.ir /proc/sys/fs/protected_regular +in +.br proc (5). +.tp +.b ebadf +.rb ( openat ()) +.i pathname +is relative but +.i dirfd +is neither +.b at_fdcwd +nor a valid file descriptor. +.tp +.b ebusy +.b o_excl +was specified in +.i flags +and +.i pathname +refers to a block device that is in use by the system (e.g., it is mounted). +.tp +.b edquot +where +.b o_creat +is specified, the file does not exist, and the user's quota of disk +blocks or inodes on the filesystem has been exhausted. +.tp +.b eexist +.i pathname +already exists and +.br o_creat " and " o_excl +were used. +.tp +.b efault +.i pathname +points outside your accessible address space. +.tp +.b efbig +see +.br eoverflow . +.tp +.b eintr +while blocked waiting to complete an open of a slow device +(e.g., a fifo; see +.br fifo (7)), +the call was interrupted by a signal handler; see +.br signal (7). +.tp +.b einval +the filesystem does not support the +.br o_direct +flag. +see +.br notes +for more information. +.tp +.b einval +invalid value in +.\" in particular, __o_tmpfile instead of o_tmpfile +.ir flags . +.tp +.b einval +.b o_tmpfile +was specified in +.ir flags , +but neither +.b o_wronly +nor +.b o_rdwr +was specified. +.tp +.b einval +.b o_creat +was specified in +.i flags +and the final component ("basename") of the new file's +.i pathname +is invalid +(e.g., it contains characters not permitted by the underlying filesystem). +.tp +.b einval +the final component ("basename") of +.i pathname +is invalid +(e.g., it contains characters not permitted by the underlying filesystem). +.tp +.b eisdir +.i pathname +refers to a directory and the access requested involved writing +(that is, +.b o_wronly +or +.b o_rdwr +is set). +.tp +.b eisdir +.i pathname +refers to an existing directory, +.b o_tmpfile +and one of +.b o_wronly +or +.b o_rdwr +were specified in +.ir flags , +but this kernel version does not provide the +.b o_tmpfile +functionality. +.tp +.b eloop +too many symbolic links were encountered in resolving +.ir pathname . +.tp +.b eloop +.i pathname +was a symbolic link, and +.i flags +specified +.br o_nofollow +but not +.br o_path . +.tp +.b emfile +the per-process limit on the number of open file descriptors has been reached +(see the description of +.br rlimit_nofile +in +.br getrlimit (2)). +.tp +.b enametoolong +.i pathname +was too long. +.tp +.b enfile +the system-wide limit on the total number of open files has been reached. +.tp +.b enodev +.i pathname +refers to a device special file and no corresponding device exists. +(this is a linux kernel bug; in this situation +.b enxio +must be returned.) +.tp +.b enoent +.b o_creat +is not set and the named file does not exist. +.tp +.b enoent +a directory component in +.i pathname +does not exist or is a dangling symbolic link. +.tp +.b enoent +.i pathname +refers to a nonexistent directory, +.b o_tmpfile +and one of +.b o_wronly +or +.b o_rdwr +were specified in +.ir flags , +but this kernel version does not provide the +.b o_tmpfile +functionality. +.tp +.b enomem +the named file is a fifo, +but memory for the fifo buffer can't be allocated because +the per-user hard limit on memory allocation for pipes has been reached +and the caller is not privileged; see +.br pipe (7). +.tp +.b enomem +insufficient kernel memory was available. +.tp +.b enospc +.i pathname +was to be created but the device containing +.i pathname +has no room for the new file. +.tp +.b enotdir +a component used as a directory in +.i pathname +is not, in fact, a directory, or \fbo_directory\fp was specified and +.i pathname +was not a directory. +.tp +.b enotdir +.rb ( openat ()) +.i pathname +is a relative pathname and +.i dirfd +is a file descriptor referring to a file other than a directory. +.tp +.b enxio +.br o_nonblock " | " o_wronly +is set, the named file is a fifo, and +no process has the fifo open for reading. +.tp +.b enxio +the file is a device special file and no corresponding device exists. +.tp +.b enxio +the file is a unix domain socket. +.tp +.br eopnotsupp +the filesystem containing +.i pathname +does not support +.br o_tmpfile . +.tp +.b eoverflow +.i pathname +refers to a regular file that is too large to be opened. +the usual scenario here is that an application compiled +on a 32-bit platform without +.i \-d_file_offset_bits=64 +tried to open a file whose size exceeds +.i (1<<31)\-1 +bytes; +see also +.b o_largefile +above. +this is the error specified by posix.1; +in kernels before 2.6.24, linux gave the error +.b efbig +for this case. +.\" see http://bugzilla.kernel.org/show_bug.cgi?id=7253 +.\" "open of a large file on 32-bit fails with efbig, should be eoverflow" +.\" reported 2006-10-03 +.tp +.b eperm +the +.b o_noatime +flag was specified, but the effective user id of the caller +.\" strictly speaking, it's the filesystem uid... (mtk) +did not match the owner of the file and the caller was not privileged. +.tp +.b eperm +the operation was prevented by a file seal; see +.br fcntl (2). +.tp +.b erofs +.i pathname +refers to a file on a read-only filesystem and write access was +requested. +.tp +.b etxtbsy +.i pathname +refers to an executable image which is currently being executed and +write access was requested. +.tp +.b etxtbsy +.i pathname +refers to a file that is currently in use as a swap file, and the +.b o_trunc +flag was specified. +.tp +.b etxtbsy +.i pathname +refers to a file that is currently being read by the kernel (e.g., for +module/firmware loading), and write access was requested. +.tp +.b ewouldblock +the +.b o_nonblock +flag was specified, and an incompatible lease was held on the file +(see +.br fcntl (2)). +.sh versions +.br openat () +was added to linux in kernel 2.6.16; +library support was added to glibc in version 2.4. +.sh conforming to +.br open (), +.br creat () +svr4, 4.3bsd, posix.1-2001, posix.1-2008. +.pp +.br openat (): +posix.1-2008. +.pp +.br openat2 (2) +is linux-specific. +.pp +the +.br o_direct , +.br o_noatime , +.br o_path , +and +.br o_tmpfile +flags are linux-specific. +one must define +.b _gnu_source +to obtain their definitions. +.pp +the +.br o_cloexec , +.br o_directory , +and +.br o_nofollow +flags are not specified in posix.1-2001, +but are specified in posix.1-2008. +since glibc 2.12, one can obtain their definitions by defining either +.b _posix_c_source +with a value greater than or equal to 200809l or +.br _xopen_source +with a value greater than or equal to 700. +in glibc 2.11 and earlier, one obtains the definitions by defining +.br _gnu_source . +.pp +as noted in +.br feature_test_macros (7), +feature test macros such as +.br _posix_c_source , +.br _xopen_source , +and +.b _gnu_source +must be defined before including +.i any +header files. +.sh notes +under linux, the +.b o_nonblock +flag is sometimes used in cases where one wants to open +but does not necessarily have the intention to read or write. +for example, +this may be used to open a device in order to get a file descriptor +for use with +.br ioctl (2). +.pp +the (undefined) effect of +.b o_rdonly | o_trunc +varies among implementations. +on many systems the file is actually truncated. +.\" linux 2.0, 2.5: truncate +.\" solaris 5.7, 5.8: truncate +.\" irix 6.5: truncate +.\" tru64 5.1b: truncate +.\" hp-ux 11.22: truncate +.\" freebsd 4.7: truncate +.pp +note that +.br open () +can open device special files, but +.br creat () +cannot create them; use +.br mknod (2) +instead. +.pp +if the file is newly created, its +.ir st_atime , +.ir st_ctime , +.i st_mtime +fields +(respectively, time of last access, time of last status change, and +time of last modification; see +.br stat (2)) +are set +to the current time, and so are the +.i st_ctime +and +.i st_mtime +fields of the +parent directory. +otherwise, if the file is modified because of the +.b o_trunc +flag, its +.i st_ctime +and +.i st_mtime +fields are set to the current time. +.pp +the files in the +.i /proc/[pid]/fd +directory show the open file descriptors of the process with the pid +.ir pid . +the files in the +.i /proc/[pid]/fdinfo +directory show even more information about these file descriptors. +see +.br proc (5) +for further details of both of these directories. +.pp +the linux header file +.b +doesn't define +.br o_async ; +the (bsd-derived) +.b fasync +synonym is defined instead. +.\" +.\" +.ss open file descriptions +the term open file description is the one used by posix to refer to the +entries in the system-wide table of open files. +in other contexts, this object is +variously also called an "open file object", +a "file handle", an "open file table entry", +or\(emin kernel-developer parlance\(ema +.ir "struct file" . +.pp +when a file descriptor is duplicated (using +.br dup (2) +or similar), +the duplicate refers to the same open file description +as the original file descriptor, +and the two file descriptors consequently share +the file offset and file status flags. +such sharing can also occur between processes: +a child process created via +.br fork (2) +inherits duplicates of its parent's file descriptors, +and those duplicates refer to the same open file descriptions. +.pp +each +.br open () +of a file creates a new open file description; +thus, there may be multiple open file descriptions +corresponding to a file inode. +.pp +on linux, one can use the +.br kcmp (2) +.b kcmp_file +operation to test whether two file descriptors +(in the same process or in two different processes) +refer to the same open file description. +.\" +.\" +.ss synchronized i/o +the posix.1-2008 "synchronized i/o" option +specifies different variants of synchronized i/o, +and specifies the +.br open () +flags +.br o_sync , +.br o_dsync , +and +.br o_rsync +for controlling the behavior. +regardless of whether an implementation supports this option, +it must at least support the use of +.br o_sync +for regular files. +.pp +linux implements +.br o_sync +and +.br o_dsync , +but not +.br o_rsync . +somewhat incorrectly, glibc defines +.br o_rsync +to have the same value as +.br o_sync . +.rb ( o_rsync +is defined in the linux header file +.i +on hp pa-risc, but it is not used.) +.pp +.br o_sync +provides synchronized i/o +.i file +integrity completion, +meaning write operations will flush data and all associated metadata +to the underlying hardware. +.br o_dsync +provides synchronized i/o +.i data +integrity completion, +meaning write operations will flush data +to the underlying hardware, +but will only flush metadata updates that are required +to allow a subsequent read operation to complete successfully. +data integrity completion can reduce the number of disk operations +that are required for applications that don't need the guarantees +of file integrity completion. +.pp +to understand the difference between the two types of completion, +consider two pieces of file metadata: +the file last modification timestamp +.ri ( st_mtime ) +and the file length. +all write operations will update the last file modification timestamp, +but only writes that add data to the end of the +file will change the file length. +the last modification timestamp is not needed to ensure that +a read completes successfully, but the file length is. +thus, +.br o_dsync +would only guarantee to flush updates to the file length metadata +(whereas +.br o_sync +would also always flush the last modification timestamp metadata). +.pp +before linux 2.6.33, linux implemented only the +.br o_sync +flag for +.br open (). +however, when that flag was specified, +most filesystems actually provided the equivalent of synchronized i/o +.i data +integrity completion (i.e., +.br o_sync +was actually implemented as the equivalent of +.br o_dsync ). +.pp +since linux 2.6.33, proper +.br o_sync +support is provided. +however, to ensure backward binary compatibility, +.br o_dsync +was defined with the same value as the historical +.br o_sync , +and +.br o_sync +was defined as a new (two-bit) flag value that includes the +.br o_dsync +flag value. +this ensures that applications compiled against +new headers get at least +.br o_dsync +semantics on pre-2.6.33 kernels. +.\" +.ss c library/kernel differences +since version 2.26, +the glibc wrapper function for +.br open () +employs the +.br openat () +system call, rather than the kernel's +.br open () +system call. +for certain architectures, this is also true in glibc versions before 2.26. +.\" +.ss nfs +there are many infelicities in the protocol underlying nfs, affecting +amongst others +.br o_sync " and " o_ndelay . +.pp +on nfs filesystems with uid mapping enabled, +.br open () +may +return a file descriptor but, for example, +.br read (2) +requests are denied +with \fbeacces\fp. +this is because the client performs +.br open () +by checking the +permissions, but uid mapping is performed by the server upon +read and write requests. +.\" +.\" +.ss fifos +opening the read or write end of a fifo blocks until the other +end is also opened (by another process or thread). +see +.br fifo (7) +for further details. +.\" +.\" +.ss file access mode +unlike the other values that can be specified in +.ir flags , +the +.i "access mode" +values +.br o_rdonly ", " o_wronly ", and " o_rdwr +do not specify individual bits. +rather, they define the low order two bits of +.ir flags , +and are defined respectively as 0, 1, and 2. +in other words, the combination +.b "o_rdonly | o_wronly" +is a logical error, and certainly does not have the same meaning as +.br o_rdwr . +.pp +linux reserves the special, nonstandard access mode 3 (binary 11) in +.i flags +to mean: +check for read and write permission on the file and return a file descriptor +that can't be used for reading or writing. +this nonstandard access mode is used by some linux drivers to return a +file descriptor that is to be used only for device-specific +.br ioctl (2) +operations. +.\" see for example util-linux's disk-utils/setfdprm.c +.\" for some background on access mode 3, see +.\" http://thread.gmane.org/gmane.linux.kernel/653123 +.\" "[rfc] correct flags to f_mode conversion in __dentry_open" +.\" lkml, 12 mar 2008 +.\" +.\" +.ss rationale for openat() and other "directory file descriptor" apis +.br openat () +and the other system calls and library functions that take +a directory file descriptor argument +(i.e., +.br execveat (2), +.br faccessat (2), +.br fanotify_mark (2), +.br fchmodat (2), +.br fchownat (2), +.br fspick (2), +.br fstatat (2), +.br futimesat (2), +.br linkat (2), +.br mkdirat (2), +.br mknodat (2), +.br mount_setattr (2), +.br move_mount (2), +.br name_to_handle_at (2), +.br open_tree (2), +.br openat2 (2), +.br readlinkat (2), +.br renameat (2), +.br renameat2 (2), +.br statx (2), +.br symlinkat (2), +.br unlinkat (2), +.br utimensat (2), +.br mkfifoat (3), +and +.br scandirat (3)) +address two problems with the older interfaces that preceded them. +here, the explanation is in terms of the +.br openat () +call, but the rationale is analogous for the other interfaces. +.pp +first, +.br openat () +allows an application to avoid race conditions that could +occur when using +.br open () +to open files in directories other than the current working directory. +these race conditions result from the fact that some component +of the directory prefix given to +.br open () +could be changed in parallel with the call to +.br open (). +suppose, for example, that we wish to create the file +.i dir1/dir2/xxx.dep +if the file +.i dir1/dir2/xxx +exists. +the problem is that between the existence check and the file-creation step, +.i dir1 +or +.i dir2 +(which might be symbolic links) +could be modified to point to a different location. +such races can be avoided by +opening a file descriptor for the target directory, +and then specifying that file descriptor as the +.i dirfd +argument of (say) +.br fstatat (2) +and +.br openat (). +the use of the +.i dirfd +file descriptor also has other benefits: +.ip * 3 +the file descriptor is a stable reference to the directory, +even if the directory is renamed; and +.ip * +the open file descriptor prevents the underlying filesystem from +being dismounted, +just as when a process has a current working directory on a filesystem. +.pp +second, +.br openat () +allows the implementation of a per-thread "current working +directory", via file descriptor(s) maintained by the application. +(this functionality can also be obtained by tricks based +on the use of +.ir /proc/self/fd/ dirfd, +but less efficiently.) +.pp +the +.i dirfd +argument for these apis can be obtained by using +.br open () +or +.br openat () +to open a directory (with either the +.br o_rdonly +or the +.br o_path +flag). +alternatively, such a file descriptor can be obtained by applying +.br dirfd (3) +to a directory stream created using +.br opendir (3). +.pp +when these apis are given a +.i dirfd +argument of +.br at_fdcwd +or the specified pathname is absolute, +then they handle their pathname argument in the same way as +the corresponding conventional apis. +however, in this case, several of the apis have a +.i flags +argument that provides access to functionality that is not available with +the corresponding conventional apis. +.\" +.\" +.ss o_direct +the +.b o_direct +flag may impose alignment restrictions on the length and address +of user-space buffers and the file offset of i/os. +in linux alignment +restrictions vary by filesystem and kernel version and might be +absent entirely. +however there is currently no filesystem\-independent +interface for an application to discover these restrictions for a given +file or filesystem. +some filesystems provide their own interfaces +for doing so, for example the +.b xfs_ioc_dioinfo +operation in +.br xfsctl (3). +.pp +under linux 2.4, transfer sizes, the alignment of the user buffer, +and the file offset must all be multiples of the logical block size +of the filesystem. +since linux 2.6.0, alignment to the logical block size of the +underlying storage (typically 512 bytes) suffices. +the logical block size can be determined using the +.br ioctl (2) +.b blksszget +operation or from the shell using the command: +.pp +.in +4n +.ex +blockdev \-\-getss +.ee +.in +.pp +.b o_direct +i/os should never be run concurrently with the +.br fork (2) +system call, +if the memory buffer is a private mapping +(i.e., any mapping created with the +.br mmap (2) +.br map_private +flag; +this includes memory allocated on the heap and statically allocated buffers). +any such i/os, whether submitted via an asynchronous i/o interface or from +another thread in the process, +should be completed before +.br fork (2) +is called. +failure to do so can result in data corruption and undefined behavior in +parent and child processes. +this restriction does not apply when the memory buffer for the +.b o_direct +i/os was created using +.br shmat (2) +or +.br mmap (2) +with the +.b map_shared +flag. +nor does this restriction apply when the memory buffer has been advised as +.b madv_dontfork +with +.br madvise (2), +ensuring that it will not be available +to the child after +.br fork (2). +.pp +the +.b o_direct +flag was introduced in sgi irix, where it has alignment +restrictions similar to those of linux 2.4. +irix has also a +.br fcntl (2) +call to query appropriate alignments, and sizes. +freebsd 4.x introduced +a flag of the same name, but without alignment restrictions. +.pp +.b o_direct +support was added under linux in kernel version 2.4.10. +older linux kernels simply ignore this flag. +some filesystems may not implement the flag, in which case +.br open () +fails with the error +.b einval +if it is used. +.pp +applications should avoid mixing +.b o_direct +and normal i/o to the same file, +and especially to overlapping byte regions in the same file. +even when the filesystem correctly handles the coherency issues in +this situation, overall i/o throughput is likely to be slower than +using either mode alone. +likewise, applications should avoid mixing +.br mmap (2) +of files with direct i/o to the same files. +.pp +the behavior of +.b o_direct +with nfs will differ from local filesystems. +older kernels, or +kernels configured in certain ways, may not support this combination. +the nfs protocol does not support passing the flag to the server, so +.b o_direct +i/o will bypass the page cache only on the client; the server may +still cache the i/o. +the client asks the server to make the i/o +synchronous to preserve the synchronous semantics of +.br o_direct . +some servers will perform poorly under these circumstances, especially +if the i/o size is small. +some servers may also be configured to +lie to clients about the i/o having reached stable storage; this +will avoid the performance penalty at some risk to data integrity +in the event of server power failure. +the linux nfs client places no alignment restrictions on +.b o_direct +i/o. +.pp +in summary, +.b o_direct +is a potentially powerful tool that should be used with caution. +it is recommended that applications treat use of +.b o_direct +as a performance option which is disabled by default. +.sh bugs +currently, it is not possible to enable signal-driven +i/o by specifying +.b o_async +when calling +.br open (); +use +.br fcntl (2) +to enable this flag. +.\" fixme . check bugzilla report on open(o_async) +.\" see http://bugzilla.kernel.org/show_bug.cgi?id=5993 +.pp +one must check for two different error codes, +.b eisdir +and +.br enoent , +when trying to determine whether the kernel supports +.b o_tmpfile +functionality. +.pp +when both +.b o_creat +and +.b o_directory +are specified in +.ir flags +and the file specified by +.i pathname +does not exist, +.br open () +will create a regular file (i.e., +.b o_directory +is ignored). +.sh see also +.br chmod (2), +.br chown (2), +.br close (2), +.br dup (2), +.br fcntl (2), +.br link (2), +.br lseek (2), +.br mknod (2), +.br mmap (2), +.br mount (2), +.br open_by_handle_at (2), +.br openat2 (2), +.br read (2), +.br socket (2), +.br stat (2), +.br umask (2), +.br unlink (2), +.br write (2), +.br fopen (3), +.br acl (5), +.br fifo (7), +.br inode (7), +.br path_resolution (7), +.br symlink (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-13.7 + +.so man3/endian.3 + +.\" copyright 1991 the regents of the university of california. +.\" all rights reserved. +.\" +.\" %%%license_start(bsd_4_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. all advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" this product includes software developed by the university of +.\" california, berkeley and its contributors. +.\" 4. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" @(#)popen.3 6.4 (berkeley) 4/30/91 +.\" +.\" converted for linux, mon nov 29 14:45:38 1993, faith@cs.unc.edu +.\" modified sat may 18 20:37:44 1996 by martin schulze (joey@linux.de) +.\" modified 7 may 1998 by joseph s. myers (jsm28@cam.ac.uk) +.\" +.th popen 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +popen, pclose \- pipe stream to or from a process +.sh synopsis +.nf +.b #include +.pp +.bi "file *popen(const char *" command ", const char *" type ); +.bi "int pclose(file *" stream ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br popen (), +.br pclose (): +.nf + _posix_c_source >= 2 + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +the +.br popen () +function opens a process by creating a pipe, forking, and invoking the +shell. +since a pipe is by definition unidirectional, the +.i type +argument may specify only reading or writing, not both; the resulting +stream is correspondingly read-only or write-only. +.pp +the +.i command +argument is a pointer to a null-terminated string containing a shell +command line. +this command is passed to +.i /bin/sh +using the +.b \-c +flag; interpretation, if any, is performed by the shell. +.pp +the +.i type +argument is a pointer to a null-terminated string which must contain +either the letter \(aqr\(aq for reading or the letter \(aqw\(aq for writing. +since glibc 2.9, +this argument can additionally include the letter \(aqe\(aq, +which causes the close-on-exec flag +.rb ( fd_cloexec ) +to be set on the underlying file descriptor; +see the description of the +.b o_cloexec +flag in +.br open (2) +for reasons why this may be useful. +.pp +the return value from +.br popen () +is a normal standard i/o stream in all respects save that it must be closed +with +.br pclose () +rather than +.br fclose (3). +writing to such a stream writes to the standard input of the command; the +command's standard output is the same as that of the process that called +.br popen (), +unless this is altered by the command itself. +conversely, reading from +the stream reads the command's standard output, and the command's +standard input is the same as that of the process that called +.br popen (). +.pp +note that output +.br popen () +streams are block buffered by default. +.pp +the +.br pclose () +function waits for the associated process to terminate and returns the exit +status of the command as returned by +.br wait4 (2). +.sh return value +.br popen (): +on success, returns a pointer to an open stream that +can be used to read or write to the pipe; +if the +.br fork (2) +or +.br pipe (2) +calls fail, or if the function cannot allocate memory, +null is returned. +.pp +.br pclose (): +on success, returns the exit status of the command; if +.\" these conditions actually give undefined results, so i commented +.\" them out. +.\" .i stream +.\" is not associated with a "popen()ed" command, if +.\".i stream +.\" already "pclose()d", or if +.br wait4 (2) +returns an error, or some other error is detected, +\-1 is returned. +.pp +on failure, both functions set +.i errno +to indicate the error. +.sh errors +the +.br popen () +function does not set +.i errno +if memory allocation fails. +if the underlying +.br fork (2) +or +.br pipe (2) +fails, +.i errno +is set to indicate the error. +if the +.i type +argument is invalid, and this condition is detected, +.i errno +is set to +.br einval . +.pp +if +.br pclose () +cannot obtain the child status, +.i errno +is set to +.br echild . +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br popen (), +.br pclose () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.pp +the \(aqe\(aq value for +.i type +is a linux extension. +.sh notes +.br note : +carefully read caveats in +.br system (3). +.sh bugs +since the standard input of a command opened for reading shares its seek +offset with the process that called +.br popen (), +if the original process has done a buffered read, the command's input +position may not be as expected. +similarly, the output from a command +opened for writing may become intermingled with that of the original +process. +the latter can be avoided by calling +.br fflush (3) +before +.br popen (). +.pp +failure to execute the shell is indistinguishable from the shell's failure +to execute command, or an immediate exit of the command. +the only hint is an exit status of 127. +.\" .sh history +.\" a +.\" .br popen () +.\" and a +.\" .br pclose () +.\" function appeared in version 7 at&t unix. +.sh see also +.br sh (1), +.br fork (2), +.br pipe (2), +.br wait4 (2), +.br fclose (3), +.br fflush (3), +.br fopen (3), +.br stdio (3), +.br system (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2003 andries brouwer (aeb@cwi.nl) +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.th ualarm 3 2021-03-22 "" "linux programmer's manual" +.sh name +ualarm \- schedule signal after given number of microseconds +.sh synopsis +.nf +.b "#include " +.pp +.bi "useconds_t ualarm(useconds_t " usecs ", useconds_t " interval ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br ualarm (): +.nf + since glibc 2.12: + (_xopen_source >= 500) && ! (_posix_c_source >= 200809l) + || /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source + before glibc 2.12: + _bsd_source || _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended +.fi +.sh description +the +.br ualarm () +function causes the signal +.b sigalrm +to be sent to the invoking process after (not less than) +.i usecs +microseconds. +the delay may be lengthened slightly by any system activity +or by the time spent processing the call or by the +granularity of system timers. +.pp +unless caught or ignored, the +.b sigalrm +signal will terminate the process. +.pp +if the +.i interval +argument is nonzero, further +.b sigalrm +signals will be sent every +.i interval +microseconds after the first. +.sh return value +this function returns the number of microseconds remaining for +any alarm that was previously set, or 0 if no alarm was pending. +.sh errors +.tp +.b eintr +interrupted by a signal; see +.br signal (7). +.tp +.b einval +\fiusecs\fp or \fiinterval\fp is not smaller than 1000000. +(on systems where that is considered an error.) +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br ualarm () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +4.3bsd, posix.1-2001. +posix.1-2001 marks +.br ualarm () +as obsolete. +posix.1-2008 removes the specification of +.br ualarm (). +4.3bsd, susv2, and posix do not define any errors. +.sh notes +posix.1-2001 does not specify what happens if the +.i usecs +argument is 0. +.\" this case is not documented in hp-us, solar, freebsd, netbsd, or openbsd! +on linux (and probably most other systems), +the effect is to cancel any pending alarm. +.pp +the type +.i useconds_t +is an unsigned integer type capable of holding integers +in the range [0,1000000]. +on the original bsd implementation, and in glibc before version 2.1, +the arguments to +.br ualarm () +were instead typed as +.ir "unsigned int" . +programs will be more portable if they never mention +.i useconds_t +explicitly. +.pp +the interaction of this function with +other timer functions such as +.br alarm (2), +.br sleep (3), +.br nanosleep (2), +.br setitimer (2), +.br timer_create (2), +.br timer_delete (2), +.br timer_getoverrun (2), +.br timer_gettime (2), +.br timer_settime (2), +.br usleep (3) +is unspecified. +.pp +this function is obsolete. +use +.br setitimer (2) +or posix interval timers +.rb ( timer_create (2), +etc.) +instead. +.sh see also +.br alarm (2), +.br getitimer (2), +.br nanosleep (2), +.br select (2), +.br setitimer (2), +.br usleep (3), +.br time (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 1993 rickard e. faith (faith@cs.unc.edu) +.\" portions extracted from /usr/include/sys/socket.h, which does not have +.\" any authorship information in it. it is probably available under the gpl. +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" +.\" other portions are from the 6.9 (berkeley) 3/10/91 man page: +.\" +.\" copyright (c) 1983 the regents of the university of california. +.\" all rights reserved. +.\" +.\" %%%license_start(bsd_4_clause_ucb) +.\" redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. all advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" this product includes software developed by the university of +.\" california, berkeley and its contributors. +.\" 4. neither the name of the university nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" this software is provided by the regents and contributors ``as is'' and +.\" any express or implied warranties, including, but not limited to, the +.\" implied warranties of merchantability and fitness for a particular purpose +.\" are disclaimed. in no event shall the regents or contributors be liable +.\" for any direct, indirect, incidental, special, exemplary, or consequential +.\" damages (including, but not limited to, procurement of substitute goods +.\" or services; loss of use, data, or profits; or business interruption) +.\" however caused and on any theory of liability, whether in contract, strict +.\" liability, or tort (including negligence or otherwise) arising in any way +.\" out of the use of this software, even if advised of the possibility of +.\" such damage. +.\" %%%license_end +.\" +.\" modified 1997-01-31 by eric s. raymond +.\" modified 1998, 1999 by andi kleen +.\" modified 2004-06-23 by michael kerrisk +.\" +.th connect 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +connect \- initiate a connection on a socket +.sh synopsis +.nf +.b #include +.pp +.bi "int connect(int " sockfd ", const struct sockaddr *" addr , +.bi " socklen_t " addrlen ); +.fi +.sh description +the +.br connect () +system call connects the socket referred to by the file descriptor +.i sockfd +to the address specified by +.ir addr . +the +.i addrlen +argument specifies the size of +.ir addr . +the format of the address in +.i addr +is determined by the address space of the socket +.ir sockfd ; +see +.br socket (2) +for further details. +.pp +if the socket +.i sockfd +is of type +.br sock_dgram , +then +.i addr +is the address to which datagrams are sent by default, and the only +address from which datagrams are received. +if the socket is of type +.b sock_stream +or +.br sock_seqpacket , +this call attempts to make a connection to the socket that is bound +to the address specified by +.ir addr . +.pp +some protocol sockets (e.g., unix domain stream sockets) +may successfully +.br connect () +only once. +.pp +some protocol sockets +(e.g., datagram sockets in the unix and internet domains) +may use +.br connect () +multiple times to change their association. +.pp +some protocol sockets +(e.g., tcp sockets as well as datagram sockets in the unix and +internet domains) +may dissolve the association by connecting to an address with the +.i sa_family +member of +.i sockaddr +set to +.br af_unspec ; +thereafter, the socket can be connected to another address. +.rb ( af_unspec +is supported on linux since kernel 2.2.) +.sh return value +if the connection or binding succeeds, zero is returned. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +the following are general socket errors only. +there may be other domain-specific error codes. +.tp +.b eacces +for unix domain sockets, which are identified by pathname: +write permission is denied on the socket file, +or search permission is denied for one of the directories +in the path prefix. +(see also +.br path_resolution (7).) +.tp +.br eacces ", " eperm +the user tried to connect to a broadcast address without having the socket +broadcast flag enabled or the connection request failed because of a local +firewall rule. +.ip +.b eacces +can also be returned if an selinux policy denied a connection (for +example, if there is a policy saying that an http proxy can only +connect to ports associated with http servers, and the proxy tries to +connect to a different port). +dd +.tp +.b eaddrinuse +local address is already in use. +.tp +.b eaddrnotavail +(internet domain sockets) +the socket referred to by +.i sockfd +had not previously been bound to an address and, +upon attempting to bind it to an ephemeral port, +it was determined that all port numbers in the ephemeral port range +are currently in use. +see the discussion of +.i /proc/sys/net/ipv4/ip_local_port_range +in +.br ip (7). +.tp +.b eafnosupport +the passed address didn't have the correct address family in its +.i sa_family +field. +.tp +.b eagain +for nonblocking unix domain sockets, the socket is nonblocking, and the +connection cannot be completed immediately. +for other socket families, there are insufficient entries in the routing cache. +.tp +.b ealready +the socket is nonblocking and a previous connection attempt has not yet +been completed. +.tp +.b ebadf +.i sockfd +is not a valid open file descriptor. +.tp +.b econnrefused +a +.br connect () +on a stream socket found no one listening on the remote address. +.tp +.b efault +the socket structure address is outside the user's address space. +.tp +.b einprogress +the socket is nonblocking and the connection cannot be completed immediately. +(unix domain sockets failed with +.br eagain +instead.) +it is possible to +.br select (2) +or +.br poll (2) +for completion by selecting the socket for writing. +after +.br select (2) +indicates writability, use +.br getsockopt (2) +to read the +.b so_error +option at level +.b sol_socket +to determine whether +.br connect () +completed successfully +.rb ( so_error +is zero) or unsuccessfully +.rb ( so_error +is one of the usual error codes listed here, +explaining the reason for the failure). +.tp +.b eintr +the system call was interrupted by a signal that was caught; see +.br signal (7). +.\" for tcp, the connection will complete asynchronously. +.\" see http://lkml.org/lkml/2005/7/12/254 +.tp +.b eisconn +the socket is already connected. +.tp +.b enetunreach +network is unreachable. +.tp +.b enotsock +the file descriptor +.i sockfd +does not refer to a socket. +.tp +.b eprototype +the socket type does not support the requested communications protocol. +this error can occur, for example, +on an attempt to connect a unix domain datagram socket to a stream socket. +.tp +.b etimedout +timeout while attempting connection. +the server may be too +busy to accept new connections. +note that for ip sockets the timeout may +be very long when syncookies are enabled on the server. +.sh conforming to +posix.1-2001, posix.1-2008, svr4, 4.4bsd, +.rb (connect () +first appeared in 4.2bsd). +.\" svr4 documents the additional +.\" general error codes +.\" .br eaddrnotavail , +.\" .br einval , +.\" .br eafnosupport , +.\" .br ealready , +.\" .br eintr , +.\" .br eprototype , +.\" and +.\" .br enosr . +.\" it also +.\" documents many additional error conditions not described here. +.sh notes +for background on the +.i socklen_t +type, see +.br accept (2). +.pp +if +.br connect () +fails, consider the state of the socket as unspecified. +portable applications should close the socket and create a new one for +reconnecting. +.sh examples +an example of the use of +.br connect () +is shown in +.br getaddrinfo (3). +.sh see also +.br accept (2), +.br bind (2), +.br getsockname (2), +.br listen (2), +.br socket (2), +.br path_resolution (7), +.br selinux (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2008 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_equal 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_equal \- compare thread ids +.sh synopsis +.nf +.b #include +.pp +.bi "int pthread_equal(pthread_t " t1 ", pthread_t " t2 ); +.pp +compile and link with \fi\-pthread\fp. +.fi +.sh description +the +.br pthread_equal () +function compares two thread identifiers. +.sh return value +if the two thread ids are equal, +.br pthread_equal () +returns a nonzero value; otherwise, it returns 0. +.sh errors +this function always succeeds. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_equal () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +the +.br pthread_equal () +function is necessary because thread ids should be considered opaque: +there is no portable way for applications to directly compare two +.i pthread_t +values. +.sh see also +.br pthread_create (3), +.br pthread_self (3), +.br pthreads (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2002 andries brouwer +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th tcgetsid 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +tcgetsid \- get session id +.sh synopsis +.nf +.br "#define _xopen_source 500" " /* see feature_test_macros(7) */" +.b "#include " +.pp +.bi "pid_t tcgetsid(int " fd ); +.fi +.sh description +the function +.br tcgetsid () +returns the session id of the current session that has the +terminal associated to +.i fd +as controlling terminal. +this terminal must be the controlling terminal of the calling process. +.sh return value +when +.i fd +refers to the controlling terminal of our session, +the function +.br tcgetsid () +will return the session id of this session. +otherwise, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b ebadf +.i fd +is not a valid file descriptor. +.tp +.b enotty +the calling process does not have a controlling terminal, or +it has one but it is not described by +.ir fd . +.sh versions +.br tcgetsid () +is provided in glibc since version 2.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br tcgetsid () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +this function is implemented via the +.b tiocgsid +.br ioctl (2), +present +since linux 2.1.71. +.sh see also +.br getsid (2) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2021 by christian brauner +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th mount_setattr 2 2021-08-27 "linux" "linux programmer's manual" +.sh name +mount_setattr \- change properties of a mount or mount tree +.sh synopsis +.nf + +.pp +.br "#include " " /* definition of " at_* " constants */" +.br "#include " " /* definition of " mount_attr_* " constants */" +.br "#include " " /* definition of " sys_* " constants */" +.b #include +.pp +.bi "int syscall(sys_mount_setattr, int " dirfd ", const char *" pathname , +.bi " unsigned int " flags ", struct mount_attr *" attr \ +", size_t " size ); +.fi +.pp +.ir note : +glibc provides no wrapper for +.br mount_setattr (), +necessitating the use of +.br syscall (2). +.sh description +the +.br mount_setattr () +system call changes the mount properties of a mount or an entire mount tree. +if +.i pathname +is a relative pathname, +then it is interpreted relative to +the directory referred to by the file descriptor +.ir dirfd . +if +.i dirfd +is the special value +.br at_fdcwd , +then +.i pathname +is interpreted relative to +the current working directory of the calling process. +if +.i pathname +is the empty string and +.b at_empty_path +is specified in +.ir flags , +then the mount properties of the mount identified by +.i dirfd +are changed. +(see +.br openat (2) +for an explanation of why the +.i dirfd +argument is useful.) +.pp +the +.br mount_setattr () +system call uses an extensible structure +.ri ( "struct mount_attr" ) +to allow for future extensions. +any non-flag extensions to +.br mount_setattr () +will be implemented as new fields appended to the this structure, +with a zero value in a new field resulting in the kernel behaving +as though that extension field was not present. +therefore, +the caller +.i must +zero-fill this structure on initialization. +see the "extensibility" subsection under +.b notes +for more details. +.pp +the +.i size +argument should usually be specified as +.ir "sizeof(struct mount_attr)" . +however, if the caller is using a kernel that supports an extended +.ir "struct mount_attr" , +but the caller does not intend to make use of these features, +it is possible to pass the size of an earlier +version of the structure together with the extended structure. +this allows the kernel to not copy later parts of the structure +that aren't used anyway. +with each extension that changes the size of +.ir "struct mount_attr" , +the kernel will expose a definition of the form +.bi mount_attr_size_ver number\c +\&. +for example, the macro for the size of the initial version of +.i struct mount_attr +is +.br mount_attr_size_ver0 . +.pp +the +.i flags +argument can be used to alter the pathname resolution behavior. +the supported values are: +.tp +.b at_empty_path +if +.i pathname +is the empty string, +change the mount properties on +.i dirfd +itself. +.tp +.b at_recursive +change the mount properties of the entire mount tree. +.tp +.b at_symlink_nofollow +don't follow trailing symbolic links. +.tp +.b at_no_automount +don't trigger automounts. +.pp +the +.i attr +argument of +.br mount_setattr () +is a structure of the following form: +.pp +.in +4n +.ex +struct mount_attr { + __u64 attr_set; /* mount properties to set */ + __u64 attr_clr; /* mount properties to clear */ + __u64 propagation; /* mount propagation type */ + __u64 userns_fd; /* user namespace file descriptor */ +}; +.ee +.in +.pp +the +.i attr_set +and +.i attr_clr +members are used to specify the mount properties that +are supposed to be set or cleared for a mount or mount tree. +flags set in +.i attr_set +enable a property on a mount or mount tree, +and flags set in +.i attr_clr +remove a property from a mount or mount tree. +.pp +when changing mount properties, +the kernel will first clear the flags specified +in the +.i attr_clr +field, +and then set the flags specified in the +.i attr_set +field. +for example, these settings: +.pp +.in +4n +.ex +struct mount_attr attr = { + .attr_clr = mount_attr_noexec | mount_attr_nodev, + .attr_set = mount_attr_rdonly | mount_attr_nosuid, +}; +.ee +.in +.pp +are equivalent to the following steps: +.pp +.in +4n +.ex +unsigned int current_mnt_flags = mnt->mnt_flags; + +/* + * clear all flags set in .attr_clr, + * clearing mount_attr_noexec and mount_attr_nodev. + */ +current_mnt_flags &= ~attr->attr_clr; + +/* + * now set all flags set in .attr_set, + * applying mount_attr_rdonly and mount_attr_nosuid. + */ +current_mnt_flags |= attr->attr_set; + +mnt->mnt_flags = current_mnt_flags; +.ee +.in +.pp +as a result of this change, the mount or mount tree (a) is read-only; +(b) blocks the execution of set-user-id and set-group-id programs; +(c) allows execution of programs; and (d) allows access to devices. +.pp +multiple changes with the same set of flags requested +in +.i attr_clr +and +.i attr_set +are guaranteed to be idempotent after the changes have been applied. +.pp +the following mount attributes can be specified in the +.i attr_set +or +.i attr_clr +fields: +.tp +.b mount_attr_rdonly +if set in +.ir attr_set , +makes the mount read-only. +if set in +.ir attr_clr , +removes the read-only setting if set on the mount. +.tp +.b mount_attr_nosuid +if set in +.ir attr_set , +causes the mount not to honor the set-user-id and set-group-id mode bits and +file capabilities when executing programs. +if set in +.ir attr_clr , +clears the set-user-id, set-group-id, +and file capability restriction if set on this mount. +.tp +.b mount_attr_nodev +if set in +.ir attr_set , +prevents access to devices on this mount. +if set in +.ir attr_clr , +removes the restriction that prevented accessing devices on this mount. +.tp +.b mount_attr_noexec +if set in +.ir attr_set , +prevents executing programs on this mount. +if set in +.ir attr_clr , +removes the restriction that prevented executing programs on this mount. +.tp +.b mount_attr_nosymfollow +if set in +.ir attr_set , +prevents following symbolic links on this mount. +if set in +.ir attr_clr , +removes the restriction that prevented following symbolic links on this mount. +.tp +.b mount_attr_nodiratime +if set in +.ir attr_set , +prevents updating access time for directories on this mount. +if set in +.ir attr_clr , +removes the restriction that prevented updating access time for directories. +note that +.b mount_attr_nodiratime +can be combined with other access-time settings +and is implied by the noatime setting. +all other access-time settings are mutually exclusive. +.tp +.br mount_attr__atime " - changing access-time settings" +the access-time values listed below are an enumeration that +includes the value zero, expressed in the bits defined by the mask +.br mount_attr__atime . +even though these bits are an enumeration +(in contrast to the other mount flags such as +.br mount_attr_noexec ), +they are nonetheless passed in +.i attr_set +and +.i attr_clr +for consistency with +.br fsmount (2), +which introduced this behavior. +.ip +note that, +since the access-time values are an enumeration rather than bit values, +a caller wanting to transition to a different access-time setting +cannot simply specify the access-time setting in +.ir attr_set , +but must also include +.b mount_attr__atime +in the +.i attr_clr +field. +the kernel will verify that +.b mount_attr__atime +isn't partially set in +.ir attr_clr +(i.e., either all bits in the +.b mount_attr__atime +bit field are either set or clear), and that +.i attr_set +doesn't have any access-time bits set if +.b mount_attr__atime +isn't set in +.ir attr_clr . +.rs +.tp +.b mount_attr_relatime +when a file is accessed via this mount, +update the file's last access time (atime) +only if the current value of atime is less than or equal to +the file's last modification time (mtime) or last status change time (ctime). +.ip +to enable this access-time setting on a mount or mount tree, +.b mount_attr_relatime +must be set in +.i attr_set +and +.b mount_attr__atime +must be set in the +.i attr_clr +field. +.tp +.b mount_attr_noatime +do not update access times for (all types of) files on this mount. +.ip +to enable this access-time setting on a mount or mount tree, +.b mount_attr_noatime +must be set in +.i attr_set +and +.b mount_attr__atime +must be set in the +.i attr_clr +field. +.tp +.b mount_attr_strictatime +always update the last access time (atime) +when files are accessed on this mount. +.ip +to enable this access-time setting on a mount or mount tree, +.b mount_attr_strictatime +must be set in +.i attr_set +and +.b mount_attr__atime +must be set in the +.i attr_clr +field. +.re +.tp +.b mount_attr_idmap +if set in +.ir attr_set , +creates an id-mapped mount. +the id mapping is taken from the user namespace specified in +.i userns_fd +and attached to the mount. +.ip +since it is not supported to +change the id mapping of a mount after it has been id mapped, +it is invalid to specify +.b mount_attr_idmap +in +.ir attr_clr . +.ip +for further details, see the subsection "id-mapped mounts" under notes. +.pp +the +.i propagation +field is used to specify the propagation type of the mount or mount tree. +this field either has the value zero, +meaning leave the propagation type unchanged, or it has one of +the following values: +.tp +.b ms_private +turn all mounts into private mounts. +.tp +.b ms_shared +turn all mounts into shared mounts. +.tp +.b ms_slave +turn all mounts into dependent mounts. +.tp +.b ms_unbindable +turn all mounts into unbindable mounts. +.pp +for further details on the above propagation types, see +.br mount_namespaces (7). +.sh return value +on success, +.br mount_setattr () +returns zero. +on error, +\-1 is returned and +.i errno +is set to indicate the cause of the error. +.sh errors +.tp +.b ebadf +.i pathname +is relative but +.i dirfd +is neither +.b at_fdcwd +nor a valid file descriptor. +.tp +.b ebadf +.i userns_fd +is not a valid file descriptor. +.tp +.b ebusy +the caller tried to change the mount to +.br mount_attr_rdonly , +but the mount still holds files open for writing. +.tp +.b einval +the pathname specified via the +.i dirfd +and +.i pathname +arguments to +.br mount_setattr () +isn't a mount point. +.tp +.b einval +an unsupported value was set in +.ir flags . +.tp +.b einval +an unsupported value was specified in the +.i attr_set +field of +.ir mount_attr . +.tp +.b einval +an unsupported value was specified in the +.i attr_clr +field of +.ir mount_attr . +.tp +.b einval +an unsupported value was specified in the +.i propagation +field of +.ir mount_attr . +.tp +.b einval +more than one of +.br ms_shared , +.br ms_slave , +.br ms_private , +or +.b ms_unbindable +was set in the +.i propagation +field of +.ir mount_attr . +.tp +.b einval +an access-time setting was specified in the +.i attr_set +field without +.b mount_attr__atime +being set in the +.i attr_clr +field. +.tp +.b einval +.b mount_attr_idmap +was specified in +.ir attr_clr . +.tp +.b einval +a file descriptor value was specified in +.i userns_fd +which exceeds +.br int_max . +.tp +.b einval +a valid file descriptor value was specified in +.ir userns_fd , +but the file descriptor did not refer to a user namespace. +.tp +.b einval +the underlying filesystem does not support id-mapped mounts. +.tp +.b einval +the mount that is to be id mapped is not a detached mount; +that is, the mount has not previously been visible in a mount namespace. +.tp +.b einval +a partial access-time setting was specified in +.i attr_clr +instead of +.b mount_attr__atime +being set. +.tp +.b einval +the mount is located outside the caller's mount namespace. +.tp +.b einval +the underlying filesystem has been mounted in a mount namespace that is +owned by a noninitial user namespace +.tp +.b enoent +a pathname was empty or had a nonexistent component. +.tp +.b enomem +when changing mount propagation to +.br ms_shared , +a new peer group id needs to be allocated for all mounts without a peer group +id set. +this allocation failed because there was not +enough memory to allocate the relevant internal structures. +.tp +.b enospc +when changing mount propagation to +.br ms_shared , +a new peer group id needs to be allocated for all mounts without a peer group +id set. +this allocation failed because +the kernel has run out of ids. +.\" christian bruner: i.e. someone has somehow managed to +.\" allocate so many peer groups and managed to keep the kernel running +.\" (???) that the ida has ran out of ids +.\" note that technically further error codes are possible that are +.\" specific to the id allocation implementation used. +.tp +.b eperm +one of the mounts had at least one of +.br mount_attr_noatime , +.br mount_attr_nodev , +.br mount_attr_nodiratime , +.br mount_attr_noexec , +.br mount_attr_nosuid , +or +.b mount_attr_rdonly +set and the flag is locked. +mount attributes become locked on a mount if: +.rs +.ip \(bu 3 +a new mount or mount tree is created causing mount propagation across user +namespaces +(i.e., propagation to a mount namespace owned by a different user namespace). +the kernel will lock the aforementioned flags to prevent these sensitive +properties from being altered. +.ip \(bu +a new mount and user namespace pair is created. +this happens for example when specifying +.b clone_newuser | clone_newns +in +.br unshare (2), +.br clone (2), +or +.br clone3 (2). +the aforementioned flags become locked in the new mount namespace +to prevent sensitive mount properties from being altered. +since the newly created mount namespace will be owned by the +newly created user namespace, +a calling process that is privileged in the new +user namespace would\(emin the absence of such locking\(embe +able to alter sensitive mount properties (e.g., to remount a mount +that was marked read-only as read-write in the new mount namespace). +.re +.tp +.b eperm +a valid file descriptor value was specified in +.ir userns_fd , +but the file descriptor refers to the initial user namespace. +.tp +.b eperm +an attempt was made to add an id mapping to a mount that is already id mapped. +.tp +.b eperm +the caller does not have +.b cap_sys_admin +in the initial user namespace. +.sh versions +.br mount_setattr () +first appeared in linux 5.12. +.\" commit 7d6beb71da3cc033649d641e1e608713b8220290 +.\" commit 2a1867219c7b27f928e2545782b86daaf9ad50bd +.\" commit 9caccd41541a6f7d6279928d9f971f6642c361af +.sh conforming to +.br mount_setattr () +is linux-specific. +.sh notes +.ss id-mapped mounts +creating an id-mapped mount makes it possible to +change the ownership of all files located under a mount. +thus, id-mapped mounts make it possible to +change ownership in a temporary and localized way. +it is a localized change because the ownership changes are +visible only via a specific mount. +all other users and locations where the filesystem is exposed are unaffected. +it is a temporary change because +the ownership changes are tied to the lifetime of the mount. +.pp +whenever callers interact with the filesystem through an id-mapped mount, +the id mapping of the mount will be applied to +user and group ids associated with filesystem objects. +this encompasses the user and group ids associated with inodes +and also the following +.br xattr (7) +keys: +.ip \(bu 3 +.ir security.capability , +whenever filesystem capabilities +are stored or returned in the +.b vfs_cap_revision_3 +format, +which stores a root user id alongside the capabilities +(see +.br capabilities (7)). +.ip \(bu +.i system.posix_acl_access +and +.ir system.posix_acl_default , +whenever user ids or group ids are stored in +.b acl_user +or +.b acl_group +entries. +.pp +the following conditions must be met in order to create an id-mapped mount: +.ip \(bu 3 +the caller must have the +.b cap_sys_admin +capability in the initial user namespace. +.ip \(bu +the filesystem must be mounted in a mount namespace +that is owned by the initial user namespace. +.ip \(bu +the underlying filesystem must support id-mapped mounts. +currently, the +.br xfs (5), +.br ext4 (5), +and +.b fat +filesystems support id-mapped mounts +with more filesystems being actively worked on. +.ip \(bu +the mount must not already be id-mapped. +this also implies that the id mapping of a mount cannot be altered. +.ip \(bu +the mount must be a detached mount; +that is, +it must have been created by calling +.br open_tree (2) +with the +.b open_tree_clone +flag and it must not already have been visible in a mount namespace. +(to put things another way: +the mount must not have been attached to the filesystem hierarchy +with a system call such as +.br move_mount (2).) +.pp +id mappings can be created for user ids, group ids, and project ids. +an id mapping is essentially a mapping of a range of user or group ids into +another or the same range of user or group ids. +id mappings are written to map files as three numbers +separated by white space. +the first two numbers specify the starting user or group id +in each of the two user namespaces. +the third number specifies the range of the id mapping. +for example, +a mapping for user ids such as "1000\ 1001\ 1" would indicate that +user id 1000 in the caller's user namespace is mapped to +user id 1001 in its ancestor user namespace. +since the map range is 1, +only user id 1000 is mapped. +.pp +it is possible to specify up to 340 id mappings for each id mapping type. +if any user ids or group ids are not mapped, +all files owned by that unmapped user or group id will appear as +being owned by the overflow user id or overflow group id respectively. +.pp +further details on setting up id mappings can be found in +.br user_namespaces (7). +.pp +in the common case, the user namespace passed in +.i userns_fd +(together with +.b mount_attr_idmap +in +.ir attr_set ) +to create an id-mapped mount will be the user namespace of a container. +in other scenarios it will be a dedicated user namespace associated with +a user's login session as is the case for portable home directories in +.br systemd-homed.service (8)). +it is also perfectly fine to create a dedicated user namespace +for the sake of id mapping a mount. +.pp +id-mapped mounts can be useful in the following +and a variety of other scenarios: +.ip \(bu 3 +sharing files or filesystems +between multiple users or multiple machines, +especially in complex scenarios. +for example, +id-mapped mounts are used to implement portable home directories in +.br systemd-homed.service (8), +where they allow users to move their home directory +to an external storage device +and use it on multiple computers +where they are assigned different user ids and group ids. +this effectively makes it possible to +assign random user ids and group ids at login time. +.ip \(bu +sharing files or filesystems +from the host with unprivileged containers. +this allows a user to avoid having to change ownership permanently through +.br chown (2). +.ip \(bu +id mapping a container's root filesystem. +users don't need to change ownership permanently through +.br chown (2). +especially for large root filesystems, using +.br chown (2) +can be prohibitively expensive. +.ip \(bu +sharing files or filesystems +between containers with non-overlapping id mappings. +.ip \(bu +implementing discretionary access (dac) permission checking +for filesystems lacking a concept of ownership. +.ip \(bu +efficiently changing ownership on a per-mount basis. +in contrast to +.br chown (2), +changing ownership of large sets of files is instantaneous with +id-mapped mounts. +this is especially useful when ownership of +an entire root filesystem of a virtual machine or container +is to be changed as mentioned above. +with id-mapped mounts, +a single +.br mount_setattr () +system call will be sufficient to change the ownership of all files. +.ip \(bu +taking the current ownership into account. +id mappings specify precisely +what a user or group id is supposed to be mapped to. +this contrasts with the +.br chown (2) +system call which cannot by itself +take the current ownership of the files it changes into account. +it simply changes the ownership to the specified user id and group id. +.ip \(bu +locally and temporarily restricted ownership changes. +id-mapped mounts make it possible to change ownership locally, +restricting the ownership changes to specific mounts, +and temporarily as the ownership changes only apply as long as the mount exists. +by contrast, +changing ownership via the +.br chown (2) +system call changes the ownership globally and permanently. +.\" +.ss extensibility +in order to allow for future extensibility, +.br mount_setattr () +requires the user-space application to specify the size of the +.i mount_attr +structure that it is passing. +by providing this information, it is possible for +.br mount_setattr () +to provide both forwards- and backwards-compatibility, with +.i size +acting as an implicit version number. +(because new extension fields will always +be appended, the structure size will always increase.) +this extensibility design is very similar to other system calls such as +.br perf_setattr (2), +.br perf_event_open (2), +.br clone3 (2) +and +.br openat2 (2). +.pp +let +.i usize +be the size of the structure as specified by the user-space application, +and let +.i ksize +be the size of the structure which the kernel supports, +then there are three cases to consider: +.ip \(bu 3 +if +.i ksize +equals +.ir usize , +then there is no version mismatch and +.i attr +can be used verbatim. +.ip \(bu +if +.i ksize +is larger than +.ir usize , +then there are some extension fields that the kernel supports +which the user-space application is unaware of. +because a zero value in any added extension field signifies a no-op, +the kernel treats all of the extension fields +not provided by the user-space application +as having zero values. +this provides backwards-compatibility. +.ip \(bu +if +.i ksize +is smaller than +.ir usize , +then there are some extension fields which the user-space application is aware +of but which the kernel does not support. +because any extension field must have its zero values signify a no-op, +the kernel can safely ignore the unsupported extension fields +if they are all zero. +if any unsupported extension fields are non-zero, +then \-1 is returned and +.i errno +is set to +.br e2big . +this provides forwards-compatibility. +.pp +because the definition of +.i struct mount_attr +may change in the future +(with new fields being added when system headers are updated), +user-space applications should zero-fill +.i struct mount_attr +to ensure that recompiling the program with new headers will not result in +spurious errors at runtime. +the simplest way is to use a designated initializer: +.pp +.in +4n +.ex +struct mount_attr attr = { + .attr_set = mount_attr_rdonly, + .attr_clr = mount_attr_nodev +}; +.ee +.in +.pp +alternatively, the structure can be zero-filled using +.br memset (3) +or similar functions: +.pp +.in +4n +.ex +struct mount_attr attr; +memset(&attr, 0, sizeof(attr)); +attr.attr_set = mount_attr_rdonly; +attr.attr_clr = mount_attr_nodev; +.ee +.in +.pp +a user-space application that wishes to determine which extensions the running +kernel supports can do so by conducting a binary search on +.i size +with a structure which has every byte nonzero +(to find the largest value which doesn't produce an error of +.br e2big ). +.sh examples +.ex +/* + * this program allows the caller to create a new detached mount + * and set various properties on it. + */ +#define _gnu_source +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static inline int +mount_setattr(int dirfd, const char *pathname, unsigned int flags, + struct mount_attr *attr, size_t size) +{ + return syscall(sys_mount_setattr, dirfd, pathname, flags, + attr, size); +} + +static inline int +open_tree(int dirfd, const char *filename, unsigned int flags) +{ + return syscall(sys_open_tree, dirfd, filename, flags); +} + +static inline int +move_mount(int from_dirfd, const char *from_pathname, + int to_dirfd, const char *to_pathname, unsigned int flags) +{ + return syscall(sys_move_mount, from_dirfd, from_pathname, + to_dirfd, to_pathname, flags); +} + +static const struct option longopts[] = { + {"map\-mount", required_argument, null, 'a'}, + {"recursive", no_argument, null, 'b'}, + {"read\-only", no_argument, null, 'c'}, + {"block\-setid", no_argument, null, 'd'}, + {"block\-devices", no_argument, null, 'e'}, + {"block\-exec", no_argument, null, 'f'}, + {"no\-access\-time", no_argument, null, 'g'}, + { null, 0, null, 0 }, +}; + +#define exit_log(format, ...) do \e +{ \e + fprintf(stderr, format, ##__va_args__); \e + exit(exit_failure); \e +} while (0) + +int +main(int argc, char *argv[]) +{ + struct mount_attr *attr = &(struct mount_attr){}; + int fd_userns = \-1; + bool recursive = false; + int index = 0; + int ret; + + while ((ret = getopt_long_only(argc, argv, "", + longopts, &index)) != \-1) { + switch (ret) { + case 'a': + fd_userns = open(optarg, o_rdonly | o_cloexec); + if (fd_userns == \-1) + exit_log("%m \- failed top open %s\en", optarg); + break; + case 'b': + recursive = true; + break; + case 'c': + attr\->attr_set |= mount_attr_rdonly; + break; + case 'd': + attr\->attr_set |= mount_attr_nosuid; + break; + case 'e': + attr\->attr_set |= mount_attr_nodev; + break; + case 'f': + attr\->attr_set |= mount_attr_noexec; + break; + case 'g': + attr\->attr_set |= mount_attr_noatime; + attr\->attr_clr |= mount_attr__atime; + break; + default: + exit_log("invalid argument specified"); + } + } + + if ((argc \- optind) < 2) + exit_log("missing source or target mount point\en"); + + const char *source = argv[optind]; + const char *target = argv[optind + 1]; + + /* in the following, \-1 as the \(aqdirfd\(aq argument ensures that + open_tree() fails if \(aqsource\(aq is not an absolute pathname. */ +.\" christian brauner +.\" when writing programs i like to never use relative paths with at_fdcwd +.\" because. because making assumptions about the current working directory +.\" of the calling process is just too easy to get wrong; especially when +.\" pivot_root() or chroot() are in play. +.\" my absolut preference (joke intended) is to open a well-known starting +.\" point with an absolute path to get a dirfd and then scope all future +.\" operations beneath that dirfd. this already works with old-style +.\" openat() and _very_ cautious programming but openat2() and its +.\" resolve-flag space have made this **chef's kiss**. +.\" if i can't operate based on a well-known dirfd i use absolute paths +.\" with a -ebadf dirfd passed to *at() functions. + + int fd_tree = open_tree(\-1, source, + open_tree_clone | open_tree_cloexec | + at_empty_path | (recursive ? at_recursive : 0)); + if (fd_tree == \-1) + exit_log("%m \- failed to open %s\en", source); + + if (fd_userns >= 0) { + attr\->attr_set |= mount_attr_idmap; + attr\->userns_fd = fd_userns; + } + + ret = mount_setattr(fd_tree, "", + at_empty_path | (recursive ? at_recursive : 0), + attr, sizeof(struct mount_attr)); + if (ret == \-1) + exit_log("%m \- failed to change mount attributes\en"); + + close(fd_userns); + + /* in the following, \-1 as the \(aqto_dirfd\(aq argument ensures that + open_tree() fails if \(aqtarget\(aq is not an absolute pathname. */ + + ret = move_mount(fd_tree, "", \-1, target, + move_mount_f_empty_path); + if (ret == \-1) + exit_log("%m \- failed to attach mount to %s\en", target); + + close(fd_tree); + + exit(exit_success); +} +.ee +.sh see also +.br newgidmap (1), +.br newuidmap (1), +.br clone (2), +.br mount (2), +.br unshare (2), +.br proc (5), +.br capabilities (7), +.br mount_namespaces (7), +.br user_namespaces (7), +.br xattr (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man7/iso_8859-7.7 + +.so man2/setpgid.2 + +.so man3/getttyent.3 + +.\" copyright (c) 2009 linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th pthread_kill 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +pthread_kill \- send a signal to a thread +.sh synopsis +.nf +.b #include +.pp +.bi "int pthread_kill(pthread_t " thread ", int " sig ); +.fi +.pp +compile and link with \fi\-pthread\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br pthread_kill (): +.nf + _posix_c_source >= 199506l || _xopen_source >= 500 +.fi +.sh description +the +.br pthread_kill () +function sends the signal +.i sig +to +.ir thread , +a thread in the same process as the caller. +the signal is asynchronously directed to +.ir thread . +.pp +if +.i sig +is 0, then no signal is sent, but error checking is still performed. +.sh return value +on success, +.br pthread_kill () +returns 0; +on error, it returns an error number, and no signal is sent. +.sh errors +.tp +.b einval +an invalid signal was specified. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br pthread_kill () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +signal dispositions are process-wide: +if a signal handler is installed, +the handler will be invoked in the thread +.ir thread , +but if the disposition of the signal is "stop", "continue", or "terminate", +this action will affect the whole process. +.pp +the glibc implementation of +.br pthread_kill () +gives an error +.rb ( einval ) +on attempts to send either of the real-time signals +used internally by the nptl threading implementation. +see +.br nptl (7) +for details. +.pp +posix.1-2008 recommends that if an implementation detects the use +of a thread id after the end of its lifetime, +.br pthread_kill () +should return the error +.br esrch . +the glibc implementation returns this error in the cases where +an invalid thread id can be detected. +but note also that posix says that an attempt to use a thread id whose +lifetime has ended produces undefined behavior, +and an attempt to use an invalid thread id in a call to +.br pthread_kill () +can, for example, cause a segmentation fault. +.sh see also +.br kill (2), +.br sigaction (2), +.br sigpending (2), +.br pthread_self (3), +.br pthread_sigmask (3), +.br raise (3), +.br pthreads (7), +.br signal (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/unimplemented.2 + +.so man3/isalpha.3 + +.so man3/pthread_getattr_default_np.3 + +.so man3/mtrace.3 + +.so man7/system_data_types.7 + +.so man3/gethostbyname.3 + +.so man3/mq_timedsend.3 +.\" because mq_timedsend(3) is layered on a system call of the same name + +.so man3/stailq.3 + +.so man3/memchr.3 + +.so man3/strspn.3 + +.\" (c) copyright 1992-1999 rickard e. faith and david a. wheeler +.\" (faith@cs.unc.edu and dwheeler@ida.org) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified sun jul 25 11:06:05 1993 by rik faith (faith@cs.unc.edu) +.\" modified sat jun 8 00:39:52 1996 by aeb +.\" modified wed jun 16 23:00:00 1999 by david a. wheeler (dwheeler@ida.org) +.\" modified thu jul 15 12:43:28 1999 by aeb +.\" modified sun jan 6 18:26:25 2002 by martin schulze +.\" modified tue jul 27 20:12:02 2004 by colin watson +.\" 2007-05-30, mtk: various rewrites and moved much text to new man-pages.7. +.\" +.th man 7 2021-03-22 "linux" "linux programmer's manual" +.sh name +man \- macros to format man pages +.sh synopsis +.b groff \-tascii \-man +.i file +\&... +.br +.b groff \-tps \-man +.i file +\&... +.pp +.b man +.ri [ section ] +.i title +.sh description +this manual page explains the +.b "groff an.tmac" +macro package (often called the +.b man +macro package). +this macro package should be used by developers when +writing or porting man pages for linux. +it is fairly compatible with other +versions of this macro package, so porting man pages should not be a major +problem (exceptions include the net-2 bsd release, which uses a totally +different macro package called mdoc; see +.br mdoc (7)). +.pp +note that net-2 bsd mdoc man pages can be used with +.b groff +simply by specifying the +.b \-mdoc +option instead of the +.b \-man +option. +using the +.b \-mandoc +option is, however, recommended, since this will automatically detect which +macro package is in use. +.pp +for conventions that should be employed when writing man pages +for the linux \fiman-pages\fp package, see +.br man\-pages (7). +.ss title line +the first command in a man page (after comment lines, +that is, lines that start with \fb.\e"\fp) should be +.pp +.rs +.b \&.th +.i "title section date source manual" +.re +.pp +for details of the arguments that should be supplied to the +.b th +command, see +.br man\-pages (7). +.pp +note that bsd mdoc-formatted pages begin with the +.b dd +command, not the +.b th +command. +.ss sections +sections are started with +.b \&.sh +followed by the heading name. +.\" the following doesn't seem to be required (see debian bug 411303), +.\" if the name contains spaces and appears +.\" on the same line as +.\" .br \&.sh , +.\" then place the heading in double quotes. +.pp +the only mandatory heading is name, which should be the first section and +be followed on the next line by a one-line description of the program: +.pp +.rs +\&.sh name +.br +item \e- description +.re +.pp +it is extremely important that this format is followed, and that there is a +backslash before the single dash which follows the item name. +this syntax is used by the +.br mandb (8) +program to create a database of short descriptions for the +.br whatis (1) +and +.br apropos (1) +commands. +(see +.br lexgrog (1) +for further details on the syntax of the name section.) +.pp +for a list of other sections that might appear in a manual page, see +.br man\-pages (7). +.ss fonts +the commands to select the type face are: +.tp 4 +.b \&.b +bold +.tp +.b \&.bi +bold alternating with italics +(especially useful for function specifications) +.tp +.b \&.br +bold alternating with roman +(especially useful for referring to other +manual pages) +.tp +.b \&.i +italics +.tp +.b \&.ib +italics alternating with bold +.tp +.b \&.ir +italics alternating with roman +.tp +.b \&.rb +roman alternating with bold +.tp +.b \&.ri +roman alternating with italics +.tp +.b \&.sb +small alternating with bold +.tp +.b \&.sm +small (useful for acronyms) +.pp +traditionally, each command can have up to six arguments, but the gnu +implementation removes this limitation (you might still want to limit +yourself to 6 arguments for portability's sake). +arguments are delimited by spaces. +double quotes can be used to specify an argument which contains spaces. +for the macros that produce alternating type faces, +the arguments will be printed next to each other without +intervening spaces, so that the +.b \&.br +command can be used to specify a word in bold followed by a mark of +punctuation in roman. +if no arguments are given, the command is applied to the following line +of text. +.ss other macros and strings +below are other relevant macros and predefined strings. +unless noted otherwise, all macros +cause a break (end the current line of text). +many of these macros set or use the "prevailing indent". +the "prevailing indent" value is set by any macro with the parameter +.i i +below; +macros may omit +.i i +in which case the current prevailing indent will be used. +as a result, successive indented paragraphs can use the same indent without +respecifying the indent value. +a normal (nonindented) paragraph resets the prevailing indent value +to its default value (0.5 inches). +by default, a given indent is measured in ens; +try to use ens or ems as units for +indents, since these will automatically adjust to font size changes. +the other key macro definitions are: +.ss normal paragraphs +.tp 9m +.b \&.lp +same as +.b \&.pp +(begin a new paragraph). +.tp +.b \&.p +same as +.b \&.pp +(begin a new paragraph). +.tp +.b \&.pp +begin a new paragraph and reset prevailing indent. +.ss relative margin indent +.tp 9m +.bi \&.rs " i" +start relative margin indent: moves the left margin +.i i +to the right (if +.i i +is omitted, the prevailing indent value is used). +a new prevailing indent is set to 0.5 inches. +as a result, all following paragraph(s) will be +indented until the corresponding +.br \&.re . +.tp +.b \&.re +end relative margin indent and +restores the previous value of the prevailing indent. +.ss indented paragraph macros +.tp 9m +.bi \&.hp " i" +begin paragraph with a hanging indent +(the first line of the paragraph is at the left margin of +normal paragraphs, and the rest of the paragraph's lines are indented). +.tp +.bi \&.ip " x i" +indented paragraph with optional hanging tag. +if the tag +.i x +is omitted, the entire following paragraph is indented by +.ir i . +if the tag +.i x +is provided, it is hung at the left margin +before the following indented paragraph +(this is just like +.b \&.tp +except the tag is included with the command instead of being on the +following line). +if the tag is too long, the text after the tag will be moved down to the +next line (text will not be lost or garbled). +for bulleted lists, use this macro with \e(bu (bullet) or \e(em (em dash) +as the tag, and for numbered lists, use the number or letter followed by +a period as the tag; +this simplifies translation to other formats. +.tp +.bi \&.tp " i" +begin paragraph with hanging tag. +the tag is given on the next line, but +its results are like those of the +.b \&.ip +command. +.ss hypertext link macros +.tp +.bi \&.ur " url" +insert a hypertext link to the uri (url) +.ir url , +with all text up to the following +.b \&.ue +macro as the link text. +.tp +.b \&.ue \c +.ri [ trailer ] +terminate the link text of the preceding +.b \&.ur +macro, with the optional +.i trailer +(if present, usually a closing parenthesis and/or end-of-sentence +punctuation) immediately following. +for non-html output devices (e.g., +.br "man \-tutf8" ), +the link text is followed by the url in angle brackets; if there is no +link text, the url is printed as its own link text, surrounded by angle +brackets. +(angle brackets may not be available on all output devices.) +for the html output device, the link text is hyperlinked to the url; if +there is no link text, the url is printed as its own link text. +.pp +these macros have been supported since gnu troff 1.20 (2009-01-05) and +heirloom doctools troff since 160217 (2016-02-17). +.ss miscellaneous macros +.tp 9m +.b \&.dt +reset tabs to default tab values (every 0.5 inches); +does not cause a break. +.tp +.bi \&.pd " d" +set inter-paragraph vertical distance to d +(if omitted, d=0.4v); +does not cause a break. +.tp +.bi \&.ss " t" +subheading +.i t +(like +.br \&.sh , +but used for a subsection inside a section). +.ss predefined strings +the +.b man +package has the following predefined strings: +.ip \e*r +registration symbol: \*r +.ip \e*s +change to default font size +.ip \e*(tm +trademark symbol: \*(tm +.ip \e*(lq +left angled double quote: \*(lq +.ip \e*(rq +right angled double quote: \*(rq +.ss safe subset +although technically +.b man +is a troff macro package, in reality a large number of other tools +process man page files that don't implement all of troff's abilities. +thus, it's best to avoid some of troff's more exotic abilities +where possible to permit these other tools to work correctly. +avoid using the various troff preprocessors +(if you must, go ahead and use +.br tbl (1), +but try to use the +.b ip +and +.b tp +commands instead for two-column tables). +avoid using computations; most other tools can't process them. +use simple commands that are easy to translate to other formats. +the following troff macros are believed to be safe (though in many cases +they will be ignored by translators): +.br \e" , +.br . , +.br ad , +.br bp , +.br br , +.br ce , +.br de , +.br ds , +.br el , +.br ie , +.br if , +.br fi , +.br ft , +.br hy , +.br ig , +.br in , +.br na , +.br ne , +.br nf , +.br nh , +.br ps , +.br so , +.br sp , +.br ti , +.br tr . +.pp +you may also use many troff escape sequences (those sequences beginning +with \e). +when you need to include the backslash character as normal text, +use \ee. +other sequences you may use, where x or xx are any characters and n +is any digit, include: +.br \e\(aq , +.br \e\(ga , +.br \e- , +.br \e. , +.br \e" , +.br \e% , +.br \e*x , +.br \e*(xx , +.br \e(xx , +.br \e$n , +.br \enx , +.br \en(xx , +.br \efx , +and +.br \ef(xx . +avoid using the escape sequences for drawing graphics. +.pp +do not use the optional parameter for +.b bp +(break page). +use only positive values for +.b sp +(vertical space). +don't define a macro +.rb ( de ) +with the same name as a macro in this or the +mdoc macro package with a different meaning; it's likely that +such redefinitions will be ignored. +every positive indent +.rb ( in ) +should be paired with a matching negative indent +(although you should be using the +.b rs +and +.b re +macros instead). +the condition test +.rb ( if,ie ) +should only have \(aqt\(aq or \(aqn\(aq as the condition. +only translations +.rb ( tr ) +that can be ignored should be used. +font changes +.rb ( ft +and the \fb\ef\fp escape sequence) +should only have the values 1, 2, 3, 4, r, i, b, p, or cw +(the ft command may also have no parameters). +.pp +if you use capabilities beyond these, check the +results carefully on several tools. +once you've confirmed that the additional capability is safe, +let the maintainer of this +document know about the safe command or sequence +that should be added to this list. +.sh files +.ir /usr/share/groff/ [*/] tmac/an.tmac +.br +.i /usr/man/whatis +.sh notes +by all means include full urls (or uris) in the text itself; +some tools such as +.br man2html (1) +can automatically turn them into hypertext links. +you can also use the +.b ur +and +.b ue +macros to identify links to related information. +if you include urls, use the full url +(e.g., +.ur http://www.kernel.org +.ue ) +to ensure that tools can automatically find the urls. +.pp +tools processing these files should open the file and examine the first +nonwhitespace character. +a period (.) or single quote (\(aq) at the beginning +of a line indicates a troff-based file (such as man or mdoc). +a left angle bracket (<) indicates an sgml/xml-based +file (such as html or docbook). +anything else suggests simple ascii +text (e.g., a "catman" result). +.pp +many man pages begin with \fb\(aq\e"\fp followed by a +space and a list of characters, +indicating how the page is to be preprocessed. +for portability's sake to non-troff translators we recommend +that you avoid using anything other than +.br tbl (1), +and linux can detect that automatically. +however, you might want to include this information so your man page +can be handled by other (less capable) systems. +here are the definitions of the preprocessors invoked by these characters: +.tp 3 +.b e +eqn(1) +.tp +.b g +grap(1) +.tp +.b p +pic(1) +.tp +.b r +refer(1) +.tp +.b t +tbl(1) +.tp +.b v +vgrind(1) +.sh bugs +most of the macros describe formatting (e.g., font type and spacing) instead +of marking semantic content (e.g., this text is a reference to another page), +compared to formats like mdoc and docbook (even html has more semantic +markings). +this situation makes it harder to vary the +.b man +format for different media, +to make the formatting consistent for a given media, and to automatically +insert cross-references. +by sticking to the safe subset described above, it should be easier to +automate transitioning to a different reference page format in the future. +.pp +the sun macro +.b tx +is not implemented. +.\" .sh authors +.\" .ip \(em 3m +.\" james clark (jjc@jclark.com) wrote the implementation of the macro package. +.\" .ip \(em +.\" rickard e. faith (faith@cs.unc.edu) wrote the initial version of +.\" this manual page. +.\" .ip \(em +.\" jens schweikhardt (schweikh@noc.fdn.de) wrote the linux man-page mini-howto +.\" (which influenced this manual page). +.\" .ip \(em +.\" david a. wheeler (dwheeler@ida.org) heavily modified this +.\" manual page, such as adding detailed information on sections and macros. +.sh see also +.br apropos (1), +.br groff (1), +.br lexgrog (1), +.br man (1), +.br man2html (1), +.br whatis (1), +.br groff_man (7), +.br groff_www (7), +.br man\-pages (7), +.br mdoc (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de) +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" distributed under gpl +.\" %%%license_end +.\" +.\" based on the description in glibc source and infopages +.\" +.\" corrections and additions, aeb +.th envz_add 3 2021-03-22 "" "linux programmer's manual" +.sh name +envz_add, envz_entry, envz_get, envz_merge, +envz_remove, envz_strip \- environment string support +.sh synopsis +.nf +.b "#include " +.pp +.bi "error_t envz_add(char **restrict " envz ", size_t *restrict " envz_len , +.bi " const char *restrict " name \ +", const char *restrict " value ); +.pp +.bi "char *envz_entry(const char *restrict " envz ", size_t " envz_len , +.bi " const char *restrict " name ); +.pp +.bi "char *envz_get(const char *restrict " envz ", size_t " envz_len , +.bi " const char *restrict " name ); +.pp +.bi "error_t envz_merge(char **restrict " envz ", size_t *restrict " envz_len , +.bi " const char *restrict " envz2 ", size_t " envz2_len , +.bi " int " override ); +.pp +.bi "void envz_remove(char **restrict " envz ", size_t *restrict " envz_len , +.bi " const char *restrict " name ); +.pp +.bi "void envz_strip(char **restrict " envz ", size_t *restrict " envz_len ); +.fi +.sh description +these functions are glibc-specific. +.pp +an argz vector is a pointer to a character buffer together with a length, +see +.br argz_add (3). +an envz vector is a special argz vector, namely one where the strings +have the form "name=value". +everything after the first \(aq=\(aq is considered +to be the value. +if there is no \(aq=\(aq, the value is taken to be null. +(while the value in case of a trailing \(aq=\(aq is the empty string "".) +.pp +these functions are for handling envz vectors. +.pp +.br envz_add () +adds the string +.ri \&" name = value \&" +(in case +.i value +is non-null) or +.ri \&" name \&" +(in case +.i value +is null) to the envz vector +.ri ( *envz ,\ *envz_len ) +and updates +.i *envz +and +.ir *envz_len . +if an entry with the same +.i name +existed, it is removed. +.pp +.br envz_entry () +looks for +.i name +in the envz vector +.ri ( envz ,\ envz_len ) +and returns the entry if found, or null if not. +.pp +.br envz_get () +looks for +.i name +in the envz vector +.ri ( envz ,\ envz_len ) +and returns the value if found, or null if not. +(note that the value can also be null, namely when there is +an entry for +.i name +without \(aq=\(aq sign.) +.pp +.br envz_merge () +adds each entry in +.i envz2 +to +.ir *envz , +as if with +.br envz_add (). +if +.i override +is true, then values in +.i envz2 +will supersede those with the same name in +.ir *envz , +otherwise not. +.pp +.br envz_remove () +removes the entry for +.i name +from +.ri ( *envz ,\ *envz_len ) +if there was one. +.pp +.br envz_strip () +removes all entries with value null. +.sh return value +all envz functions that do memory allocation have a return type of +.ir error_t +(an integer type), +and return 0 for success, and +.b enomem +if an allocation error occurs. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br envz_add (), +.br envz_entry (), +.br envz_get (), +.br envz_merge (), +.br envz_remove (), +.br envz_strip () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +these functions are a gnu extension. +.sh examples +.ex +#include +#include +#include + +int +main(int argc, char *argv[], char *envp[]) +{ + int e_len = 0; + char *str; + + for (int i = 0; envp[i] != null; i++) + e_len += strlen(envp[i]) + 1; + + str = envz_entry(*envp, e_len, "home"); + printf("%s\en", str); + str = envz_get(*envp, e_len, "home"); + printf("%s\en", str); + exit(exit_success); +} +.ee +.sh see also +.br argz_add (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2007 by michael kerrisk +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" 2007-07-31, mtk, created +.\" +.th timeradd 3 2021-03-22 "linux" "linux programmer's manual" +.sh name +timeradd, timersub, timercmp, timerclear, timerisset \- timeval operations +.sh synopsis +.nf +.b #include +.pp +.bi "void timeradd(struct timeval *" a ", struct timeval *" b , +.bi " struct timeval *" res ); +.bi "void timersub(struct timeval *" a ", struct timeval *" b , +.bi " struct timeval *" res ); +.pp +.bi "void timerclear(struct timeval *" tvp ); +.bi "int timerisset(struct timeval *" tvp ); +.pp +.bi "int timercmp(struct timeval *" a ", struct timeval *" b ", " cmp ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +all functions shown above: +.nf + since glibc 2.19: + _default_source + glibc 2.19 and earlier: + _bsd_source +.fi +.sh description +the macros are provided to operate on +.i timeval +structures, defined in +.i +as: +.pp +.in +4n +.ex +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* microseconds */ +}; +.ee +.in +.pp +.br timeradd () +adds the time values in +.i a +and +.ir b , +and places the sum in the +.i timeval +pointed to by +.ir res . +the result is normalized such that +.i res\->tv_usec +has a value in the range 0 to 999,999. +.pp +.br timersub () +subtracts the time value in +.i b +from the time value in +.ir a , +and places the result in the +.i timeval +pointed to by +.ir res . +the result is normalized such that +.i res\->tv_usec +has a value in the range 0 to 999,999. +.pp +.br timerclear () +zeros out the +.i timeval +structure pointed to by +.ir tvp , +so that it represents the epoch: 1970-01-01 00:00:00 +0000 (utc). +.pp +.br timerisset () +returns true (nonzero) if either field of the +.i timeval +structure pointed to by +.i tvp +contains a nonzero value. +.pp +.br timercmp () +compares the timer values in +.i a +and +.i b +using the comparison operator +.ir cmp , +and returns true (nonzero) or false (0) depending on +the result of the comparison. +some systems (but not linux/glibc), +have a broken +.br timercmp () +implementation, +.\" hp-ux, tru64, irix have a definition like: +.\"#define timercmp(tvp, uvp, cmp) \ +.\" ((tvp)->tv_sec cmp (uvp)->tv_sec || \ +.\" (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) +in which +.i cmp +of +.ir >= , +.ir <= , +and +.i == +do not work; +portable applications can instead use +.pp + !timercmp(..., <) + !timercmp(..., >) + !timercmp(..., !=) +.sh return value +.br timerisset () +and +.br timercmp () +return true (nonzero) or false (0). +.sh errors +no errors are defined. +.sh conforming to +not in posix.1. +present on most bsd derivatives. +.sh see also +.br gettimeofday (2), +.br time (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 1995 jim van zandt +.\" and copyright 2008, linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified 2002-07-27 walter harms +.\" (walter.harms@informatik.uni-oldenburg.de) +.\" +.th expm1 3 2021-03-22 "" "linux programmer's manual" +.sh name +expm1, expm1f, expm1l \- exponential minus 1 +.sh synopsis +.nf +.b #include +.pp +.bi "double expm1(double " x ); +.bi "float expm1f(float " x ); +.bi "long double expm1l(long double " x ); +.pp +.fi +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br expm1 (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.pp +.br expm1f (), +.br expm1l (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +these functions return a value equivalent to +.pp +.nf + exp(x) \- 1 +.fi +.pp +the result is computed in a way that is accurate even if the value of +.i x +is near +zero\(ema case where +.i "exp(x) \- 1" +would be inaccurate due to +subtraction of two numbers that are nearly equal. +.sh return value +on success, these functions return +.ir "exp(x)\ \-\ 1" . +.pp +if +.i x +is a nan, +a nan is returned. +.pp +if +.i x +is +0 (\-0), ++0 (\-0) is returned. +.pp +if +.i x +is positive infinity, positive infinity is returned. +.pp +if +.i x +is negative infinity, \-1 is returned. +.pp +if the result overflows, a range error occurs, +and the functions return +.rb \- huge_val , +.rb \- huge_valf , +or +.rb \- huge_vall , +respectively. +.sh errors +see +.br math_error (7) +for information on how to determine whether an error has occurred +when calling these functions. +.pp +the following errors can occur: +.tp +range error, overflow +.i errno +is set to +.br erange +(but see bugs). +an overflow floating-point exception +.rb ( fe_overflow ) +is raised. +.\" +.\" posix.1 specifies an optional range error (underflow) if +.\" x is subnormal. glibc does not implement this. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br expm1 (), +.br expm1f (), +.br expm1l () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +c99, posix.1-2001, posix.1-2008. +.\" bsd. +.sh bugs +before glibc 2.17, +.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6778 +on certain architectures (e.g., x86, but not x86_64) +.br expm1 () +raised a bogus underflow floating-point exception +for some large negative +.i x +values (where the function result approaches \-1). +.pp +before approximately glibc version 2.11, +.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6814 +.\" e.g., expm1(1e5) through expm1(1.00199970127e5), +.\" but not expm1(1.00199970128e5) and beyond. +.br expm1 () +raised a bogus invalid floating-point exception in addition to the expected +overflow exception, and returned a nan instead of positive infinity, +for some large positive +.i x +values. +.pp +before version 2.11, +.\" it looks like the fix was in 2.11, or possibly 2.12. +.\" i have no test system for 2.11, but 2.12 passes. +.\" from the source (sysdeps/i386/fpu/s_expm1.s) it looks +.\" like the changes were in 2.11. +the glibc implementation did not set +.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6788 +.i errno +to +.b erange +when a range error occurred. +.sh see also +.br exp (3), +.br log (3), +.br log1p (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/mkstemp.3 + +.so man3/lrint.3 + +.so man3/expm1.3 + +.so man3/rpc.3 + +.\" copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de) +.\" and copyright 2008, linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(gpl_noversion_oneline) +.\" distributed under gpl +.\" %%%license_end +.\" +.\" based on glibc infopages +.\" +.th lgamma 3 2021-03-22 "" "linux programmer's manual" +.sh name +lgamma, lgammaf, lgammal, lgamma_r, lgammaf_r, lgammal_r, signgam \- +log gamma function +.sh synopsis +.nf +.b #include +.pp +.bi "double lgamma(double " x ); +.bi "float lgammaf(float " x ); +.bi "long double lgammal(long double " x ); +.pp +.bi "double lgamma_r(double " x ", int *" signp ); +.bi "float lgammaf_r(float " x ", int *" signp ); +.bi "long double lgammal_r(long double " x ", int *" signp ); +.pp +.bi "extern int " signgam ; +.fi +.pp +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.nf +.br lgamma (): + _isoc99_source || _posix_c_source >= 200112l || _xopen_source + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.pp +.br lgammaf (), +.br lgammal (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.pp +.br lgamma_r (), +.br lgammaf_r (), +.br lgammal_r (): +.nf + /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.pp +.ir signgam : +.nf + _xopen_source + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +for the definition of the gamma function, see +.br tgamma (3). +.pp +the +.br lgamma (), +.br lgammaf (), +and +.br lgammal () +functions return the natural logarithm of +the absolute value of the gamma function. +the sign of the gamma function is returned in the +external integer +.i signgam +declared in +.ir . +it is 1 when the gamma function is positive or zero, \-1 +when it is negative. +.pp +since using a constant location +.i signgam +is not thread-safe, the functions +.br lgamma_r (), +.br lgammaf_r (), +and +.br lgammal_r () +have been introduced; they return the sign via the argument +.ir signp . +.sh return value +on success, these functions return the natural logarithm of gamma(x). +.pp +if +.i x +is a nan, a nan is returned. +.pp +if +.i x +is 1 or 2, +0 is returned. +.pp +if +.i x +is positive infinity or negative infinity, +positive infinity is returned. +.pp +if +.i x +is a nonpositive integer, +a pole error occurs, +and the functions return +.rb + huge_val , +.rb + huge_valf , +or +.rb + huge_vall , +respectively. +.pp +if the result overflows, +a range error occurs, +.\" e.g., lgamma(dbl_max) +and the functions return +.br huge_val , +.br huge_valf , +or +.br huge_vall , +respectively, with the correct mathematical sign. +.sh errors +see +.br math_error (7) +for information on how to determine whether an error has occurred +when calling these functions. +.pp +the following errors can occur: +.tp +pole error: \fix\fp is a nonpositive integer +.i errno +is set to +.br erange +(but see bugs). +a divide-by-zero floating-point exception +.rb ( fe_divbyzero ) +is raised. +.tp +range error: result overflow +.i errno +is set to +.br erange . +an overflow floating-point exception +.rb ( fe_overflow ) +is raised. +.\" glibc (as at 2.8) also supports an inexact +.\" exception for various cases. +.sh conforming to +the +.br lgamma () +functions are specified in c99, posix.1-2001, and posix.1-2008. +.i signgam +is specified in posix.1-2001 and posix.1-2008, but not in c99. +the +.br lgamma_r () +functions are nonstandard, but present on several other systems. +.sh bugs +in glibc 2.9 and earlier, +.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6777 +when a pole error occurs, +.i errno +is set to +.br edom ; +instead of the posix-mandated +.br erange . +since version 2.10, glibc does the right thing. +.sh see also +.br tgamma (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" this manpage is copyright (c) 2006 silicon graphics, inc. +.\" christoph lameter +.\" +.\" %%%license_start(verbatim_two_para) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" %%%license_end +.\" +.\" fixme should programs normally be using move_pages() directly, or should +.\" they rather be using interfaces in the numactl package? +.\" (e.g., compare with recommendation in mbind(2)). +.\" does this page need to give advice on this topic? +.\" +.th move_pages 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +move_pages \- move individual pages of a process to another node +.sh synopsis +.nf +.b #include +.pp +.bi "long move_pages(int " pid ", unsigned long " count ", void **" pages , +.bi " const int *" nodes ", int *" status ", int " flags ); +.fi +.pp +link with \fi\-lnuma\fp. +.pp +.ir note : +there is no glibc wrapper for this system call; see notes. +.sh description +.br move_pages () +moves the specified +.i pages +of the process +.i pid +to the memory nodes specified by +.ir nodes . +the result of the move is reflected in +.ir status . +the +.i flags +indicate constraints on the pages to be moved. +.pp +.i pid +is the id of the process in which pages are to be moved. +if +.i pid +is 0, then +.br move_pages () +moves pages of the calling process. +.pp +to move pages in another process requires the following privileges: +.ip * 3 +in kernels up to and including linux 4.12: +the caller must be privileged +.rb ( cap_sys_nice ) +or the real or effective user id of the calling process must match the +real or saved-set user id of the target process. +.ip * +the older rules allowed the caller to discover various +virtual address choices made by the kernel that could lead +to the defeat of address-space-layout randomization +for a process owned by the same uid as the caller, +the rules were changed starting with linux 4.13. +since linux 4.13, +.\" commit 197e7e521384a23b9e585178f3f11c9fa08274b9 +permission is governed by a ptrace access mode +.b ptrace_mode_read_realcreds +check with respect to the target process; see +.br ptrace (2). +.pp +.i count +is the number of pages to move. +it defines the size of the three arrays +.ir pages , +.ir nodes , +and +.ir status . +.pp +.i pages +is an array of pointers to the pages that should be moved. +these are pointers that should be aligned to page boundaries. +.\" fixme describe the result if pointers in the 'pages' array are +.\" not aligned to page boundaries +addresses are specified as seen by the process specified by +.ir pid . +.pp +.i nodes +is an array of integers that specify the desired location for each page. +each element in the array is a node number. +.i nodes +can also be null, in which case +.br move_pages () +does not move any pages but instead will return the node +where each page currently resides, in the +.i status +array. +obtaining the status of each page may be necessary to determine +pages that need to be moved. +.pp +.i status +is an array of integers that return the status of each page. +the array contains valid values only if +.br move_pages () +did not return an error. +preinitialization of the array to a value +which cannot represent a real numa node or valid error of status array +could help to identify pages that have been migrated. +.pp +.i flags +specify what types of pages to move. +.b mpol_mf_move +means that only pages that are in exclusive use by the process +are to be moved. +.b mpol_mf_move_all +means that pages shared between multiple processes can also be moved. +the process must be privileged +.rb ( cap_sys_nice ) +to use +.br mpol_mf_move_all . +.ss page states in the status array +the following values can be returned in each element of the +.i status +array. +.tp +.b 0..max_numnodes +identifies the node on which the page resides. +.tp +.b \-eacces +the page is mapped by multiple processes and can be moved only if +.b mpol_mf_move_all +is specified. +.tp +.b \-ebusy +the page is currently busy and cannot be moved. +try again later. +this occurs if a page is undergoing i/o or another kernel subsystem +is holding a reference to the page. +.tp +.b \-efault +this is a zero page or the memory area is not mapped by the process. +.tp +.b \-eio +unable to write back a page. +the page has to be written back +in order to move it since the page is dirty and the filesystem +does not provide a migration function that would allow the move +of dirty pages. +.tp +.b \-einval +a dirty page cannot be moved. +the filesystem does not +provide a migration function and has no ability to write back pages. +.tp +.b \-enoent +the page is not present. +.tp +.b \-enomem +unable to allocate memory on target node. +.sh return value +on success +.br move_pages () +returns zero. +.\" fixme . is the following quite true: does the wrapper in numactl +.\" do the right thing? +on error, it returns \-1, and sets +.i errno +to indicate the error. +if positive value is returned, it is the number of +nonmigrated pages. +.sh errors +.tp +.b positive value +the number of nonmigrated pages if they were the result of nonfatal +reasons (since +.\" commit a49bd4d7163707de377aee062f17befef6da891b +linux 4.17). +.tp +.b e2big +too many pages to move. +since linux 2.6.29, +.\" commit 3140a2273009c01c27d316f35ab76a37e105fdd8 +the kernel no longer generates this error. +.tp +.b eacces +.\" fixme clarify "current cpuset" in the description of the eacces error. +.\" is that the cpuset of the caller or the target? +one of the target nodes is not allowed by the current cpuset. +.tp +.b efault +parameter array could not be accessed. +.tp +.b einval +flags other than +.b mpol_mf_move +and +.b mpol_mf_move_all +was specified or an attempt was made to migrate pages of a kernel thread. +.tp +.b enodev +one of the target nodes is not online. +.tp +.b eperm +the caller specified +.b mpol_mf_move_all +without sufficient privileges +.rb ( cap_sys_nice ). +or, the caller attempted to move pages of a process belonging +to another user but did not have privilege to do so +.rb ( cap_sys_nice ). +.tp +.b esrch +process does not exist. +.sh versions +.br move_pages () +first appeared on linux in version 2.6.18. +.sh conforming to +this system call is linux-specific. +.sh notes +glibc does not provide a wrapper for this system call. +for information on library support, see +.br numa (7). +.pp +use +.br get_mempolicy (2) +with the +.b mpol_f_mems_allowed +flag to obtain the set of nodes that are allowed by +.\" fixme clarify "current cpuset". is that the cpuset of the caller +.\" or the target? +the current cpuset. +note that this information is subject to change at any +time by manual or automatic reconfiguration of the cpuset. +.pp +use of this function may result in pages whose location +(node) violates the memory policy established for the +specified addresses (see +.br mbind (2)) +and/or the specified process (see +.br set_mempolicy (2)). +that is, memory policy does not constrain the destination +nodes used by +.br move_pages (). +.pp +the +.i +header is not included with glibc, but requires installing +.i libnuma\-devel +or a similar package. +.sh see also +.br get_mempolicy (2), +.br mbind (2), +.br set_mempolicy (2), +.br numa (3), +.br numa_maps (5), +.br cpuset (7), +.br numa (7), +.br migratepages (8), +.br numastat (8) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man2/unimplemented.2 + +.\" copyright (c) 2002 andries brouwer +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" this replaces an earlier man page written by walter harms +.\" . +.\" +.\" corrected return types; from fabian; 2004-10-05 +.\" +.th ecvt_r 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +ecvt_r, fcvt_r, qecvt_r, qfcvt_r \- convert a floating-point number to a string +.sh synopsis +.nf +.b #include +.pp +.bi "int ecvt_r(double " number ", int " ndigits ", int *restrict " decpt , +.bi " int *restrict " sign ", char *restrict " buf ", size_t " len ); +.bi "int fcvt_r(double " number ", int " ndigits ", int *restrict " decpt , +.bi " int *restrict " sign ", char *restrict " buf ", size_t " len ); +.pp +.bi "int qecvt_r(long double " number ", int " ndigits \ +", int *restrict " decpt , +.bi " int *restrict " sign ", char *restrict " buf ", size_t " len ); +.bi "int qfcvt_r(long double " number ", int " ndigits \ +", int *restrict " decpt , +.bi " int *restrict " sign ", char *restrict " buf ", size_t " len ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br ecvt_r (), +.br fcvt_r (), +.br qecvt_r (), +.br qfcvt_r (): +.nf + /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _svid_source || _bsd_source +.fi +.sh description +the functions +.br ecvt_r (), +.br fcvt_r (), +.br qecvt_r (), +and +.br qfcvt_r () +are identical to +.br ecvt (3), +.br fcvt (3), +.br qecvt (3), +and +.br qfcvt (3), +respectively, except that they do not return their result in a static +buffer, but instead use the supplied +.i buf +of size +.ir len . +see +.br ecvt (3) +and +.br qecvt (3). +.sh return value +these functions return 0 on success, and \-1 otherwise. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br ecvt_r (), +.br fcvt_r (), +.br qecvt_r (), +.br qfcvt_r () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +these functions are gnu extensions. +.sh notes +these functions are obsolete. +instead, +.br sprintf (3) +is recommended. +.sh see also +.br ecvt (3), +.br qecvt (3), +.br sprintf (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/rpc.3 + +.\" copyright (c) 2013, peter schiffer (pschiffe@redhat.com) +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.th mtrace 1 2021-03-22 "gnu" "linux user manual" +.sh name +mtrace \- interpret the malloc trace log +.sh synopsis +.nf +.br mtrace " [\fioption\fr]... [\fibinary\fr] \fimtracedata\fr" +.fi +.sh description +.b mtrace +is a perl script used to interpret and provide human readable output +of the trace log contained in the file +.ir mtracedata , +whose contents were produced by +.br mtrace (3). +if +.i binary +is provided, the output of +.b mtrace +also contains the source file name with line number information +for problem locations +(assuming that +.i binary +was compiled with debugging information). +.pp +for more information about the +.br mtrace (3) +function and +.b mtrace +script usage, see +.br mtrace (3). +.sh options +.tp +.bi \fb\-\-help +print help and exit. +.tp +.bi \fb\-\-version +print version information and exit. +.sh bugs +for bug reporting instructions, please see: +.ur http://www.gnu.org/software/libc/bugs.html +.ue . +.sh see also +.br memusage (1), +.br mtrace (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/qecvt.3 + +.so man3/tailq.3 + +.so man3/cacosh.3 + +.\" copyright (c) 2014 michael kerrisk +.\" and copyright (c) 2014 david herrmann +.\" +.\" %%%license_start(gplv2+) +.\" +.\" this program is free software; you can redistribute it and/or modify +.\" it under the terms of the gnu general public license as published by +.\" the free software foundation; either version 2 of the license, or +.\" (at your option) any later version. +.\" +.\" this program is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.th memfd_create 2 2021-03-22 linux "linux programmer's manual" +.sh name +memfd_create \- create an anonymous file +.sh synopsis +.nf +.br "#define _gnu_source" " /* see feature_test_macros(7) */" +.b #include +.pp +.bi "int memfd_create(const char *" name ", unsigned int " flags ");" +.fi +.sh description +.br memfd_create () +creates an anonymous file and returns a file descriptor that refers to it. +the file behaves like a regular file, and so can be modified, +truncated, memory-mapped, and so on. +however, unlike a regular file, +it lives in ram and has a volatile backing storage. +once all references to the file are dropped, it is automatically released. +anonymous memory is used for all backing pages of the file. +therefore, files created by +.br memfd_create () +have the same semantics as other anonymous +.\" david herrmann: +.\" memfd uses vm_noreserve so each page is accounted on first access. +.\" this means, the overcommit-limits (see __vm_enough_memory()) and the +.\" memory-cgroup limits (mem_cgroup_try_charge()) are applied. note that +.\" those are accounted on "current" and "current->mm", that is, the +.\" process doing the first page access. +memory allocations such as those allocated using +.br mmap (2) +with the +.br map_anonymous +flag. +.pp +the initial size of the file is set to 0. +following the call, the file size should be set using +.br ftruncate (2). +(alternatively, the file may be populated by calls to +.br write (2) +or similar.) +.pp +the name supplied in +.i name +is used as a filename and will be displayed +as the target of the corresponding symbolic link in the directory +.ir /proc/self/fd/ . +the displayed name is always prefixed with +.ir memfd: +and serves only for debugging purposes. +names do not affect the behavior of the file descriptor, +and as such multiple files can have the same name without any side effects. +.pp +the following values may be bitwise ored in +.ir flags +to change the behavior of +.br memfd_create (): +.tp +.br mfd_cloexec +set the close-on-exec +.rb ( fd_cloexec ) +flag on the new file descriptor. +see the description of the +.b o_cloexec +flag in +.br open (2) +for reasons why this may be useful. +.tp +.br mfd_allow_sealing +allow sealing operations on this file. +see the discussion of the +.b f_add_seals +and +.br f_get_seals +operations in +.br fcntl (2), +and also notes, below. +the initial set of seals is empty. +if this flag is not set, the initial set of seals will be +.br f_seal_seal , +meaning that no other seals can be set on the file. +.\" fixme why is the mfd_allow_sealing behavior not simply the default? +.\" is it worth adding some text explaining this? +.tp +.br mfd_hugetlb " (since linux 4.14)" +.\" commit 749df87bd7bee5a79cef073f5d032ddb2b211de8 +the anonymous file will be created in the hugetlbfs filesystem using +huge pages. +see the linux kernel source file +.i documentation/admin\-guide/mm/hugetlbpage.rst +for more information about hugetlbfs. +.\" commit 47b9012ecdc747f6936395265e677d41e11a31ff +specifying both +.b mfd_hugetlb +and +.b mfd_allow_sealing +in +.i flags +is supported since linux 4.16. +.tp +.br mfd_huge_2mb ", " mfd_huge_1gb ", " "..." +used in conjunction with +.b mfd_hugetlb +to select alternative hugetlb page sizes (respectively, 2\ mb, 1\ gb, ...) +on systems that support multiple hugetlb page sizes. +definitions for known +huge page sizes are included in the header file +.i . +.ip +for details on encoding huge page sizes not included in the header file, +see the discussion of the similarly named constants in +.br mmap (2). +.pp +unused bits in +.i flags +must be 0. +.pp +as its return value, +.br memfd_create () +returns a new file descriptor that can be used to refer to the file. +this file descriptor is opened for both reading and writing +.rb ( o_rdwr ) +and +.b o_largefile +is set for the file descriptor. +.pp +with respect to +.br fork (2) +and +.br execve (2), +the usual semantics apply for the file descriptor created by +.br memfd_create (). +a copy of the file descriptor is inherited by the child produced by +.br fork (2) +and refers to the same file. +the file descriptor is preserved across +.br execve (2), +unless the close-on-exec flag has been set. +.sh return value +on success, +.br memfd_create () +returns a new file descriptor. +on error, \-1 is returned and +.i errno +is set to indicate the error. +.sh errors +.tp +.b efault +the address in +.ir name +points to invalid memory. +.tp +.b einval +.i flags +included unknown bits. +.tp +.b einval +.i name +was too long. +(the limit is +.\" name_max - strlen("memfd:") +249 bytes, excluding the terminating null byte.) +.tp +.b einval +both +.b mfd_hugetlb +and +.b mfd_allow_sealing +were specified in +.ir flags . +.tp +.b emfile +the per-process limit on the number of open file descriptors has been reached. +.tp +.b enfile +the system-wide limit on the total number of open files has been reached. +.tp +.b enomem +there was insufficient memory to create a new anonymous file. +.sh versions +the +.br memfd_create () +system call first appeared in linux 3.17; +glibc support was added in version 2.27. +.tp +.b eperm +the +.b mfd_hugetlb +flag was specified, but the caller was not privileged (did not have the +.b cap_ipc_lock +capability) +and is not a member of the +.i sysctl_hugetlb_shm_group +group; see the description of +.i /proc/sys/vm/sysctl_hugetlb_shm_group +in +.br proc (5). +.sh conforming to +the +.br memfd_create () +system call is linux-specific. +.sh notes +.\" see also http://lwn.net/articles/593918/ +.\" and http://lwn.net/articles/594919/ and http://lwn.net/articles/591108/ +the +.br memfd_create () +system call provides a simple alternative to manually mounting a +.br tmpfs (5) +filesystem and creating and opening a file in that filesystem. +the primary purpose of +.br memfd_create () +is to create files and associated file descriptors that are +used with the file-sealing apis provided by +.br fcntl (2). +.pp +the +.br memfd_create () +system call also has uses without file sealing +(which is why file-sealing is disabled, unless explicitly requested with the +.br mfd_allow_sealing +flag). +in particular, it can be used as an alternative to creating files in +.ir tmp +or as an alternative to using the +.br open (2) +.b o_tmpfile +in cases where there is no intention to actually link the +resulting file into the filesystem. +.ss file sealing +in the absence of file sealing, +processes that communicate via shared memory must either trust each other, +or take measures to deal with the possibility that an untrusted peer +may manipulate the shared memory region in problematic ways. +for example, an untrusted peer might modify the contents of the +shared memory at any time, or shrink the shared memory region. +the former possibility leaves the local process vulnerable to +time-of-check-to-time-of-use race conditions +(typically dealt with by copying data from +the shared memory region before checking and using it). +the latter possibility leaves the local process vulnerable to +.br sigbus +signals when an attempt is made to access a now-nonexistent +location in the shared memory region. +(dealing with this possibility necessitates the use of a handler for the +.br sigbus +signal.) +.pp +dealing with untrusted peers imposes extra complexity on +code that employs shared memory. +memory sealing enables that extra complexity to be eliminated, +by allowing a process to operate secure in the knowledge that +its peer can't modify the shared memory in an undesired fashion. +.pp +an example of the usage of the sealing mechanism is as follows: +.ip 1. 3 +the first process creates a +.br tmpfs (5) +file using +.br memfd_create (). +the call yields a file descriptor used in subsequent steps. +.ip 2. +the first process +sizes the file created in the previous step using +.br ftruncate (2), +maps it using +.br mmap (2), +and populates the shared memory with the desired data. +.ip 3. +the first process uses the +.br fcntl (2) +.b f_add_seals +operation to place one or more seals on the file, +in order to restrict further modifications on the file. +(if placing the seal +.br f_seal_write , +then it will be necessary to first unmap the shared writable mapping +created in the previous step. +otherwise, behavior similar to +.br f_seal_write +can be achieved by using +.br f_seal_future_write , +which will prevent future writes via +.br mmap (2) +and +.br write (2) +from succeeding while keeping existing shared writable mappings). +.ip 4. +a second process obtains a file descriptor for the +.br tmpfs (5) +file and maps it. +among the possible ways in which this could happen are the following: +.rs +.ip * 3 +the process that called +.br memfd_create () +could transfer the resulting file descriptor to the second process +via a unix domain socket (see +.br unix (7) +and +.br cmsg (3)). +the second process then maps the file using +.br mmap (2). +.ip * +the second process is created via +.br fork (2) +and thus automatically inherits the file descriptor and mapping. +(note that in this case and the next, +there is a natural trust relationship between the two processes, +since they are running under the same user id. +therefore, file sealing would not normally be necessary.) +.ip * +the second process opens the file +.ir /proc//fd/ , +where +.i +is the pid of the first process (the one that called +.br memfd_create ()), +and +.i +is the number of the file descriptor returned by the call to +.br memfd_create () +in that process. +the second process then maps the file using +.br mmap (2). +.re +.ip 5. +the second process uses the +.br fcntl (2) +.b f_get_seals +operation to retrieve the bit mask of seals +that has been applied to the file. +this bit mask can be inspected in order to determine +what kinds of restrictions have been placed on file modifications. +if desired, the second process can apply further seals +to impose additional restrictions (so long as the +.br f_seal_seal +seal has not yet been applied). +.sh examples +below are shown two example programs that demonstrate the use of +.br memfd_create () +and the file sealing api. +.pp +the first program, +.ir t_memfd_create.c , +creates a +.br tmpfs (5) +file using +.br memfd_create (), +sets a size for the file, maps it into memory, +and optionally places some seals on the file. +the program accepts up to three command-line arguments, +of which the first two are required. +the first argument is the name to associate with the file, +the second argument is the size to be set for the file, +and the optional third argument is a string of characters that specify +seals to be set on file. +.pp +the second program, +.ir t_get_seals.c , +can be used to open an existing file that was created via +.br memfd_create () +and inspect the set of seals that have been applied to that file. +.pp +the following shell session demonstrates the use of these programs. +first we create a +.br tmpfs (5) +file and set some seals on it: +.pp +.in +4n +.ex +$ \fb./t_memfd_create my_memfd_file 4096 sw &\fp +[1] 11775 +pid: 11775; fd: 3; /proc/11775/fd/3 +.ee +.in +.pp +at this point, the +.i t_memfd_create +program continues to run in the background. +from another program, we can obtain a file descriptor for the +file created by +.br memfd_create () +by opening the +.ir /proc/[pid]/fd +file that corresponds to the file descriptor opened by +.br memfd_create (). +using that pathname, we inspect the content of the +.ir /proc/[pid]/fd +symbolic link, and use our +.i t_get_seals +program to view the seals that have been placed on the file: +.pp +.in +4n +.ex +$ \fbreadlink /proc/11775/fd/3\fp +/memfd:my_memfd_file (deleted) +$ \fb./t_get_seals /proc/11775/fd/3\fp +existing seals: write shrink +.ee +.in +.ss program source: t_memfd_create.c +\& +.ex +#define _gnu_source +#include +#include +#include +#include +#include +#include +#include + +#define errexit(msg) do { perror(msg); exit(exit_failure); \e + } while (0) + +int +main(int argc, char *argv[]) +{ + int fd; + unsigned int seals; + char *addr; + char *name, *seals_arg; + ssize_t len; + + if (argc < 3) { + fprintf(stderr, "%s name size [seals]\en", argv[0]); + fprintf(stderr, "\et\(aqseals\(aq can contain any of the " + "following characters:\en"); + fprintf(stderr, "\et\etg \- f_seal_grow\en"); + fprintf(stderr, "\et\ets \- f_seal_shrink\en"); + fprintf(stderr, "\et\etw \- f_seal_write\en"); + fprintf(stderr, "\et\etw \- f_seal_future_write\en"); + fprintf(stderr, "\et\ets \- f_seal_seal\en"); + exit(exit_failure); + } + + name = argv[1]; + len = atoi(argv[2]); + seals_arg = argv[3]; + + /* create an anonymous file in tmpfs; allow seals to be + placed on the file. */ + + fd = memfd_create(name, mfd_allow_sealing); + if (fd == \-1) + errexit("memfd_create"); + + /* size the file as specified on the command line. */ + + if (ftruncate(fd, len) == \-1) + errexit("truncate"); + + printf("pid: %jd; fd: %d; /proc/%jd/fd/%d\en", + (intmax_t) getpid(), fd, (intmax_t) getpid(), fd); + + /* code to map the file and populate the mapping with data + omitted. */ + + /* if a \(aqseals\(aq command\-line argument was supplied, set some + seals on the file. */ + + if (seals_arg != null) { + seals = 0; + + if (strchr(seals_arg, \(aqg\(aq) != null) + seals |= f_seal_grow; + if (strchr(seals_arg, \(aqs\(aq) != null) + seals |= f_seal_shrink; + if (strchr(seals_arg, \(aqw\(aq) != null) + seals |= f_seal_write; + if (strchr(seals_arg, \(aqw\(aq) != null) + seals |= f_seal_future_write; + if (strchr(seals_arg, \(aqs\(aq) != null) + seals |= f_seal_seal; + + if (fcntl(fd, f_add_seals, seals) == \-1) + errexit("fcntl"); + } + + /* keep running, so that the file created by memfd_create() + continues to exist. */ + + pause(); + + exit(exit_success); +} +.ee +.ss program source: t_get_seals.c +\& +.ex +#define _gnu_source +#include +#include +#include +#include +#include +#include + +#define errexit(msg) do { perror(msg); exit(exit_failure); \e + } while (0) + +int +main(int argc, char *argv[]) +{ + int fd; + unsigned int seals; + + if (argc != 2) { + fprintf(stderr, "%s /proc/pid/fd/fd\en", argv[0]); + exit(exit_failure); + } + + fd = open(argv[1], o_rdwr); + if (fd == \-1) + errexit("open"); + + seals = fcntl(fd, f_get_seals); + if (seals == \-1) + errexit("fcntl"); + + printf("existing seals:"); + if (seals & f_seal_seal) + printf(" seal"); + if (seals & f_seal_grow) + printf(" grow"); + if (seals & f_seal_write) + printf(" write"); + if (seals & f_seal_future_write) + printf(" future_write"); + if (seals & f_seal_shrink) + printf(" shrink"); + printf("\en"); + + /* code to map the file and access the contents of the + resulting mapping omitted. */ + + exit(exit_success); +} +.ee +.sh see also +.br fcntl (2), +.br ftruncate (2), +.br mmap (2), +.br shmget (2), +.br shm_open (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright (c) 2010, michael kerrisk +.\" +.\" %%%license_start(gplv2+_doc_full) +.\" this is free documentation; you can redistribute it and/or +.\" modify it under the terms of the gnu general public license as +.\" published by the free software foundation; either version 2 of +.\" the license, or (at your option) any later version. +.\" +.\" the gnu general public license's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" this manual is distributed in the hope that it will be useful, +.\" but without any warranty; without even the implied warranty of +.\" merchantability or fitness for a particular purpose. see the +.\" gnu general public license for more details. +.\" +.\" you should have received a copy of the gnu general public +.\" license along with this manual; if not, see +.\" . +.\" %%%license_end +.\" +.th lio_listio 3 2021-03-22 "" "linux programmer's manual" +.sh name +lio_listio \- initiate a list of i/o requests +.sh synopsis +.nf +.b "#include " +.pp +.bi "int lio_listio(int " mode ", struct aiocb *restrict const " aiocb_list [restrict], +.bi " int " nitems ", struct sigevent *restrict " sevp ); +.pp +link with \fi\-lrt\fp. +.fi +.sh description +the +.br lio_listio () +function initiates the list of i/o operations described by the array +.ir aiocb_list . +.pp +the +.i mode +operation has one of the following values: +.tp +.b lio_wait +the call blocks until all operations are complete. +the +.i sevp +argument is ignored. +.tp +.b lio_nowait +the i/o operations are queued for processing and the call returns immediately. +when all of the i/o operations complete, asynchronous notification occurs, +as specified by the +.ir sevp +argument; see +.br sigevent (7) +for details. +if +.ir sevp +is null, no asynchronous notification occurs. +.pp +the +.i aiocb_list +argument is an array of pointers to +.i aiocb +structures that describe i/o operations. +these operations are executed in an unspecified order. +the +.i nitems +argument specifies the size of the array +.ir aiocb_list . +null pointers in +.i aiocb_list +are ignored. +.pp +in each control block in +.ir aiocb_list , +the +.i aio_lio_opcode +field specifies the i/o operation to be initiated, as follows: +.tp +.br lio_read +initiate a read operation. +the operation is queued as for a call to +.br aio_read (3) +specifying this control block. +.tp +.br lio_write +initiate a write operation. +the operation is queued as for a call to +.br aio_write (3) +specifying this control block. +.tp +.br lio_nop +ignore this control block. +.pp +the remaining fields in each control block have the same meanings as for +.br aio_read (3) +and +.br aio_write (3). +the +.i aio_sigevent +fields of each control block can be used to specify notifications +for the individual i/o operations (see +.br sigevent (7)). +.sh return value +if +.i mode +is +.br lio_nowait , +.br lio_listio () +returns 0 if all i/o operations are successfully queued. +otherwise, \-1 is returned, and +.i errno +is set to indicate the error. +.pp +if +.i mode +is +.br lio_wait , +.br lio_listio () +returns 0 when all of the i/o operations have completed successfully. +otherwise, \-1 is returned, and +.i errno +is set to indicate the error. +.pp +the return status from +.br lio_listio () +provides information only about the call itself, +not about the individual i/o operations. +one or more of the i/o operations may fail, +but this does not prevent other operations completing. +the status of individual i/o operations in +.ir aiocb_list +can be determined using +.br aio_error (3). +when an operation has completed, +its return status can be obtained using +.br aio_return (3). +individual i/o operations can fail for the reasons described in +.br aio_read (3) +and +.br aio_write (3). +.sh errors +the +.br lio_listio () +function may fail for the following reasons: +.tp +.b eagain +out of resources. +.tp +.b eagain +.\" doesn't happen in glibc(?) +the number of i/o operations specified by +.i nitems +would cause the limit +.br aio_max +to be exceeded. +.tp +.b eintr +.i mode +was +.br lio_wait +and a signal +was caught before all i/o operations completed; see +.br signal (7). +(this may even be one of the signals used for +asynchronous i/o completion notification.) +.tp +.b einval +.i mode +is invalid, or +.\" doesn't happen in glibc(?) +.i nitems +exceeds the limit +.br aio_listio_max . +.tp +.b eio +one of more of the operations specified by +.ir aiocb_list +failed. +.\" e.g., ioa_reqprio or aio_lio_opcode was invalid +the application can check the status of each operation using +.br aio_return (3). +.pp +if +.br lio_listio () +fails with the error +.br eagain , +.br eintr , +or +.br eio , +then some of the operations in +.ir aiocb_list +may have been initiated. +if +.br lio_listio () +fails for any other reason, +then none of the i/o operations has been initiated. +.sh versions +the +.br lio_listio () +function is available since glibc 2.1. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br lio_listio () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008. +.sh notes +it is a good idea to zero out the control blocks before use. +the control blocks must not be changed while the i/o operations +are in progress. +the buffer areas being read into or written from +.\" or the control block of the operation +must not be accessed during the operations or undefined results may occur. +the memory areas involved must remain valid. +.pp +simultaneous i/o operations specifying the same +.i aiocb +structure produce undefined results. +.sh see also +.br aio_cancel (3), +.br aio_error (3), +.br aio_fsync (3), +.br aio_return (3), +.br aio_suspend (3), +.br aio_write (3), +.br aio (7) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/y0.3 + +.so man3/strchr.3 + +.\" copyright (c) 1998 andries brouwer (aeb@cwi.nl) +.\" and copyright (c) 2002, 2006, 2008, 2012, 2013, 2015 michael kerrisk +.\" and copyright guillem jover +.\" and copyright (c) 2010 andi kleen +.\" and copyright (c) 2012 cyrill gorcunov +.\" and copyright (c) 2014 dave hansen / intel +.\" and copyright (c) 2016 eugene syromyatnikov +.\" and copyright (c) 2018 konrad rzeszutek wilk +.\" and copyright (c) 2020 dave martin +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" modified thu nov 11 04:19:42 met 1999, aeb: added pr_get_pdeathsig +.\" modified 27 jun 02, michael kerrisk +.\" added pr_set_dumpable, pr_get_dumpable, +.\" pr_set_keepcaps, pr_get_keepcaps +.\" modified 2006-08-30 guillem jover +.\" updated linux versions where the options where introduced. +.\" added pr_set_timing, pr_get_timing, pr_set_name, pr_get_name, +.\" pr_set_unalign, pr_get_unalign, pr_set_fpemu, pr_get_fpemu, +.\" pr_set_fpexc, pr_get_fpexc +.\" 2008-04-29 serge hallyn, document pr_capbset_read and pr_capbset_drop +.\" 2008-06-13 erik bosman, +.\" document pr_get_tsc and pr_set_tsc. +.\" 2008-06-15 mtk, document pr_set_seccomp, pr_get_seccomp +.\" 2009-10-03 andi kleen, document pr_mce_kill +.\" 2012-04 cyrill gorcunov, document pr_set_mm +.\" 2012-04-25 michael kerrisk, document pr_task_perf_events_disable and +.\" pr_task_perf_events_enable +.\" 2012-09-20 kees cook, update pr_set_seccomp for mode 2 +.\" 2012-09-20 kees cook, document pr_set_no_new_privs, pr_get_no_new_privs +.\" 2012-10-25 michael kerrisk, document pr_set_timerslack and +.\" pr_get_timerslack +.\" 2013-01-10 kees cook, document pr_set_ptracer +.\" 2012-02-04 michael kerrisk, document pr_{set,get}_child_subreaper +.\" 2014-11-10 dave hansen, document pr_mpx_{en,dis}able_management +.\" +.\" +.th prctl 2 2021-03-22 "linux" "linux programmer's manual" +.sh name +prctl \- operations on a process or thread +.sh synopsis +.nf +.b #include +.pp +.bi "int prctl(int " option ", unsigned long " arg2 ", unsigned long " arg3 , +.bi " unsigned long " arg4 ", unsigned long " arg5 ); +.fi +.sh description +.br prctl () +manipulates various aspects of the behavior +of the calling thread or process. +.pp +note that careless use of some +.br prctl () +operations can confuse the user-space run-time environment, +so these operations should be used with care. +.pp +.br prctl () +is called with a first argument describing what to do +(with values defined in \fi\fp), and further +arguments with a significance depending on the first one. +the first argument can be: +.\" +.\" prctl pr_cap_ambient +.tp +.br pr_cap_ambient " (since linux 4.3)" +.\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08 +reads or changes the ambient capability set of the calling thread, +according to the value of +.ir arg2 , +which must be one of the following: +.rs +.\" +.tp +.b pr_cap_ambient_raise +the capability specified in +.i arg3 +is added to the ambient set. +the specified capability must already be present in +both the permitted and the inheritable sets of the process. +this operation is not permitted if the +.b secbit_no_cap_ambient_raise +securebit is set. +.tp +.b pr_cap_ambient_lower +the capability specified in +.i arg3 +is removed from the ambient set. +.tp +.b pr_cap_ambient_is_set +the +.br prctl () +call returns 1 if the capability in +.i arg3 +is in the ambient set and 0 if it is not. +.tp +.br pr_cap_ambient_clear_all +all capabilities will be removed from the ambient set. +this operation requires setting +.i arg3 +to zero. +.re +.ip +in all of the above operations, +.i arg4 +and +.i arg5 +must be specified as 0. +.ip +higher-level interfaces layered on top of the above operations are +provided in the +.br libcap (3) +library in the form of +.br cap_get_ambient (3), +.br cap_set_ambient (3), +and +.br cap_reset_ambient (3). +.\" prctl pr_capbset_read +.tp +.br pr_capbset_read " (since linux 2.6.25)" +return (as the function result) 1 if the capability specified in +.i arg2 +is in the calling thread's capability bounding set, +or 0 if it is not. +(the capability constants are defined in +.ir .) +the capability bounding set dictates +whether the process can receive the capability through a +file's permitted capability set on a subsequent call to +.br execve (2). +.ip +if the capability specified in +.i arg2 +is not valid, then the call fails with the error +.br einval . +.ip +a higher-level interface layered on top of this operation is provided in the +.br libcap (3) +library in the form of +.br cap_get_bound (3). +.\" prctl pr_capbset_drop +.tp +.br pr_capbset_drop " (since linux 2.6.25)" +if the calling thread has the +.b cap_setpcap +capability within its user namespace, then drop the capability specified by +.i arg2 +from the calling thread's capability bounding set. +any children of the calling thread will inherit the newly +reduced bounding set. +.ip +the call fails with the error: +.b eperm +if the calling thread does not have the +.br cap_setpcap ; +.br einval +if +.i arg2 +does not represent a valid capability; or +.br einval +if file capabilities are not enabled in the kernel, +in which case bounding sets are not supported. +.ip +a higher-level interface layered on top of this operation is provided in the +.br libcap (3) +library in the form of +.br cap_drop_bound (3). +.\" prctl pr_set_child_subreaper +.tp +.br pr_set_child_subreaper " (since linux 3.4)" +.\" commit ebec18a6d3aa1e7d84aab16225e87fd25170ec2b +if +.i arg2 +is nonzero, +set the "child subreaper" attribute of the calling process; +if +.i arg2 +is zero, unset the attribute. +.ip +a subreaper fulfills the role of +.br init (1) +for its descendant processes. +when a process becomes orphaned +(i.e., its immediate parent terminates), +then that process will be reparented to +the nearest still living ancestor subreaper. +subsequently, calls to +.br getppid (2) +in the orphaned process will now return the pid of the subreaper process, +and when the orphan terminates, it is the subreaper process that +will receive a +.br sigchld +signal and will be able to +.br wait (2) +on the process to discover its termination status. +.ip +the setting of the "child subreaper" attribute +is not inherited by children created by +.br fork (2) +and +.br clone (2). +the setting is preserved across +.br execve (2). +.ip +establishing a subreaper process is useful in session management frameworks +where a hierarchical group of processes is managed by a subreaper process +that needs to be informed when one of the processes\(emfor example, +a double-forked daemon\(emterminates +(perhaps so that it can restart that process). +some +.br init (1) +frameworks (e.g., +.br systemd (1)) +employ a subreaper process for similar reasons. +.\" prctl pr_get_child_subreaper +.tp +.br pr_get_child_subreaper " (since linux 3.4)" +return the "child subreaper" setting of the caller, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_dumpable +.tp +.br pr_set_dumpable " (since linux 2.3.20)" +set the state of the "dumpable" attribute, +which determines whether core dumps are produced for the calling process +upon delivery of a signal whose default behavior is to produce a core dump. +.ip +in kernels up to and including 2.6.12, +.i arg2 +must be either 0 +.rb ( suid_dump_disable , +process is not dumpable) or 1 +.rb ( suid_dump_user , +process is dumpable). +between kernels 2.6.13 and 2.6.17, +.\" commit abf75a5033d4da7b8a7e92321d74021d1fcfb502 +the value 2 was also permitted, +which caused any binary which normally would not be dumped +to be dumped readable by root only; +for security reasons, this feature has been removed. +.\" see http://marc.theaimsgroup.com/?l=linux-kernel&m=115270289030630&w=2 +.\" subject: fix prctl privilege escalation (cve-2006-2451) +.\" from: marcel holtmann +.\" date: 2006-07-12 11:12:00 +(see also the description of +.i /proc/sys/fs/\:suid_dumpable +in +.br proc (5).) +.ip +normally, the "dumpable" attribute is set to 1. +however, it is reset to the current value contained in the file +.ir /proc/sys/fs/\:suid_dumpable +(which by default has the value 0), +in the following circumstances: +.\" see kernel/cred.c::commit_creds() (linux 3.18 sources) +.rs +.ip * 3 +the process's effective user or group id is changed. +.ip * +the process's filesystem user or group id is changed (see +.br credentials (7)). +.ip * +the process executes +.rb ( execve (2)) +a set-user-id or set-group-id program, resulting in a change +of either the effective user id or the effective group id. +.ip * +the process executes +.rb ( execve (2)) +a program that has file capabilities (see +.br capabilities (7)), +.\" see kernel/cred.c::commit_creds() +but only if the permitted capabilities +gained exceed those already permitted for the process. +.\" also certain namespace operations; +.re +.ip +processes that are not dumpable can not be attached via +.br ptrace (2) +.br ptrace_attach ; +see +.br ptrace (2) +for further details. +.ip +if a process is not dumpable, +the ownership of files in the process's +.ir /proc/[pid] +directory is affected as described in +.br proc (5). +.\" prctl pr_get_dumpable +.tp +.br pr_get_dumpable " (since linux 2.3.20)" +return (as the function result) the current state of the calling +process's dumpable attribute. +.\" since linux 2.6.13, the dumpable flag can have the value 2, +.\" but in 2.6.13 pr_get_dumpable simply returns 1 if the dumpable +.\" flags has a nonzero value. this was fixed in 2.6.14. +.\" prctl pr_set_endian +.tp +.br pr_set_endian " (since linux 2.6.18, powerpc only)" +set the endian-ness of the calling process to the value given +in \fiarg2\fp, which should be one of the following: +.\" respectively 0, 1, 2 +.br pr_endian_big , +.br pr_endian_little , +or +.b pr_endian_ppc_little +(powerpc pseudo little endian). +.\" prctl pr_get_endian +.tp +.br pr_get_endian " (since linux 2.6.18, powerpc only)" +return the endian-ness of the calling process, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_fp_mode +.tp +.br pr_set_fp_mode " (since linux 4.0, only on mips)" +.\" commit 9791554b45a2acc28247f66a5fd5bbc212a6b8c8 +on the mips architecture, +user-space code can be built using an abi which permits linking +with code that has more restrictive floating-point (fp) requirements. +for example, user-space code may be built to target the o32 fpxx abi +and linked with code built for either one of the more restrictive +fp32 or fp64 abis. +when more restrictive code is linked in, +the overall requirement for the process is to use the more +restrictive floating-point mode. +.ip +because the kernel has no means of knowing in advance +which mode the process should be executed in, +and because these restrictions can +change over the lifetime of the process, the +.b pr_set_fp_mode +operation is provided to allow control of the floating-point mode +from user space. +.ip +.\" https://dmz-portal.mips.com/wiki/mips_o32_abi_-_fr0_and_fr1_interlinking +the +.i (unsigned int) arg2 +argument is a bit mask describing the floating-point mode used: +.rs +.tp +.br pr_fp_mode_fr +when this bit is +.i unset +(so called +.br fr=0 " or " fr0 +mode), the 32 floating-point registers are 32 bits wide, +and 64-bit registers are represented as a pair of registers +(even- and odd- numbered, +with the even-numbered register containing the lower 32 bits, +and the odd-numbered register containing the higher 32 bits). +.ip +when this bit is +.i set +(on supported hardware), +the 32 floating-point registers are 64 bits wide (so called +.br fr=1 " or " fr1 +mode). +note that modern mips implementations (mips r6 and newer) support +.b fr=1 +mode only. +.ip +applications that use the o32 fp32 abi can operate only when this bit is +.i unset +.rb ( fr=0 ; +or they can be used with fre enabled, see below). +applications that use the o32 fp64 abi +(and the o32 fp64a abi, which exists to +provide the ability to operate with existing fp32 code; see below) +can operate only when this bit is +.i set +.rb ( fr=1 ). +applications that use the o32 fpxx abi can operate with either +.br fr=0 +or +.br fr=1 . +.tp +.br pr_fp_mode_fre +enable emulation of 32-bit floating-point mode. +when this mode is enabled, +it emulates 32-bit floating-point operations +by raising a reserved-instruction exception +on every instruction that uses 32-bit formats and +the kernel then handles the instruction in software. +(the problem lies in the discrepancy of handling odd-numbered registers +which are the high 32 bits of 64-bit registers with even numbers in +.b fr=0 +mode and the lower 32-bit parts of odd-numbered 64-bit registers in +.b fr=1 +mode.) +enabling this bit is necessary when code with the o32 fp32 abi should operate +with code with compatible the o32 fpxx or o32 fp64a abis (which require +.b fr=1 +fpu mode) or when it is executed on newer hardware (mips r6 onwards) +which lacks +.b fr=0 +mode support when a binary with the fp32 abi is used. +.ip +note that this mode makes sense only when the fpu is in 64-bit mode +.rb ( fr=1 ). +.ip +note that the use of emulation inherently has a significant performance hit +and should be avoided if possible. +.re +.ip +in the n32/n64 abi, 64-bit floating-point mode is always used, +so fpu emulation is not required and the fpu always operates in +.b fr=1 +mode. +.ip +this option is mainly intended for use by the dynamic linker +.rb ( ld.so (8)). +.ip +the arguments +.ir arg3 , +.ir arg4 , +and +.ir arg5 +are ignored. +.\" prctl pr_get_fp_mode +.tp +.br pr_get_fp_mode " (since linux 4.0, only on mips)" +return (as the function result) +the current floating-point mode (see the description of +.b pr_set_fp_mode +for details). +.ip +on success, +the call returns a bit mask which represents the current floating-point mode. +.ip +the arguments +.ir arg2 , +.ir arg3 , +.ir arg4 , +and +.ir arg5 +are ignored. +.\" prctl pr_set_fpemu +.tp +.br pr_set_fpemu " (since linux 2.4.18, 2.5.9, only on ia64)" +set floating-point emulation control bits to \fiarg2\fp. +pass +.b pr_fpemu_noprint +to silently emulate floating-point operation accesses, or +.b pr_fpemu_sigfpe +to not emulate floating-point operations and send +.b sigfpe +instead. +.\" prctl pr_get_fpemu +.tp +.br pr_get_fpemu " (since linux 2.4.18, 2.5.9, only on ia64)" +return floating-point emulation control bits, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_fpexc +.tp +.br pr_set_fpexc " (since linux 2.4.21, 2.5.32, only on powerpc)" +set floating-point exception mode to \fiarg2\fp. +pass \fbpr_fp_exc_sw_enable\fp to use fpexc for fp exception enables, +\fbpr_fp_exc_div\fp for floating-point divide by zero, +\fbpr_fp_exc_ovf\fp for floating-point overflow, +\fbpr_fp_exc_und\fp for floating-point underflow, +\fbpr_fp_exc_res\fp for floating-point inexact result, +\fbpr_fp_exc_inv\fp for floating-point invalid operation, +\fbpr_fp_exc_disabled\fp for fp exceptions disabled, +\fbpr_fp_exc_nonrecov\fp for async nonrecoverable exception mode, +\fbpr_fp_exc_async\fp for async recoverable exception mode, +\fbpr_fp_exc_precise\fp for precise exception mode. +.\" prctl pr_get_fpexc +.tp +.br pr_get_fpexc " (since linux 2.4.21, 2.5.32, only on powerpc)" +return floating-point exception mode, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_io_flusher +.tp +.br pr_set_io_flusher " (since linux 5.6)" +if a user process is involved in the block layer or filesystem i/o path, +and can allocate memory while processing i/o requests it must set +\fiarg2\fp to 1. +this will put the process in the io_flusher state, +which allows it special treatment to make progress when allocating memory. +if \fiarg2\fp is 0, the process will clear the io_flusher state, and +the default behavior will be used. +.ip +the calling process must have the +.br cap_sys_resource +capability. +.ip +.ir arg3 , +.ir arg4 , +and +.ir arg5 +must be zero. +.ip +the io_flusher state is inherited by a child process created via +.br fork (2) +and is preserved across +.br execve (2). +.ip +examples of io_flusher applications are fuse daemons, scsi device +emulation daemons, and daemons that perform error handling like multipath +path recovery applications. +.\" prctl pr_get_io_flusher +.tp +.b pr_get_io_flusher (since linux 5.6) +return (as the function result) the io_flusher state of the caller. +a value of 1 indicates that the caller is in the io_flusher state; +0 indicates that the caller is not in the io_flusher state. +.ip +the calling process must have the +.br cap_sys_resource +capability. +.ip +.ir arg2 , +.ir arg3 , +.ir arg4 , +and +.ir arg5 +must be zero. +.\" prctl pr_set_keepcaps +.tp +.br pr_set_keepcaps " (since linux 2.2.18)" +set the state of the calling thread's "keep capabilities" flag. +the effect of this flag is described in +.br capabilities (7). +.i arg2 +must be either 0 (clear the flag) +or 1 (set the flag). +the "keep capabilities" value will be reset to 0 on subsequent calls to +.br execve (2). +.\" prctl pr_get_keepcaps +.tp +.br pr_get_keepcaps " (since linux 2.2.18)" +return (as the function result) the current state of the calling thread's +"keep capabilities" flag. +see +.br capabilities (7) +for a description of this flag. +.\" prctl pr_mce_kill +.tp +.br pr_mce_kill " (since linux 2.6.32)" +set the machine check memory corruption kill policy for the calling thread. +if +.i arg2 +is +.br pr_mce_kill_clear , +clear the thread memory corruption kill policy and use the system-wide default. +(the system-wide default is defined by +.ir /proc/sys/vm/memory_failure_early_kill ; +see +.br proc (5).) +if +.i arg2 +is +.br pr_mce_kill_set , +use a thread-specific memory corruption kill policy. +in this case, +.i arg3 +defines whether the policy is +.i early kill +.rb ( pr_mce_kill_early ), +.i late kill +.rb ( pr_mce_kill_late ), +or the system-wide default +.rb ( pr_mce_kill_default ). +early kill means that the thread receives a +.b sigbus +signal as soon as hardware memory corruption is detected inside +its address space. +in late kill mode, the process is killed only when it accesses a corrupted page. +see +.br sigaction (2) +for more information on the +.br sigbus +signal. +the policy is inherited by children. +the remaining unused +.br prctl () +arguments must be zero for future compatibility. +.\" prctl pr_mce_kill_get +.tp +.br pr_mce_kill_get " (since linux 2.6.32)" +return (as the function result) +the current per-process machine check kill policy. +all unused +.br prctl () +arguments must be zero. +.\" prctl pr_set_mm +.tp +.br pr_set_mm " (since linux 3.3)" +.\" commit 028ee4be34a09a6d48bdf30ab991ae933a7bc036 +modify certain kernel memory map descriptor fields +of the calling process. +usually these fields are set by the kernel and dynamic loader (see +.br ld.so (8) +for more information) and a regular application should not use this feature. +however, there are cases, such as self-modifying programs, +where a program might find it useful to change its own memory map. +.ip +the calling process must have the +.br cap_sys_resource +capability. +the value in +.i arg2 +is one of the options below, while +.i arg3 +provides a new value for the option. +the +.i arg4 +and +.i arg5 +arguments must be zero if unused. +.ip +before linux 3.10, +.\" commit 52b3694157e3aa6df871e283115652ec6f2d31e0 +this feature is available only if the kernel is built with the +.br config_checkpoint_restore +option enabled. +.rs +.tp +.br pr_set_mm_start_code +set the address above which the program text can run. +the corresponding memory area must be readable and executable, +but not writable or shareable (see +.br mprotect (2) +and +.br mmap (2) +for more information). +.tp +.br pr_set_mm_end_code +set the address below which the program text can run. +the corresponding memory area must be readable and executable, +but not writable or shareable. +.tp +.br pr_set_mm_start_data +set the address above which initialized and +uninitialized (bss) data are placed. +the corresponding memory area must be readable and writable, +but not executable or shareable. +.tp +.b pr_set_mm_end_data +set the address below which initialized and +uninitialized (bss) data are placed. +the corresponding memory area must be readable and writable, +but not executable or shareable. +.tp +.br pr_set_mm_start_stack +set the start address of the stack. +the corresponding memory area must be readable and writable. +.tp +.br pr_set_mm_start_brk +set the address above which the program heap can be expanded with +.br brk (2) +call. +the address must be greater than the ending address of +the current program data segment. +in addition, the combined size of the resulting heap and +the size of the data segment can't exceed the +.br rlimit_data +resource limit (see +.br setrlimit (2)). +.tp +.br pr_set_mm_brk +set the current +.br brk (2) +value. +the requirements for the address are the same as for the +.br pr_set_mm_start_brk +option. +.pp +the following options are available since linux 3.5. +.\" commit fe8c7f5cbf91124987106faa3bdf0c8b955c4cf7 +.tp +.br pr_set_mm_arg_start +set the address above which the program command line is placed. +.tp +.br pr_set_mm_arg_end +set the address below which the program command line is placed. +.tp +.br pr_set_mm_env_start +set the address above which the program environment is placed. +.tp +.br pr_set_mm_env_end +set the address below which the program environment is placed. +.ip +the address passed with +.br pr_set_mm_arg_start , +.br pr_set_mm_arg_end , +.br pr_set_mm_env_start , +and +.br pr_set_mm_env_end +should belong to a process stack area. +thus, the corresponding memory area must be readable, writable, and +(depending on the kernel configuration) have the +.br map_growsdown +attribute set (see +.br mmap (2)). +.tp +.br pr_set_mm_auxv +set a new auxiliary vector. +the +.i arg3 +argument should provide the address of the vector. +the +.i arg4 +is the size of the vector. +.tp +.br pr_set_mm_exe_file +.\" commit b32dfe377102ce668775f8b6b1461f7ad428f8b6 +supersede the +.ir /proc/pid/exe +symbolic link with a new one pointing to a new executable file +identified by the file descriptor provided in +.i arg3 +argument. +the file descriptor should be obtained with a regular +.br open (2) +call. +.ip +to change the symbolic link, one needs to unmap all existing +executable memory areas, including those created by the kernel itself +(for example the kernel usually creates at least one executable +memory area for the elf +.ir \.text +section). +.ip +in linux 4.9 and earlier, the +.\" commit 3fb4afd9a504c2386b8435028d43283216bf588e +.br pr_set_mm_exe_file +operation can be performed only once in a process's lifetime; +attempting to perform the operation a second time results in the error +.br eperm . +this restriction was enforced for security reasons that were subsequently +deemed specious, +and the restriction was removed in linux 4.10 because some +user-space applications needed to perform this operation more than once. +.pp +the following options are available since linux 3.18. +.\" commit f606b77f1a9e362451aca8f81d8f36a3a112139e +.tp +.br pr_set_mm_map +provides one-shot access to all the addresses by passing in a +.i struct prctl_mm_map +(as defined in \fi\fp). +the +.i arg4 +argument should provide the size of the struct. +.ip +this feature is available only if the kernel is built with the +.br config_checkpoint_restore +option enabled. +.tp +.br pr_set_mm_map_size +returns the size of the +.i struct prctl_mm_map +the kernel expects. +this allows user space to find a compatible struct. +the +.i arg4 +argument should be a pointer to an unsigned int. +.ip +this feature is available only if the kernel is built with the +.br config_checkpoint_restore +option enabled. +.re +.\" prctl pr_mpx_enable_management +.tp +.br pr_mpx_enable_management ", " pr_mpx_disable_management " (since linux 3.19, removed in linux 5.4; only on x86)" +.\" commit fe3d197f84319d3bce379a9c0dc17b1f48ad358c +.\" see also http://lwn.net/articles/582712/ +.\" see also https://gcc.gnu.org/wiki/intel%20mpx%20support%20in%20the%20gcc%20compiler +enable or disable kernel management of memory protection extensions (mpx) +bounds tables. +the +.ir arg2 , +.ir arg3 , +.ir arg4 , +and +.ir arg5 +.\" commit e9d1b4f3c60997fe197bf0243cb4a41a44387a88 +arguments must be zero. +.ip +mpx is a hardware-assisted mechanism for performing bounds checking on +pointers. +it consists of a set of registers storing bounds information +and a set of special instruction prefixes that tell the cpu on which +instructions it should do bounds enforcement. +there is a limited number of these registers and +when there are more pointers than registers, +their contents must be "spilled" into a set of tables. +these tables are called "bounds tables" and the mpx +.br prctl () +operations control +whether the kernel manages their allocation and freeing. +.ip +when management is enabled, the kernel will take over allocation +and freeing of the bounds tables. +it does this by trapping the #br exceptions that result +at first use of missing bounds tables and +instead of delivering the exception to user space, +it allocates the table and populates the bounds directory +with the location of the new table. +for freeing, the kernel checks to see if bounds tables are +present for memory which is not allocated, and frees them if so. +.ip +before enabling mpx management using +.br pr_mpx_enable_management , +the application must first have allocated a user-space buffer for +the bounds directory and placed the location of that directory in the +.i bndcfgu +register. +.ip +these calls fail if the cpu or kernel does not support mpx. +kernel support for mpx is enabled via the +.br config_x86_intel_mpx +configuration option. +you can check whether the cpu supports mpx by looking for the +.i mpx +cpuid bit, like with the following command: +.ip +.in +4n +.ex +cat /proc/cpuinfo | grep \(aq mpx \(aq +.ee +.in +.ip +a thread may not switch in or out of long (64-bit) mode while mpx is +enabled. +.ip +all threads in a process are affected by these calls. +.ip +the child of a +.br fork (2) +inherits the state of mpx management. +during +.br execve (2), +mpx management is reset to a state as if +.br pr_mpx_disable_management +had been called. +.ip +for further information on intel mpx, see the kernel source file +.ir documentation/x86/intel_mpx.txt . +.ip +.\" commit f240652b6032b48ad7fa35c5e701cc4c8d697c0b +.\" see also https://lkml.kernel.org/r/20190705175321.db42f0ad@viggo.jf.intel.com +due to a lack of toolchain support, +.br pr_mpx_enable_management " and " pr_mpx_disable_management +are not supported in linux 5.4 and later. +.\" prctl pr_set_name +.tp +.br pr_set_name " (since linux 2.6.9)" +set the name of the calling thread, +using the value in the location pointed to by +.ir "(char\ *) arg2" . +the name can be up to 16 bytes long, +.\" task_comm_len in include/linux/sched.h +including the terminating null byte. +(if the length of the string, including the terminating null byte, +exceeds 16 bytes, the string is silently truncated.) +this is the same attribute that can be set via +.br pthread_setname_np (3) +and retrieved using +.br pthread_getname_np (3). +the attribute is likewise accessible via +.ir /proc/self/task/[tid]/comm +(see +.br proc (5)), +where +.i [tid] +is the thread id of the calling thread, as returned by +.br gettid (2). +.\" prctl pr_get_name +.tp +.br pr_get_name " (since linux 2.6.11)" +return the name of the calling thread, +in the buffer pointed to by +.ir "(char\ *) arg2" . +the buffer should allow space for up to 16 bytes; +the returned string will be null-terminated. +.\" prctl pr_set_no_new_privs +.tp +.br pr_set_no_new_privs " (since linux 3.5)" +set the calling thread's +.i no_new_privs +attribute to the value in +.ir arg2 . +with +.i no_new_privs +set to 1, +.br execve (2) +promises not to grant privileges to do anything +that could not have been done without the +.br execve (2) +call (for example, +rendering the set-user-id and set-group-id mode bits, +and file capabilities non-functional). +once set, the +.i no_new_privs +attribute cannot be unset. +the setting of this attribute is inherited by children created by +.br fork (2) +and +.br clone (2), +and preserved across +.br execve (2). +.ip +since linux 4.10, +the value of a thread's +.i no_new_privs +attribute can be viewed via the +.i nonewprivs +field in the +.ir /proc/[pid]/status +file. +.ip +for more information, see the kernel source file +.ir documentation/userspace\-api/no_new_privs.rst +.\" commit 40fde647ccb0ae8c11d256d271e24d385eed595b +(or +.ir documentation/prctl/no_new_privs.txt +before linux 4.13). +see also +.br seccomp (2). +.\" prctl pr_get_no_new_privs +.tp +.br pr_get_no_new_privs " (since linux 3.5)" +return (as the function result) the value of the +.i no_new_privs +attribute for the calling thread. +a value of 0 indicates the regular +.br execve (2) +behavior. +a value of 1 indicates +.br execve (2) +will operate in the privilege-restricting mode described above. +.\" prctl pr_pac_reset_keys +.\" commit ba830885656414101b2f8ca88786524d4bb5e8c1 +.tp +.br pr_pac_reset_keys " (since linux 5.0, only on arm64)" +securely reset the thread's pointer authentication keys +to fresh random values generated by the kernel. +.ip +the set of keys to be reset is specified by +.ir arg2 , +which must be a logical or of zero or more of the following: +.rs +.tp +.b pr_pac_apiakey +instruction authentication key a +.tp +.b pr_pac_apibkey +instruction authentication key b +.tp +.b pr_pac_apdakey +data authentication key a +.tp +.b pr_pac_apdbkey +data authentication key b +.tp +.b pr_pac_apgakey +generic authentication \(lqa\(rq key. +.ip +(yes folks, there really is no generic b key.) +.re +.ip +as a special case, if +.i arg2 +is zero, then all the keys are reset. +since new keys could be added in future, +this is the recommended way to completely wipe the existing keys +when establishing a clean execution context. +note that there is no need to use +.br pr_pac_reset_keys +in preparation for calling +.br execve (2), +since +.br execve (2) +resets all the pointer authentication keys. +.ip +the remaining arguments +.ir arg3 ", " arg4 ", and " arg5 +must all be zero. +.ip +if the arguments are invalid, +and in particular if +.i arg2 +contains set bits that are unrecognized +or that correspond to a key not available on this platform, +then the call fails with error +.br einval . +.ip +.b warning: +because the compiler or run-time environment +may be using some or all of the keys, +a successful +.b pr_pac_reset_keys +may crash the calling process. +the conditions for using it safely are complex and system-dependent. +don't use it unless you know what you are doing. +.ip +for more information, see the kernel source file +.i documentation/arm64/pointer\-authentication.rst +.\"commit b693d0b372afb39432e1c49ad7b3454855bc6bed +(or +.i documentation/arm64/pointer\-authentication.txt +before linux 5.3). +.\" prctl pr_set_pdeathsig +.tp +.br pr_set_pdeathsig " (since linux 2.1.57)" +set the parent-death signal +of the calling process to \fiarg2\fp (either a signal value +in the range 1..\c +.br nsig "\-1" , +or 0 to clear). +this is the signal that the calling process will get when its +parent dies. +.ip +.ir warning : +.\" https://bugzilla.kernel.org/show_bug.cgi?id=43300 +the "parent" in this case is considered to be the +.i thread +that created this process. +in other words, the signal will be sent when that thread terminates +(via, for example, +.br pthread_exit (3)), +rather than after all of the threads in the parent process terminate. +.ip +the parent-death signal is sent upon subsequent termination of the parent +thread and also upon termination of each subreaper process +(see the description of +.b pr_set_child_subreaper +above) to which the caller is subsequently reparented. +if the parent thread and all ancestor subreapers have already terminated +by the time of the +.br pr_set_pdeathsig +operation, then no parent-death signal is sent to the caller. +.ip +the parent-death signal is process-directed (see +.br signal (7)) +and, if the child installs a handler using the +.br sigaction (2) +.b sa_siginfo +flag, the +.i si_pid +field of the +.i siginfo_t +argument of the handler contains the pid of the terminating parent process. +.ip +the parent-death signal setting is cleared for the child of a +.br fork (2). +it is also +(since linux 2.4.36 / 2.6.23) +.\" commit d2d56c5f51028cb9f3d800882eb6f4cbd3f9099f +cleared when executing a set-user-id or set-group-id binary, +or a binary that has associated capabilities (see +.br capabilities (7)); +otherwise, this value is preserved across +.br execve (2). +the parent-death signal setting is also cleared upon changes to +any of the following thread credentials: +.\" fixme capability changes can also trigger this; see +.\" kernel/cred.c::commit_creds in the linux 5.6 source. +effective user id, effective group id, filesystem user id, +or filesystem group id. +.\" prctl pr_get_pdeathsig +.tp +.br pr_get_pdeathsig " (since linux 2.3.15)" +return the current value of the parent process death signal, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_ptracer +.tp +.br pr_set_ptracer " (since linux 3.4)" +.\" commit 2d514487faf188938a4ee4fb3464eeecfbdcf8eb +.\" commit bf06189e4d14641c0148bea16e9dd24943862215 +this is meaningful only when the yama lsm is enabled and in mode 1 +("restricted ptrace", visible via +.ir /proc/sys/kernel/yama/ptrace_scope ). +when a "ptracer process id" is passed in \fiarg2\fp, +the caller is declaring that the ptracer process can +.br ptrace (2) +the calling process as if it were a direct process ancestor. +each +.b pr_set_ptracer +operation replaces the previous "ptracer process id". +employing +.b pr_set_ptracer +with +.i arg2 +set to 0 clears the caller's "ptracer process id". +if +.i arg2 +is +.br pr_set_ptracer_any , +the ptrace restrictions introduced by yama are effectively disabled for the +calling process. +.ip +for further information, see the kernel source file +.ir documentation/admin\-guide/lsm/yama.rst +.\" commit 90bb766440f2147486a2acc3e793d7b8348b0c22 +(or +.ir documentation/security/yama.txt +before linux 4.13). +.\" prctl pr_set_seccomp +.tp +.br pr_set_seccomp " (since linux 2.6.23)" +.\" see http://thread.gmane.org/gmane.linux.kernel/542632 +.\" [patch 0 of 2] seccomp updates +.\" andrea@cpushare.com +set the secure computing (seccomp) mode for the calling thread, to limit +the available system calls. +the more recent +.br seccomp (2) +system call provides a superset of the functionality of +.br pr_set_seccomp . +.ip +the seccomp mode is selected via +.ir arg2 . +(the seccomp constants are defined in +.ir .) +.ip +with +.ir arg2 +set to +.br seccomp_mode_strict , +the only system calls that the thread is permitted to make are +.br read (2), +.br write (2), +.br _exit (2) +(but not +.br exit_group (2)), +and +.br sigreturn (2). +other system calls result in the delivery of a +.br sigkill +signal. +strict secure computing mode is useful for number-crunching applications +that may need to execute untrusted byte code, +perhaps obtained by reading from a pipe or socket. +this operation is available only +if the kernel is configured with +.b config_seccomp +enabled. +.ip +with +.ir arg2 +set to +.br seccomp_mode_filter " (since linux 3.5)," +the system calls allowed are defined by a pointer +to a berkeley packet filter passed in +.ir arg3 . +this argument is a pointer to +.ir "struct sock_fprog" ; +it can be designed to filter +arbitrary system calls and system call arguments. +this mode is available only if the kernel is configured with +.b config_seccomp_filter +enabled. +.ip +if +.br seccomp_mode_filter +filters permit +.br fork (2), +then the seccomp mode is inherited by children created by +.br fork (2); +if +.br execve (2) +is permitted, then the seccomp mode is preserved across +.br execve (2). +if the filters permit +.br prctl () +calls, then additional filters can be added; +they are run in order until the first non-allow result is seen. +.ip +for further information, see the kernel source file +.ir documentation/userspace\-api/seccomp_filter.rst +.\" commit c061f33f35be0ccc80f4b8e0aea5dfd2ed7e01a3 +(or +.ir documentation/prctl/seccomp_filter.txt +before linux 4.13). +.\" prctl pr_get_seccomp +.tp +.br pr_get_seccomp " (since linux 2.6.23)" +return (as the function result) +the secure computing mode of the calling thread. +if the caller is not in secure computing mode, this operation returns 0; +if the caller is in strict secure computing mode, then the +.br prctl () +call will cause a +.b sigkill +signal to be sent to the process. +if the caller is in filter mode, and this system call is allowed by the +seccomp filters, it returns 2; otherwise, the process is killed with a +.br sigkill +signal. +this operation is available only +if the kernel is configured with +.b config_seccomp +enabled. +.ip +since linux 3.8, the +.ir seccomp +field of the +.ir /proc/[pid]/status +file provides a method of obtaining the same information, +without the risk that the process is killed; see +.br proc (5). +.\" prctl pr_set_securebits +.tp +.br pr_set_securebits " (since linux 2.6.26)" +set the "securebits" flags of the calling thread to the value supplied in +.ir arg2 . +see +.br capabilities (7). +.\" prctl pr_get_securebits +.tp +.br pr_get_securebits " (since linux 2.6.26)" +return (as the function result) +the "securebits" flags of the calling thread. +see +.br capabilities (7). +.\" prctl pr_get_speculation_ctrl +.tp +.br pr_get_speculation_ctrl " (since linux 4.17)" +return (as the function result) +the state of the speculation misfeature specified in +.ir arg2 . +currently, the only permitted value for this argument is +.br pr_spec_store_bypass +(otherwise the call fails with the error +.br enodev ). +.ip +the return value uses bits 0-3 with the following meaning: +.rs +.tp +.br pr_spec_prctl +mitigation can be controlled per thread by +.br pr_set_speculation_ctrl . +.tp +.br pr_spec_enable +the speculation feature is enabled, mitigation is disabled. +.tp +.br pr_spec_disable +the speculation feature is disabled, mitigation is enabled. +.tp +.br pr_spec_force_disable +same as +.b pr_spec_disable +but cannot be undone. +.tp +.br pr_spec_disable_noexec " (since linux 5.1)" +same as +.br pr_spec_disable , +but the state will be cleared on +.br execve (2). +.re +.ip +if all bits are 0, +then the cpu is not affected by the speculation misfeature. +.ip +if +.b pr_spec_prctl +is set, then per-thread control of the mitigation is available. +if not set, +.br prctl () +for the speculation misfeature will fail. +.ip +the +.ir arg3 , +.ir arg4 , +and +.i arg5 +arguments must be specified as 0; otherwise the call fails with the error +.br einval . +.\" prctl pr_set_speculation_ctrl +.tp +.br pr_set_speculation_ctrl " (since linux 4.17)" +.\" commit b617cfc858161140d69cc0b5cc211996b557a1c7 +.\" commit 356e4bfff2c5489e016fdb925adbf12a1e3950ee +sets the state of the speculation misfeature specified in +.ir arg2 . +the speculation-misfeature settings are per-thread attributes. +.ip +currently, +.i arg2 +must be one of: +.rs +.tp +.b pr_spec_store_bypass +set the state of the speculative store bypass misfeature. +.\" commit 9137bb27e60e554dab694eafa4cca241fa3a694f +.tp +.br pr_spec_indirect_branch " (since linux 4.20)" +set the state of the indirect branch speculation misfeature. +.re +.ip +if +.i arg2 +does not have one of the above values, +then the call fails with the error +.br enodev . +.ip +the +.ir arg3 +argument is used to hand in the control value, +which is one of the following: +.rs +.tp +.br pr_spec_enable +the speculation feature is enabled, mitigation is disabled. +.tp +.br pr_spec_disable +the speculation feature is disabled, mitigation is enabled. +.tp +.br pr_spec_force_disable +same as +.br pr_spec_disable , +but cannot be undone. +a subsequent +.br prctl (\c +.ir arg2 , +.br pr_spec_enable ) +with the same value for +.i arg2 +will fail with the error +.br eperm . +.\" commit 71368af9027f18fe5d1c6f372cfdff7e4bde8b48 +.tp +.br pr_spec_disable_noexec " (since linux 5.1)" +same as +.br pr_spec_disable , +but the state will be cleared on +.br execve (2). +currently only supported for +.i arg2 +equal to +.b pr_spec_store_bypass. +.re +.ip +any unsupported value in +.ir arg3 +will result in the call failing with the error +.br erange . +.ip +the +.i arg4 +and +.i arg5 +arguments must be specified as 0; otherwise the call fails with the error +.br einval . +.ip +the speculation feature can also be controlled by the +.b spec_store_bypass_disable +boot parameter. +this parameter may enforce a read-only policy which will result in the +.br prctl () +call failing with the error +.br enxio . +for further details, see the kernel source file +.ir documentation/admin\-guide/kernel\-parameters.txt . +.\" prctl pr_sve_set_vl +.\" commit 2d2123bc7c7f843aa9db87720de159a049839862 +.\" linux-5.6/documentation/arm64/sve.rst +.tp +.br pr_sve_set_vl " (since linux 4.15, only on arm64)" +configure the thread's sve vector length, +as specified by +.ir "(int) arg2" . +arguments +.ir arg3 ", " arg4 ", and " arg5 +are ignored. +.ip +the bits of +.i arg2 +corresponding to +.b pr_sve_vl_len_mask +must be set to the desired vector length in bytes. +this is interpreted as an upper bound: +the kernel will select the greatest available vector length +that does not exceed the value specified. +in particular, specifying +.b sve_vl_max +(defined in +.i ) +for the +.b pr_sve_vl_len_mask +bits requests the maximum supported vector length. +.ip +in addition, the other bits of +.i arg2 +must be set to one of the following combinations of flags: +.rs +.tp +.b 0 +perform the change immediately. +at the next +.br execve (2) +in the thread, +the vector length will be reset to the value configured in +.ir /proc/sys/abi/sve_default_vector_length . +.tp +.b pr_sve_vl_inherit +perform the change immediately. +subsequent +.br execve (2) +calls will preserve the new vector length. +.tp +.b pr_sve_set_vl_onexec +defer the change, so that it is performed at the next +.br execve (2) +in the thread. +further +.br execve (2) +calls will reset the vector length to the value configured in +.ir /proc/sys/abi/sve_default_vector_length . +.tp +.b "pr_sve_set_vl_onexec | pr_sve_vl_inherit" +defer the change, so that it is performed at the next +.br execve (2) +in the thread. +further +.br execve (2) +calls will preserve the new vector length. +.re +.ip +in all cases, +any previously pending deferred change is canceled. +.ip +the call fails with error +.b einval +if sve is not supported on the platform, if +.i arg2 +is unrecognized or invalid, or the value in the bits of +.i arg2 +corresponding to +.b pr_sve_vl_len_mask +is outside the range +.br sve_vl_min .. sve_vl_max +or is not a multiple of 16. +.ip +on success, +a nonnegative value is returned that describes the +.i selected +configuration. +if +.b pr_sve_set_vl_onexec +was included in +.ir arg2 , +then the configuration described by the return value +will take effect at the next +.br execve (2). +otherwise, the configuration is already in effect when the +.b pr_sve_set_vl +call returns. +in either case, the value is encoded in the same way as the return value of +.br pr_sve_get_vl . +note that there is no explicit flag in the return value +corresponding to +.br pr_sve_set_vl_onexec . +.ip +the configuration (including any pending deferred change) +is inherited across +.br fork (2) +and +.br clone (2). +.ip +for more information, see the kernel source file +.i documentation/arm64/sve.rst +.\"commit b693d0b372afb39432e1c49ad7b3454855bc6bed +(or +.i documentation/arm64/sve.txt +before linux 5.3). +.ip +.b warning: +because the compiler or run-time environment +may be using sve, using this call without the +.b pr_sve_set_vl_onexec +flag may crash the calling process. +the conditions for using it safely are complex and system-dependent. +don't use it unless you really know what you are doing. +.\" prctl pr_sve_get_vl +.tp +.br pr_sve_get_vl " (since linux 4.15, only on arm64)" +get the thread's current sve vector length configuration. +.ip +arguments +.ir arg2 ", " arg3 ", " arg4 ", and " arg5 +are ignored. +.ip +provided that the kernel and platform support sve, +this operation always succeeds, +returning a nonnegative value that describes the +.i current +configuration. +the bits corresponding to +.b pr_sve_vl_len_mask +contain the currently configured vector length in bytes. +the bit corresponding to +.b pr_sve_vl_inherit +indicates whether the vector length will be inherited +across +.br execve (2). +.ip +note that there is no way to determine whether there is +a pending vector length change that has not yet taken effect. +.ip +for more information, see the kernel source file +.i documentation/arm64/sve.rst +.\"commit b693d0b372afb39432e1c49ad7b3454855bc6bed +(or +.i documentation/arm64/sve.txt +before linux 5.3). +.tp +.\" prctl pr_set_syscall_user_dispatch +.\" commit 1446e1df9eb183fdf81c3f0715402f1d7595d4 +.br pr_set_syscall_user_dispatch " (since linux 5.11, x86 only)" +configure the syscall user dispatch mechanism +for the calling thread. +this mechanism allows an application +to selectively intercept system calls +so that they can be handled within the application itself. +interception takes the form of a thread-directed +.b sigsys +signal that is delivered to the thread +when it makes a system call. +if intercepted, +the system call is not executed by the kernel. +.ip +to enable this mechanism, +.i arg2 +should be set to +.br pr_sys_dispatch_on . +once enabled, further system calls will be selectively intercepted, +depending on a control variable provided by user space. +in this case, +.i arg3 +and +.i arg4 +respectively identify the +.i offset +and +.i length +of a single contiguous memory region in the process address space +from where system calls are always allowed to be executed, +regardless of the control variable. +(typically, this area would include the area of memory +containing the c library.) +.ip +.i arg5 +points to a char-sized variable +that is a fast switch to allow/block system call execution +without the overhead of doing another system call +to re-configure syscall user dispatch. +this control variable can either be set to +.b syscall_dispatch_filter_block +to block system calls from executing +or to +.b syscall_dispatch_filter_allow +to temporarily allow them to be executed. +this value is checked by the kernel +on every system call entry, +and any unexpected value will raise +an uncatchable +.b sigsys +at that time, +killing the application. +.ip +when a system call is intercepted, +the kernel sends a thread-directed +.b sigsys +signal to the triggering thread. +various fields will be set in the +.i siginfo_t +structure (see +.br sigaction (2)) +associated with the signal: +.rs +.ip * 3 +.i si_signo +will contain +.br sigsys . +.ip * +.ir si_call_addr +will show the address of the system call instruction. +.ip * +.ir si_syscall +and +.ir si_arch +will indicate which system call was attempted. +.ip * +.i si_code +will contain +.br sys_user_dispatch . +.ip * +.i si_errno +will be set to 0. +.re +.ip +the program counter will be as though the system call happened +(i.e., the program counter will not point to the system call instruction). +.ip +when the signal handler returns to the kernel, +the system call completes immediately +and returns to the calling thread, +without actually being executed. +if necessary +(i.e., when emulating the system call on user space.), +the signal handler should set the system call return value +to a sane value, +by modifying the register context stored in the +.i ucontext +argument of the signal handler. +see +.br sigaction (2), +.br sigreturn (2), +and +.br getcontext (3) +for more information. +.ip +if +.i arg2 +is set to +.br pr_sys_dispatch_off , +syscall user dispatch is disabled for that thread. +the remaining arguments must be set to 0. +.ip +the setting is not preserved across +.br fork (2), +.br clone (2), +or +.br execve (2). +.ip +for more information, +see the kernel source file +.ir documentation/admin-guide/syscall-user-dispatch.rst +.\" prctl pr_set_tagged_addr_ctrl +.\" commit 63f0c60379650d82250f22e4cf4137ef3dc4f43d +.tp +.br pr_set_tagged_addr_ctrl " (since linux 5.4, only on arm64)" +controls support for passing tagged user-space addresses to the kernel +(i.e., addresses where bits 56\(em63 are not all zero). +.ip +the level of support is selected by +.ir "arg2" , +which can be one of the following: +.rs +.tp +.b 0 +addresses that are passed +for the purpose of being dereferenced by the kernel +must be untagged. +.tp +.b pr_tagged_addr_enable +addresses that are passed +for the purpose of being dereferenced by the kernel +may be tagged, with the exceptions summarized below. +.re +.ip +the remaining arguments +.ir arg3 ", " arg4 ", and " arg5 +must all be zero. +.\" enforcement added in +.\" commit 3e91ec89f527b9870fe42dcbdb74fd389d123a95 +.ip +on success, the mode specified in +.i arg2 +is set for the calling thread and the return value is 0. +if the arguments are invalid, +the mode specified in +.i arg2 +is unrecognized, +or if this feature is unsupported by the kernel +or disabled via +.ir /proc/sys/abi/tagged_addr_disabled , +the call fails with the error +.br einval . +.ip +in particular, if +.br prctl ( pr_set_tagged_addr_ctrl , +0, 0, 0, 0) +fails with +.br einval , +then all addresses passed to the kernel must be untagged. +.ip +irrespective of which mode is set, +addresses passed to certain interfaces +must always be untagged: +.rs +.ip \(bu 2 +.br brk (2), +.br mmap (2), +.br shmat (2), +.br shmdt (2), +and the +.i new_address +argument of +.br mremap (2). +.ip +(prior to linux 5.6 these accepted tagged addresses, +but the behaviour may not be what you expect. +don't rely on it.) +.ip \(bu +\(oqpolymorphic\(cq interfaces +that accept pointers to arbitrary types cast to a +.i void * +or other generic type, specifically +.br prctl (), +.br ioctl (2), +and in general +.br setsockopt (2) +(only certain specific +.br setsockopt (2) +options allow tagged addresses). +.re +.ip +this list of exclusions may shrink +when moving from one kernel version to a later kernel version. +while the kernel may make some guarantees +for backwards compatibility reasons, +for the purposes of new software +the effect of passing tagged addresses to these interfaces +is unspecified. +.ip +the mode set by this call is inherited across +.br fork (2) +and +.br clone (2). +the mode is reset by +.br execve (2) +to 0 +(i.e., tagged addresses not permitted in the user/kernel abi). +.ip +for more information, see the kernel source file +.ir documentation/arm64/tagged\-address\-abi.rst . +.ip +.b warning: +this call is primarily intended for use by the run-time environment. +a successful +.b pr_set_tagged_addr_ctrl +call elsewhere may crash the calling process. +the conditions for using it safely are complex and system-dependent. +don't use it unless you know what you are doing. +.\" prctl pr_get_tagged_addr_ctrl +.\" commit 63f0c60379650d82250f22e4cf4137ef3dc4f43d +.tp +.br pr_get_tagged_addr_ctrl " (since linux 5.4, only on arm64)" +returns the current tagged address mode +for the calling thread. +.ip +arguments +.ir arg2 ", " arg3 ", " arg4 ", and " arg5 +must all be zero. +.ip +if the arguments are invalid +or this feature is disabled or unsupported by the kernel, +the call fails with +.br einval . +in particular, if +.br prctl ( pr_get_tagged_addr_ctrl , +0, 0, 0, 0) +fails with +.br einval , +then this feature is definitely either unsupported, +or disabled via +.ir /proc/sys/abi/tagged_addr_disabled . +in this case, +all addresses passed to the kernel must be untagged. +.ip +otherwise, the call returns a nonnegative value +describing the current tagged address mode, +encoded in the same way as the +.i arg2 +argument of +.br pr_set_tagged_addr_ctrl . +.ip +for more information, see the kernel source file +.ir documentation/arm64/tagged\-address\-abi.rst . +.\" +.\" prctl pr_task_perf_events_disable +.tp +.br pr_task_perf_events_disable " (since linux 2.6.31)" +disable all performance counters attached to the calling process, +regardless of whether the counters were created by +this process or another process. +performance counters created by the calling process for other +processes are unaffected. +for more information on performance counters, see the linux kernel source file +.ir tools/perf/design.txt . +.ip +originally called +.br pr_task_perf_counters_disable ; +.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28 +renamed (retaining the same numerical value) +in linux 2.6.32. +.\" +.\" prctl pr_task_perf_events_enable +.tp +.br pr_task_perf_events_enable " (since linux 2.6.31)" +the converse of +.br pr_task_perf_events_disable ; +enable performance counters attached to the calling process. +.ip +originally called +.br pr_task_perf_counters_enable ; +.\" commit 1d1c7ddbfab358445a542715551301b7fc363e28 +renamed +.\" commit cdd6c482c9ff9c55475ee7392ec8f672eddb7be6 +in linux 2.6.32. +.\" +.\" prctl pr_set_thp_disable +.tp +.br pr_set_thp_disable " (since linux 3.15)" +.\" commit a0715cc22601e8830ace98366c0c2bd8da52af52 +set the state of the "thp disable" flag for the calling thread. +if +.i arg2 +has a nonzero value, the flag is set, otherwise it is cleared. +setting this flag provides a method +for disabling transparent huge pages +for jobs where the code cannot be modified, and using a malloc hook with +.br madvise (2) +is not an option (i.e., statically allocated data). +the setting of the "thp disable" flag is inherited by a child created via +.br fork (2) +and is preserved across +.br execve (2). +.\" prctl pr_get_thp_disable +.tp +.br pr_get_thp_disable " (since linux 3.15)" +return (as the function result) the current setting of the "thp disable" +flag for the calling thread: +either 1, if the flag is set, or 0, if it is not. +.\" prctl pr_get_tid_address +.tp +.br pr_get_tid_address " (since linux 3.5)" +.\" commit 300f786b2683f8bb1ec0afb6e1851183a479c86d +return the +.i clear_child_tid +address set by +.br set_tid_address (2) +and the +.br clone (2) +.b clone_child_cleartid +flag, in the location pointed to by +.ir "(int\ **)\ arg2" . +this feature is available only if the kernel is built with the +.br config_checkpoint_restore +option enabled. +note that since the +.br prctl () +system call does not have a compat implementation for +the amd64 x32 and mips n32 abis, +and the kernel writes out a pointer using the kernel's pointer size, +this operation expects a user-space buffer of 8 (not 4) bytes on these abis. +.\" prctl pr_set_timerslack +.tp +.br pr_set_timerslack " (since linux 2.6.28)" +.\" see https://lwn.net/articles/369549/ +.\" commit 6976675d94042fbd446231d1bd8b7de71a980ada +each thread has two associated timer slack values: +a "default" value, and a "current" value. +this operation sets the "current" timer slack value for the calling thread. +.i arg2 +is an unsigned long value, then maximum "current" value is ulong_max and +the minimum "current" value is 1. +if the nanosecond value supplied in +.ir arg2 +is greater than zero, then the "current" value is set to this value. +if +.i arg2 +is equal to zero, +the "current" timer slack is reset to the +thread's "default" timer slack value. +.ip +the "current" timer slack is used by the kernel to group timer expirations +for the calling thread that are close to one another; +as a consequence, timer expirations for the thread may be +up to the specified number of nanoseconds late (but will never expire early). +grouping timer expirations can help reduce system power consumption +by minimizing cpu wake-ups. +.ip +the timer expirations affected by timer slack are those set by +.br select (2), +.br pselect (2), +.br poll (2), +.br ppoll (2), +.br epoll_wait (2), +.br epoll_pwait (2), +.br clock_nanosleep (2), +.br nanosleep (2), +and +.br futex (2) +(and thus the library functions implemented via futexes, including +.\" list obtained by grepping for futex usage in glibc source +.br pthread_cond_timedwait (3), +.br pthread_mutex_timedlock (3), +.br pthread_rwlock_timedrdlock (3), +.br pthread_rwlock_timedwrlock (3), +and +.br sem_timedwait (3)). +.ip +timer slack is not applied to threads that are scheduled under +a real-time scheduling policy (see +.br sched_setscheduler (2)). +.ip +when a new thread is created, +the two timer slack values are made the same as the "current" value +of the creating thread. +thereafter, a thread can adjust its "current" timer slack value via +.br pr_set_timerslack . +the "default" value can't be changed. +the timer slack values of +.ir init +(pid 1), the ancestor of all processes, +are 50,000 nanoseconds (50 microseconds). +the timer slack value is inherited by a child created via +.br fork (2), +and is preserved across +.br execve (2). +.ip +since linux 4.6, the "current" timer slack value of any process +can be examined and changed via the file +.ir /proc/[pid]/timerslack_ns . +see +.br proc (5). +.\" prctl pr_get_timerslack +.tp +.br pr_get_timerslack " (since linux 2.6.28)" +return (as the function result) +the "current" timer slack value of the calling thread. +.\" prctl pr_set_timing +.tp +.br pr_set_timing " (since linux 2.6.0)" +.\" precisely: linux 2.6.0-test4 +set whether to use (normal, traditional) statistical process timing or +accurate timestamp-based process timing, by passing +.b pr_timing_statistical +.\" 0 +or +.b pr_timing_timestamp +.\" 1 +to \fiarg2\fp. +.b pr_timing_timestamp +is not currently implemented +(attempting to set this mode will yield the error +.br einval ). +.\" pr_timing_timestamp doesn't do anything in 2.6.26-rc8, +.\" and looking at the patch history, it appears +.\" that it never did anything. +.\" prctl pr_get_timing +.tp +.br pr_get_timing " (since linux 2.6.0)" +.\" precisely: linux 2.6.0-test4 +return (as the function result) which process timing method is currently +in use. +.\" prctl pr_set_tsc +.tp +.br pr_set_tsc " (since linux 2.6.26, x86 only)" +set the state of the flag determining whether the timestamp counter +can be read by the process. +pass +.b pr_tsc_enable +to +.i arg2 +to allow it to be read, or +.b pr_tsc_sigsegv +to generate a +.b sigsegv +when the process tries to read the timestamp counter. +.\" prctl pr_get_tsc +.tp +.br pr_get_tsc " (since linux 2.6.26, x86 only)" +return the state of the flag determining whether the timestamp counter +can be read, +in the location pointed to by +.ir "(int\ *) arg2" . +.\" prctl pr_set_unalign +.tp +.b pr_set_unalign +(only on: ia64, since linux 2.3.48; parisc, since linux 2.6.15; +powerpc, since linux 2.6.18; alpha, since linux 2.6.22; +.\" sh: 94ea5e449ae834af058ef005d16a8ad44fcf13d6 +.\" tile: 2f9ac29eec71a696cb0dcc5fb82c0f8d4dac28c9 +sh, since linux 2.6.34; tile, since linux 3.12) +set unaligned access control bits to \fiarg2\fp. +pass +\fbpr_unalign_noprint\fp to silently fix up unaligned user accesses, +or \fbpr_unalign_sigbus\fp to generate +.b sigbus +on unaligned user access. +alpha also supports an additional flag with the value +of 4 and no corresponding named constant, +which instructs kernel to not fix up +unaligned accesses (it is analogous to providing the +.br uac_nofix +flag in +.br ssi_nvpairs +operation of the +.br setsysinfo () +system call on tru64). +.\" prctl pr_get_unalign +.tp +.b pr_get_unalign +(see +.b pr_set_unalign +for information on versions and architectures.) +return unaligned access control bits, in the location pointed to by +.ir "(unsigned int\ *) arg2" . +.sh return value +on success, +.br pr_cap_ambient + pr_cap_ambient_is_set , +.br pr_capbset_read , +.br pr_get_dumpable , +.br pr_get_fp_mode , +.br pr_get_io_flusher , +.br pr_get_keepcaps , +.br pr_mce_kill_get , +.br pr_get_no_new_privs , +.br pr_get_securebits , +.br pr_get_speculation_ctrl , +.br pr_sve_get_vl , +.br pr_sve_set_vl , +.br pr_get_tagged_addr_ctrl , +.br pr_get_thp_disable , +.br pr_get_timing , +.br pr_get_timerslack , +and (if it returns) +.br pr_get_seccomp +return the nonnegative values described above. +all other +.i option +values return 0 on success. +on error, \-1 is returned, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b eacces +.i option +is +.br pr_set_seccomp +and +.i arg2 +is +.br seccomp_mode_filter , +but the process does not have the +.br cap_sys_admin +capability or has not set the +.ir no_new_privs +attribute (see the discussion of +.br pr_set_no_new_privs +above). +.tp +.b eacces +.i option +is +.br pr_set_mm , +and +.i arg3 +is +.br pr_set_mm_exe_file , +the file is not executable. +.tp +.b ebadf +.i option +is +.br pr_set_mm , +.i arg3 +is +.br pr_set_mm_exe_file , +and the file descriptor passed in +.i arg4 +is not valid. +.tp +.b ebusy +.i option +is +.br pr_set_mm , +.i arg3 +is +.br pr_set_mm_exe_file , +and this the second attempt to change the +.i /proc/pid/exe +symbolic link, which is prohibited. +.tp +.b efault +.i arg2 +is an invalid address. +.tp +.b efault +.i option +is +.br pr_set_seccomp , +.i arg2 +is +.br seccomp_mode_filter , +the system was built with +.br config_seccomp_filter , +and +.i arg3 +is an invalid address. +.tp +.b efault +.i option +is +.b pr_set_syscall_user_dispatch +and +.i arg5 +has an invalid address. +.tp +.b einval +the value of +.i option +is not recognized, +or not supported on this system. +.tp +.b einval +.i option +is +.br pr_mce_kill +or +.br pr_mce_kill_get +or +.br pr_set_mm , +and unused +.br prctl () +arguments were not specified as zero. +.tp +.b einval +.i arg2 +is not valid value for this +.ir option . +.tp +.b einval +.i option +is +.br pr_set_seccomp +or +.br pr_get_seccomp , +and the kernel was not configured with +.br config_seccomp . +.tp +.b einval +.i option +is +.br pr_set_seccomp , +.i arg2 +is +.br seccomp_mode_filter , +and the kernel was not configured with +.br config_seccomp_filter . +.tp +.b einval +.i option +is +.br pr_set_mm , +and one of the following is true +.rs +.ip * 3 +.i arg4 +or +.i arg5 +is nonzero; +.ip * +.i arg3 +is greater than +.b task_size +(the limit on the size of the user address space for this architecture); +.ip * +.i arg2 +is +.br pr_set_mm_start_code , +.br pr_set_mm_end_code , +.br pr_set_mm_start_data , +.br pr_set_mm_end_data , +or +.br pr_set_mm_start_stack , +and the permissions of the corresponding memory area are not as required; +.ip * +.i arg2 +is +.br pr_set_mm_start_brk +or +.br pr_set_mm_brk , +and +.i arg3 +is less than or equal to the end of the data segment +or specifies a value that would cause the +.b rlimit_data +resource limit to be exceeded. +.re +.tp +.b einval +.i option +is +.br pr_set_ptracer +and +.i arg2 +is not 0, +.br pr_set_ptracer_any , +or the pid of an existing process. +.tp +.b einval +.i option +is +.b pr_set_pdeathsig +and +.i arg2 +is not a valid signal number. +.tp +.b einval +.i option +is +.br pr_set_dumpable +and +.i arg2 +is neither +.b suid_dump_disable +nor +.br suid_dump_user . +.tp +.b einval +.i option +is +.br pr_set_timing +and +.i arg2 +is not +.br pr_timing_statistical . +.tp +.b einval +.i option +is +.br pr_set_no_new_privs +and +.i arg2 +is not equal to 1 +or +.ir arg3 , +.ir arg4 , +or +.ir arg5 +is nonzero. +.tp +.b einval +.i option +is +.br pr_get_no_new_privs +and +.ir arg2 , +.ir arg3 , +.ir arg4 , +or +.ir arg5 +is nonzero. +.tp +.b einval +.i option +is +.br pr_set_thp_disable +and +.ir arg3 , +.ir arg4 , +or +.ir arg5 +is nonzero. +.tp +.b einval +.i option +is +.br pr_get_thp_disable +and +.ir arg2 , +.ir arg3 , +.ir arg4 , +or +.ir arg5 +is nonzero. +.tp +.b einval +.i option +is +.b pr_cap_ambient +and an unused argument +.ri ( arg4 , +.ir arg5 , +or, +in the case of +.br pr_cap_ambient_clear_all , +.ir arg3 ) +is nonzero; or +.ir arg2 +has an invalid value; +or +.ir arg2 +is +.br pr_cap_ambient_lower , +.br pr_cap_ambient_raise , +or +.br pr_cap_ambient_is_set +and +.ir arg3 +does not specify a valid capability. +.tp +.b einval +.i option +was +.br pr_get_speculation_ctrl +or +.br pr_set_speculation_ctrl +and unused arguments to +.br prctl () +are not 0. +.b einval +.i option +is +.b pr_pac_reset_keys +and the arguments are invalid or unsupported. +see the description of +.b pr_pac_reset_keys +above for details. +.tp +.b einval +.i option +is +.b pr_sve_set_vl +and the arguments are invalid or unsupported, +or sve is not available on this platform. +see the description of +.b pr_sve_set_vl +above for details. +.tp +.b einval +.i option +is +.b pr_sve_get_vl +and sve is not available on this platform. +.tp +.b einval +.i option +is +.b pr_set_syscall_user_dispatch +and one of the following is true: +.rs +.ip * 3 +.i arg2 +is +.b pr_sys_dispatch_off +and the remaining arguments are not 0; +.ip * 3 +.i arg2 +is +.b pr_sys_dispatch_on +and the memory range specified is outside the +address space of the process. +.ip * 3 +.i arg2 +is invalid. +.re +.tp +.b einval +.i option +is +.br pr_set_tagged_addr_ctrl +and the arguments are invalid or unsupported. +see the description of +.b pr_set_tagged_addr_ctrl +above for details. +.tp +.b einval +.i option +is +.br pr_get_tagged_addr_ctrl +and the arguments are invalid or unsupported. +see the description of +.b pr_get_tagged_addr_ctrl +above for details. +.tp +.b enodev +.i option +was +.br pr_set_speculation_ctrl +the kernel or cpu does not support the requested speculation misfeature. +.tp +.b enxio +.i option +was +.br pr_mpx_enable_management +or +.br pr_mpx_disable_management +and the kernel or the cpu does not support mpx management. +check that the kernel and processor have mpx support. +.tp +.b enxio +.i option +was +.br pr_set_speculation_ctrl +implies that the control of the selected speculation misfeature is not possible. +see +.br pr_get_speculation_ctrl +for the bit fields to determine which option is available. +.tp +.b eopnotsupp +.i option +is +.b pr_set_fp_mode +and +.i arg2 +has an invalid or unsupported value. +.tp +.b eperm +.i option +is +.br pr_set_securebits , +and the caller does not have the +.b cap_setpcap +capability, +or tried to unset a "locked" flag, +or tried to set a flag whose corresponding locked flag was set +(see +.br capabilities (7)). +.tp +.b eperm +.i option +is +.br pr_set_speculation_ctrl +wherein the speculation was disabled with +.b pr_spec_force_disable +and caller tried to enable it again. +.tp +.b eperm +.i option +is +.br pr_set_keepcaps , +and the caller's +.b secbit_keep_caps_locked +flag is set +(see +.br capabilities (7)). +.tp +.b eperm +.i option +is +.br pr_capbset_drop , +and the caller does not have the +.b cap_setpcap +capability. +.tp +.b eperm +.i option +is +.br pr_set_mm , +and the caller does not have the +.b cap_sys_resource +capability. +.tp +.b eperm +.ir option +is +.br pr_cap_ambient +and +.ir arg2 +is +.br pr_cap_ambient_raise , +but either the capability specified in +.ir arg3 +is not present in the process's permitted and inheritable capability sets, +or the +.b pr_cap_ambient_lower +securebit has been set. +.tp +.b erange +.i option +was +.br pr_set_speculation_ctrl +and +.ir arg3 +is not +.br pr_spec_enable , +.br pr_spec_disable , +.br pr_spec_force_disable , +nor +.br pr_spec_disable_noexec . +.sh versions +the +.br prctl () +system call was introduced in linux 2.1.57. +.\" the library interface was added in glibc 2.0.6 +.sh conforming to +this call is linux-specific. +irix has a +.br prctl () +system call (also introduced in linux 2.1.44 +as irix_prctl on the mips architecture), +with prototype +.pp +.in +4n +.ex +.bi "ptrdiff_t prctl(int " option ", int " arg2 ", int " arg3 ); +.ee +.in +.pp +and options to get the maximum number of processes per user, +get the maximum number of processors the calling process can use, +find out whether a specified process is currently blocked, +get or set the maximum stack size, and so on. +.sh see also +.br signal (2), +.br core (5) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.so man3/nextup.3 + +.so man3/insque.3 + +.\" copyright 2001 andries brouwer . +.\" and copyright 2008, linux foundation, written by michael kerrisk +.\" +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.th ceil 3 2021-03-22 "" "linux programmer's manual" +.sh name +ceil, ceilf, ceill \- ceiling function: smallest integral value not +less than argument +.sh synopsis +.nf +.b #include +.pp +.bi "double ceil(double " x ); +.bi "float ceilf(float " x ); +.bi "long double ceill(long double " x ); +.fi +.pp +link with \fi\-lm\fp. +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br ceilf (), +.br ceill (): +.nf + _isoc99_source || _posix_c_source >= 200112l + || /* since glibc 2.19: */ _default_source + || /* glibc <= 2.19: */ _bsd_source || _svid_source +.fi +.sh description +these functions return the smallest integral value that is not less than +.ir x . +.pp +for example, +.ir ceil(0.5) +is 1.0, and +.ir ceil(\-0.5) +is 0.0. +.sh return value +these functions return the ceiling of +.ir x . +.pp +if +.i x +is integral, +0, \-0, nan, or infinite, +.i x +itself is returned. +.sh errors +no errors occur. +posix.1-2001 documents a range error for overflows, but see notes. +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br ceil (), +.br ceilf (), +.br ceill () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +c99, posix.1-2001, posix.1-2008. +.pp +the variant returning +.i double +also conforms to +svr4, 4.3bsd, c89. +.sh notes +susv2 and posix.1-2001 contain text about overflow (which might set +.i errno +to +.br erange , +or raise an +.b fe_overflow +exception). +in practice, the result cannot overflow on any current machine, +so this error-handling stuff is just nonsense. +.\" the posix.1-2001 application usage section discusses this point. +(more precisely, overflow can happen only when the maximum value +of the exponent is smaller than the number of mantissa bits. +for the ieee-754 standard 32-bit and 64-bit floating-point numbers +the maximum value of the exponent is 128 (respectively, 1024), +and the number of mantissa bits is 24 (respectively, 53).) +.pp +the integral value returned by these functions may be too large +to store in an integer type +.ri ( int , +.ir long , +etc.). +to avoid an overflow, which will produce undefined results, +an application should perform a range check on the returned value +before assigning it to an integer type. +.sh see also +.br floor (3), +.br lrint (3), +.br nearbyint (3), +.br rint (3), +.br round (3), +.br trunc (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/. + +.\" copyright 1993 david metcalfe (david@prism.demon.co.uk) +.\" +.\" %%%license_start(verbatim) +.\" permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" since the linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. the author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. the author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%license_end +.\" +.\" references consulted: +.\" linux libc source code +.\" lewine's _posix programmer's guide_ (o'reilly & associates, 1991) +.\" 386bsd man pages +.\" modified sun mar 28 00:25:51 1993, david metcalfe +.\" modified sat jul 24 18:13:39 1993 by rik faith (faith@cs.unc.edu) +.\" modified sun aug 20 21:47:07 2000, aeb +.\" +.th random 3 2021-03-22 "gnu" "linux programmer's manual" +.sh name +random, srandom, initstate, setstate \- random number generator +.sh synopsis +.nf +.b #include +.pp +.b long random(void); +.bi "void srandom(unsigned int " seed ); +.pp +.bi "char *initstate(unsigned int " seed ", char *" state ", size_t " n ); +.bi "char *setstate(char *" state ); +.fi +.pp +.rs -4 +feature test macro requirements for glibc (see +.br feature_test_macros (7)): +.re +.pp +.br random (), +.br srandom (), +.br initstate (), +.br setstate (): +.nf + _xopen_source >= 500 +.\" || _xopen_source && _xopen_source_extended + || /* glibc since 2.19: */ _default_source + || /* glibc <= 2.19: */ _svid_source || _bsd_source +.fi +.sh description +the +.br random () +function uses a nonlinear additive feedback random +number generator employing a default table of size 31 long integers to +return successive pseudo-random numbers in +the range from 0 to 2^31\ \-\ 1. +the period of this random number generator is very large, approximately +.ir "16\ *\ ((2^31)\ \-\ 1)" . +.pp +the +.br srandom () +function sets its argument as the seed for a new +sequence of pseudo-random integers to be returned by +.br random (). +these sequences are repeatable by calling +.br srandom () +with the same +seed value. +if no seed value is provided, the +.br random () +function +is automatically seeded with a value of 1. +.pp +the +.br initstate () +function allows a state array \fistate\fp to +be initialized for use by +.br random (). +the size of the state array +\fin\fp is used by +.br initstate () +to decide how sophisticated a +random number generator it should use\(emthe larger the state array, +the better the random numbers will be. +current "optimal" values for the size of the state array \fin\fp are +8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to +the nearest known amount. +using less than 8 bytes results in an error. +\fiseed\fp is the seed for the +initialization, which specifies a starting point for the random number +sequence, and provides for restarting at the same point. +.pp +the +.br setstate () +function changes the state array used by the +.br random () +function. +the state array \fistate\fp is used for +random number generation until the next call to +.br initstate () +or +.br setstate (). +\fistate\fp must first have been initialized +using +.br initstate () +or be the result of a previous call of +.br setstate (). +.sh return value +the +.br random () +function returns a value between 0 and +.ir "(2^31)\ \-\ 1" . +the +.br srandom () +function returns no value. +.pp +the +.br initstate () +function returns a pointer to the previous state array. +on failure, it returns null, and +.i errno +is set to indicate the error. +.pp +on success, +.br setstate () +returns a pointer to the previous state array. +on failure, it returns null, and +.i errno +is set to indicate the error. +.sh errors +.tp +.b einval +the +.i state +argument given to +.br setstate () +was null. +.tp +.b einval +a state array of less than 8 bytes was specified to +.br initstate (). +.sh attributes +for an explanation of the terms used in this section, see +.br attributes (7). +.ad l +.nh +.ts +allbox; +lbx lb lb +l l l. +interface attribute value +t{ +.br random (), +.br srandom (), +.br initstate (), +.br setstate () +t} thread safety mt-safe +.te +.hy +.ad +.sp 1 +.sh conforming to +posix.1-2001, posix.1-2008, 4.3bsd. +.sh notes +the +.br random () +function should not be used in multithreaded programs +where reproducible behavior is required. +use +.br random_r (3) +for that purpose. +.pp +random-number generation is a complex topic. +.i numerical recipes in c: the art of scientific computing +(william h.\& press, brian p.\& flannery, saul a.\& teukolsky, +william t.\& vetterling; new york: cambridge university press, 2007, 3rd ed.) +provides an excellent discussion of practical random-number generation +issues in chapter 7 (random numbers). +.pp +for a more theoretical discussion which also covers many practical issues +in depth, see chapter 3 (random numbers) in donald e.\& knuth's +.ir "the art of computer programming" , +volume 2 (seminumerical algorithms), 2nd ed.; reading, massachusetts: +addison-wesley publishing company, 1981. +.sh bugs +according to posix, +.br initstate () +should return null on error. +in the glibc implementation, +.i errno +is (as specified) set on error, but the function does not return null. +.\" http://sourceware.org/bugzilla/show_bug.cgi?id=15380 +.sh see also +.br getrandom (2), +.br drand48 (3), +.br rand (3), +.br random_r (3), +.br srand (3) +.sh colophon +this page is part of release 5.13 of the linux +.i 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/.