Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


F_GETSIG(2const) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |STANDARDS |HISTORY |BUGS |SEE ALSO |COLOPHON

F_GETSIG(2const)F_GETSIG(2const)

NAME        top

       F_GETOWN, F_SETOWN, F_GETOWN_EX, F_SETOWN_EX, F_GETSIG, F_SETSIG -       managing signals

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <fcntl.h>int fcntl(intfd, F_GETOWN);int fcntl(intfd, F_SETOWN, intarg);#define _GNU_SOURCE#include <fcntl.h>int fcntl(intfd, F_GETOWN_EX, struct f_owner_ex *arg);int fcntl(intfd, F_SETOWN_EX, const struct f_owner_ex *arg);int fcntl(intfd, F_GETSIG);int fcntl(intfd, F_SETSIG, intarg);

DESCRIPTION        top

F_GETOWN,F_SETOWN,F_GETOWN_EX,F_SETOWN_EX,F_GETSIG, andF_SETSIGare used to manage I/O availability signals:F_GETOWN              Return (as the function result) the process ID or process              group ID currently receivingSIGIOandSIGURGsignals for              events on file descriptorfd.  Process IDs are returned as              positive values; process group IDs are returned as negative              values (but see BUGS below).arg is ignored.F_SETOWN              Set the process ID or process group ID that will receiveSIGIOandSIGURGsignals for events on the file descriptorfd.  The target process or process group ID is specified inarg.  A process ID is specified as a positive value; a              process group ID is specified as a negative value.  Most              commonly, the calling process specifies itself as the owner              (that is,arg is specified asgetpid(2)).              As well as setting the file descriptor owner, one must also              enable generation of signals on the file descriptor.  This              is done by using theF_SETFL(2const) operation to set theO_ASYNCfile status flag on the file descriptor.              Subsequently, aSIGIOsignal is sent whenever input or              output becomes possible on the file descriptor.  Thefcntl()F_SETSIGoperation can be used to obtain delivery              of a signal other thanSIGIO.              Sending a signal to the owner process (group) specified byF_SETOWNis subject to the same permissions checks as are              described forkill(2), where the sending process is the one              that employsF_SETOWN(but see BUGS below).  If this              permission check fails, then the signal is silently              discarded.Note: TheF_SETOWNoperation records the              caller's credentials at the time of thefcntl() call, and              it is these saved credentials that are used for the              permission checks.              If the file descriptorfd refers to a socket,F_SETOWNalso              selects the recipient ofSIGURGsignals that are delivered              when out-of-band data arrives on that socket.  (SIGURGis              sent in any situation whereselect(2) would report the              socket as having an "exceptional condition".)              The following was true in Linux 2.6.x up to and including              Linux 2.6.11:                     If a nonzero value is given toF_SETSIGin a                     multithreaded process running with a threading                     library that supports thread groups (e.g., NPTL),                     then a positive value given toF_SETOWNhas a                     different meaning: instead of being a process ID                     identifying a whole process, it is a thread ID                     identifying a specific thread within a process.                     Consequently, it may be necessary to passF_SETOWN                     the result ofgettid(2) instead ofgetpid(2) to get                     sensible results whenF_SETSIGis used.  (In current                     Linux threading implementations, a main thread's                     thread ID is the same as its process ID.  This means                     that a single-threaded program can equally usegettid(2) orgetpid(2) in this scenario.)  Note,                     however, that the statements in this paragraph do                     not apply to theSIGURGsignal generated for out-of-                     band data on a socket: this signal is always sent to                     either a process or a process group, depending on                     the value given toF_SETOWN.              The above behavior was accidentally dropped in Linux              2.6.12, and won't be restored.  From Linux 2.6.32 onward,              useF_SETOWN_EXto targetSIGIOandSIGURGsignals at a              particular thread.F_GETOWN_EX              Return the current file descriptor owner settings as              defined by a previousF_SETOWN_EXoperation.  The              information is returned in the structure pointed to byarg,              which has the following form:                  struct f_owner_ex {                      int   type;                      pid_t pid;                  };              Thetype field will have one of the valuesF_OWNER_TID,F_OWNER_PID, orF_OWNER_PGRP.  Thepid field is a positive              integer representing a thread ID, process ID, or process              group ID.  SeeF_SETOWN_EXfor more details.F_SETOWN_EX              This operation performs a similar task toF_SETOWN.  It              allows the caller to direct I/O availability signals to a              specific thread, process, or process group.  The caller              specifies the target of signals viaarg, which is a pointer              to af_owner_ex structure.  Thetype field has one of the              following values, which define howpid is interpreted:F_OWNER_TID                     Send the signal to the thread whose thread ID (the                     value returned by a call toclone(2) orgettid(2))                     is specified inpid.F_OWNER_PID                     Send the signal to the process whose ID is specified                     inpid.F_OWNER_PGRP                     Send the signal to the process group whose ID is                     specified inpid.  (Note that, unlike withF_SETOWN,                     a process group ID is specified as a positive value                     here.)F_GETSIG              Return (as the function result) the signal sent when input              or output becomes possible.  A value of zero meansSIGIOis              sent.  Any other value (includingSIGIO) is the signal sent              instead, and in this case additional info is available to              the signal handler if installed withSA_SIGINFO.arg is              ignored.F_SETSIG              Set the signal sent when input or output becomes possible              to the value given inarg.  A value of zero means to send              the defaultSIGIOsignal.  Any other value (includingSIGIO) is the signal to send instead, and in this case              additional info is available to the signal handler if              installed withSA_SIGINFO.              By usingF_SETSIGwith a nonzero value, and settingSA_SIGINFOfor the signal handler (seesigaction(2)), extra              information about I/O events is passed to the handler in asiginfo_t structure.  If thesi_code field indicates the              source isSI_SIGIO, thesi_fd field gives the file              descriptor associated with the event.  Otherwise, there is              no indication which file descriptors are pending, and you              should use the usual mechanisms (select(2),poll(2),read(2) withO_NONBLOCKset etc.) to determine which file              descriptors are available for I/O.              Note that the file descriptor provided insi_fd is the one              that was specified during theF_SETSIGoperation.  This can              lead to an unusual corner case.  If the file descriptor is              duplicated (dup(2) or similar), and the original file              descriptor is closed, then I/O events will continue to be              generated, but thesi_fd field will contain the number of              the now closed file descriptor.              By selecting a real time signal (value >=SIGRTMIN),              multiple I/O events may be queued using the same signal              numbers.  (Queuing is dependent on available memory.)              Extra information is available ifSA_SIGINFOis set for the              signal handler, as above.              Note that Linux imposes a limit on the number of real-time              signals that may be queued to a process (seegetrlimit(2)              andsignal(7)) and if this limit is reached, then the              kernel reverts to deliveringSIGIO, and this signal is              delivered to the entire process rather than to a specific              thread.       Using these mechanisms, a program can implement fully asynchronous       I/O without usingselect(2) orpoll(2) most of the time.       The use ofO_ASYNCis specific to BSD and Linux.  The only use ofF_GETOWNandF_SETOWNspecified in POSIX.1 is in conjunction with       the use of theSIGURGsignal on sockets.  (POSIX does not specify       theSIGIOsignal.)F_GETOWN_EX,F_SETOWN_EX,F_GETSIG, andF_SETSIGare Linux-specific.  POSIX has asynchronous I/O and theaio_sigevent structure to achieve similar things; these are also       available in Linux as part of the GNU C Library (glibc).

