bglibs: selfpipe: Safe child exit management.

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Related Pages
- Examples

# selfpipe: Safe child exit management.

## Functions
int | selfpipe_init (void)
void | selfpipe_close (void)
void | selfpipe_catch_signal (int)

## Function Documentation

void selfpipe_catch_signal | ( | int | signal | ) |

Catch a signal and write it to the self-pipe.

This routine can be used with sig_*_catch() to send other signals through the self-pipe.

void selfpipe_close | ( | void |  | ) |

Shut down the self-pipe.

int selfpipe_init | ( | void |  | ) |

Set up a self-pipe for catching child exit events.

This function opens up a pipe within the program used to safely handle exiting child processes. Every time a child exits, a single byte is written to the pipe. The resulting file descriptor is statically assigned, so do not call this function more than once within a single program. The file descriptor is set to non-blocking mode to prevent blocking when reading from it.

To use the file descriptor, use either `poll` or `select` to determine when it is readable. When it becomes readable, read the data written to it (and throw it away), and use `wait` or equivalent to catch the `exit` value from the child process(es).

Returns:
  -1 if an error occurred, otherwise the return value is the file descriptor opened for reading.