Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


waitid(3p) — Linux manual page

PROLOG |NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLES |APPLICATION USAGE |RATIONALE |FUTURE DIRECTIONS |SEE ALSO |COPYRIGHT

WAITID(3P)              POSIX Programmer's ManualWAITID(3P)

PROLOG        top

       This manual page is part of the POSIX Programmer's Manual.  The       Linux implementation of this interface may differ (consult the       corresponding Linux manual page for details of Linux behavior), or       the interface may not be implemented on Linux.

NAME        top

       waitid — wait for a child process to change state

SYNOPSIS        top

       #include <sys/wait.h>       int waitid(idtype_tidtype, id_tid, siginfo_t *infop, intoptions);

DESCRIPTION        top

       Thewaitid() function shall obtain status information (seeSection2.13,Status Information) pertaining to termination, stop, and/or       continue events in one of the caller's child processes.       Thewaitid() function shall cause the calling thread to become       blocked until an error occurs or status information becomes       available to the calling thread that satisfies all of the       following properties (``matching status information''):        *  The status information is from one of the child processes in           the set of child processes specified by theidtype andid           arguments.        *  The state change in the status information matches one of the           state change flags set in theoptions argument.       If matching status information is available prior to the call towaitid(), return shall be immediate. If matching status       information is available for two or more child processes, the       order in which their status is reported is unspecified.       As described inSection 2.13,Status Information, thewaitid()       function consumes the status information it obtains unless the       WNOWAIT flag is set in theoptions argument.       The behavior when multiple threads are blocked inwait(),waitid(), orwaitpid() is described inSection 2.13,StatusInformation.       Thewaitid() function shall record the obtained status information       in the structure pointed to byinfop.  The fields of the structure       pointed to byinfop shall be filled in as described under       ``Pointer to a Function'' inSection 2.4.3,Signal Actions.       Theidtype andid arguments are used to specify which childrenwaitid() waits for.       Ifidtype is P_PID,waitid() shall wait for the child with a       process ID equal to (pid_t)id.       Ifidtype is P_PGID,waitid() shall wait for any child with a       process group ID equal to (pid_t)id.       Ifidtype is P_ALL,waitid() shall wait for any children andid is       ignored.       Theoptions argument is used to specify which state changeswaitid() shall wait for. It is formed by OR'ing together the       following flags:       WCONTINUED  Status shall be returned for any continued child                   process whose status either has not been reported                   since it continued from a job control stop or has been                   reported only by calls towaitid() with the WNOWAIT                   flag set.       WEXITED     Wait for processes that have exited.       WNOHANG     Do not hang if no status is available; return                   immediately.       WNOWAIT     Keep the process whose status is returned ininfop in                   a waitable state. This shall not affect the state of                   the process; the process may be waited for again after                   this call completes.       WSTOPPED    Status shall be returned for any child that has                   stopped upon receipt of a signal, and whose status                   either has not been reported since it stopped or has                   been reported only by calls towaitid() with the                   WNOWAIT flag set.       Applications shall specify at least one of the flags WEXITED,       WSTOPPED, or WCONTINUED to be OR'ed in with theoptions argument.       The application shall ensure that theinfop argument points to asiginfo_tstructure. Ifwaitid() returns because a child process       was found that satisfied the conditions indicated by the argumentsidtype andoptions, then the structure pointed to byinfop shall       be filled in by the system with the status of the process; thesi_signo member shall be set equal to SIGCHLD.  Ifwaitid()       returns because WNOHANG was specified and status is not available       for any process specified byidtype andid, then thesi_signo andsi_pid members of the structure pointed to byinfop shall be set       to zero and the values of other members of the structure are       unspecified.

RETURN VALUE        top

       If WNOHANG was specified and status is not available for any       process specified byidtype andid, 0 shall be returned. Ifwaitid() returns due to the change of state of one of its       children, 0 shall be returned. Otherwise, -1 shall be returned anderrno set to indicate the error.

ERRORS        top

       Thewaitid() function shall fail if:ECHILDThe calling process has no existing unwaited-for child              processes.EINTRThewaitid() function was interrupted by a signal.EINVALAn invalid value was specified foroptions, oridtype andid specify an invalid set of processes.The following sections are informative.

EXAMPLES        top

       None.

APPLICATION USAGE        top

       Calls towaitid() withidtype equal to P_ALL will collect       information about any child process. This may result in       interactions with other interfaces that may be waiting for their       own children (such as by use ofsystem()).  For this reason it is       recommended that portable applications not usewaitid() with       idtype of P_ALL. See also APPLICATION USAGE forwait().       As specified inConsequences of Process Termination, if the       calling process has SA_NOCLDWAIT set or has SIGCHLD set to       SIG_IGN, then the termination of a child process will not cause       status information to become available to a thread blocked inwait(),waitid(), orwaitpid().  Thus, a thread blocked in one of       the wait functions will remain blocked unless some other condition       causes the thread to resume execution (such as an[ECHILD]failure       due to no remaining children in the set of waited-for children).

RATIONALE        top

       None.

FUTURE DIRECTIONS        top

       None.

SEE ALSO        top

Section 2.4.3,Signal Actions,Section 2.13,Status Information,exec(1p),exit(3p),wait(3p)       The Base Definitions volume of POSIX.1‐2017,signal.h(0p),sys_wait.h(0p)

COPYRIGHT        top

       Portions of this text are reprinted and reproduced in electronic       form from IEEE Std 1003.1-2017, Standard for Information       Technology -- Portable Operating System Interface (POSIX), The       Open Group Base Specifications Issue 7, 2018 Edition, Copyright       (C) 2018 by the Institute of Electrical and Electronics Engineers,       Inc and The Open Group.  In the event of any discrepancy between       this version and the original IEEE and The Open Group Standard,       the original IEEE and The Open Group Standard is the referee       document. The original Standard can be obtained online athttp://www.opengroup.org/unix/online.html .       Any typographical or formatting errors that appear in this page       are most likely to have been introduced during the conversion of       the source files to man page format. To report such errors, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html .IEEE/The Open Group                2017WAITID(3P)

Pages that refer to this page:signal.h(0p)sys_wait.h(0p)abort(3p)exit(3p)_Exit(3p)popen(3p)posix_spawn(3p)sigaction(3p)sighold(3p)signal(3p)times(3p)wait(3p)



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