RETURN VALUE        top

       Seefcntl(2).F_GETOWN              Value of file descriptor owner.F_GETSIG              Value of signal sent when read or write becomes possible,              or zero for traditionalSIGIObehavior.F_SETOWNF_GETOWN_EXF_SETOWN_EXF_SETSIG              Zero.       On error, -1 is returned, anderrno is set to indicate the error.

ERRORS        top

       Seefcntl(2).EINVALop isF_SETSIGandarg is not an allowable signal number.

STANDARDS        top

F_GETOWNF_SETOWN              POSIX.1-2008.F_GETOWN_EXF_SETOWN_EXF_GETSIGF_SETSIG              Linux.  (Define the_GNU_SOURCEmacro to obtain these              definitions.)

HISTORY        top

F_GETOWNF_SETOWN              POSIX.1-2001.  (To get their definitions, define either_XOPEN_SOURCEwith the value 500 or greater, or_POSIX_C_SOURCEwith the value 200809L or greater.)F_GETOWN_EXF_GETOWN_EX              Linux 2.6.32.F_GETSIGF_GETSIG              Linux.

BUGS        top

F_GETOWN       A limitation of the Linux system call conventions on some       architectures (notably i386) means that if a (negative) process       group ID to be returned byF_GETOWNfalls in the range -1 to       -4095, then the return value is wrongly interpreted by glibc as an       error in the system call; that is, the return value offcntl()       will be -1, anderrno will contain the (positive) process group       ID.  The Linux-specificF_GETOWN_EXoperation avoids this problem.       Since glibc 2.11, glibc makes the kernelF_GETOWNproblem       invisible by implementingF_GETOWNusingF_GETOWN_EX.F_SETOWN       In Linux 2.4 and earlier, there is bug that can occur when an       unprivileged process usesF_SETOWNto specify the owner of a       socket file descriptor as a process (group) other than the caller.       In this case,fcntl() can return -1 witherrno set toEPERM, even       when the owner process (group) is one that the caller has       permission to send signals to.  Despite this error return, the       file descriptor owner is set, and signals will be sent to the       owner.

SEE ALSO        top

fcntl(2)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-07-20F_GETSIG(2const)

Pages that refer to this page:fcntl(2)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp