123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- /*++
- Copyright (c) 2013 Minoca Corp.
- This file is licensed under the terms of the GNU Lesser General Public
- License version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details.
- Module Name:
- wait.h
- Abstract:
- This header contains definitions for obtaining information about a child
- process that has stopped or terminated.
- Author:
- Evan Green 30-Mar-2013
- --*/
- #ifndef _WAIT_H
- #define _WAIT_H
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <libcbase.h>
- #include <signal.h>
- #include <sys/resource.h>
- //
- // --------------------------------------------------------------------- Macros
- //
- #ifdef __cplusplus
- extern "C" {
- #endif
- //
- // Use this to get the exit status out of a child process.
- //
- #define WEXITSTATUS(_Status) (((_Status) & 0x0000FF00) >> 8)
- //
- // This macro evaluates to nonzero if the status indicates that the child has
- // been continued.
- //
- #define WIFCONTINUED(_Status) (((_Status) & 0xFFFF) == 0xFFFF)
- //
- // This macro evaluates to nonzero if the status indicates that the child has
- // exited.
- //
- #define WIFEXITED(_Status) (((_Status) & 0x7F) == 0)
- //
- // This macro evaluates to nonzero if the status indicates that the child has
- // exited due to an uncaught signal. This constant matches up to flags in
- // ksignals.h. The macro is looking to make sure that the lower 7 bits are not
- // all 0 (exited) and are not all 1 (continued or stopped).
- //
- #define WIFSIGNALED(_Status) (((((_Status) + 1) >> 1) & 0x7F) != 0)
- //
- // This macro evaluates to nonzero if the status indicates that the child has
- // stopped.
- //
- #define WIFSTOPPED(_Status) (((_Status) & 0xFF) == 0x7F)
- //
- // This macro returns the stop signal if the child was stopped.
- //
- #define WSTOPSIG(_Status) WEXITSTATUS(_Status)
- //
- // This macro returns the signal that caused the process to terminate, if it was
- // terminated.
- //
- #define WTERMSIG(_Status) ((_Status) & 0x7F)
- //
- // This macro evaluates to nonzero if the child process terminated and produced
- // a core dump file.
- //
- #define WCOREDUMP(_Status) ((_Status) & 0x80)
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Set this in the wait options to return immediately if no child process
- // information is available instead of the usual behavior of blocking until it
- // is.
- //
- #define WNOHANG 0x00000001
- //
- // Set this option to wait for a process that has just stopped.
- //
- #define WUNTRACED 0x00000002
- //
- // Set this option to wait for a process that has just continued.
- //
- #define WCONTINUED 0x00000004
- //
- // Set this option to wait for a process that has just exited.
- //
- #define WEXITED 0x00000008
- //
- // Set this option to keep the process whose status is returned in a waitable
- // state.
- //
- #define WNOWAIT 0x00000010
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // Define the ID type, which is used to identify whether an ID is a process ID,
- // process group ID, or neither.
- //
- typedef enum {
- P_ALL = 0,
- P_PID = 1,
- P_PGID = 2
- } idtype_t;
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // -------------------------------------------------------- Function Prototypes
- //
- LIBC_API
- pid_t
- wait (
- int *Status
- );
- /*++
- Routine Description:
- This routine obtains status information about one of the caller's
- terminated child processes. This routine blocks until such status
- information becomes available or until the calling process receives a
- terminating signal.
- Arguments:
- Status - Supplies an optional pointer where the child process' exit status
- information will be returned.
- Return Value:
- Returns the process ID of the child process that just experienced a state
- change.
- -1 on failure, and the errno variable will contain more information.
- --*/
- LIBC_API
- pid_t
- waitpid (
- pid_t ProcessId,
- int *Status,
- int Options
- );
- /*++
- Routine Description:
- This routine obtains status information about one of the caller's child
- processes. This routine can block waiting for any child process to change,
- or can wait for a specific process.
- Arguments:
- ProcessId - Supplies the process ID of the process to wait for. The
- various valid values are as follows:
- If equal to -1, then this routine will be equivalent to the original
- routine, it will return when any process has status information.
- If greater than 0, then the specific process ID will be waited for.
- If 0, then any child whose process process group ID is equal to that of
- the calling process will satisfy the wait.
- If less than negative one, then any child process whose process group ID
- is equal to the absolute value of this parameter will satisfy the
- wait.
- Status - Supplies an optional pointer where the child process' exit status
- information will be returned.
- Options - Supplies a bitfield of options. This field may contain one or
- more of the following options:
- WCONTINUED - Wait for a process that just continued.
- WNOHANG - Return immediately if no child process information is
- currently available.
- WUNTRACED - Wait for a process that just stopped.
- Return Value:
- Returns the process ID of the child process that just experienced a state
- change.
- -1 on failure, and the errno variable will contain more information.
- --*/
- LIBC_API
- int
- waitid (
- idtype_t IdentifierType,
- id_t ProcessOrGroupIdentifier,
- siginfo_t *SignalInformation,
- int Options
- );
- /*++
- Routine Description:
- This routine suspends execution until a child process of this process
- changes state.
- Arguments:
- IdentifierType - Supplies a value indicating whether the process or group
- identifier identifies a process, group, or nothing. If nothing, then
- any child process changing state will satisfy the wait.
- ProcessOrGroupIdentifier - Supplies a process or process group identifier
- to wait for. If the identifier type indicates neither, then this
- parameter is ignored.
- SignalInformation - Supplies a pointer where the child signal information
- will be returned.
- Options - Supplies a bitfield of options. Valid values are WEXITED,
- WSTOPPED, WCONTINUED, WNOHANG, and WNOWAIT. One or more of WEXITED,
- WSTOPPED or WCONTINUED must be supplied.
- Return Value:
- 0 if WNOHANG was specified and no child was waiting to report status
- information.
- 0 on success (child information was returned).
- -1 on failure, and the errno variable will be set to indicate the error.
- --*/
- LIBC_API
- pid_t
- wait3 (
- int *Status,
- int Options,
- struct rusage *ResourceUsage
- );
- /*++
- Routine Description:
- This routine is equivalent to the wait function, except it can obtain
- resource usage about the reaped child. This function is provided for
- compatibility with existing applications. New applications should use the
- waitpid function.
- Arguments:
- Status - Supplies an optional pointer where the child process' exit status
- information will be returned.
- Options - Supplies a bitfield of options. See the waitpid function for
- more details.
- ResourceUsage - Supplies an optional pointer where the resource usage of
- the process will be returned on success.
- Return Value:
- Returns the process ID of the child process that just experienced a state
- change.
- -1 on failure, and the errno variable will contain more information.
- --*/
- LIBC_API
- pid_t
- wait4 (
- pid_t ProcessId,
- int *Status,
- int Options,
- struct rusage *ResourceUsage
- );
- /*++
- Routine Description:
- This routine is equivalent to the waitpid function, except it can obtain
- resource usage about the reaped child. This function is provided for
- compatibility with existing applications. New applications should use the
- waitpid function.
- Arguments:
- ProcessId - Supplies the process ID to wait for. See waitpid for more
- information.
- Status - Supplies an optional pointer where the child process' exit status
- information will be returned.
- Options - Supplies a bitfield of options. See the waitpid function for
- more details.
- ResourceUsage - Supplies an optional pointer where the resource usage of
- the process will be returned on success.
- Return Value:
- Returns the process ID of the child process that just experienced a state
- change.
- -1 on failure, and the errno variable will contain more information.
- --*/
- #ifdef __cplusplus
- }
- #endif
- #endif
|