pipe2()

QNX SDP8.0C Library ReferenceAPIDeveloper

Create a pipe with additional control flags.

Synopsis:

#include <unistd.h>

int pipe2( int filedes[2], 
           int flags);

Arguments:

filedes
An array where the function can store the file descriptors for the ends of the pipe.
flags
Bitwise combination of two supported flags:
O_CLOEXEC
Closes both file descriptors on any of the exec*() calls or on posix_spawn().
O_NONBLOCK
Makes both file descriptors non-blocking.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The pipe2() function helps to:
  • Avoid extra calls to fcntl() after the pipe is created.
  • Close race conditions between the creation of the pipe and the setting of any of these flags.

If the flags value is 0 then pipe2() behaves exactly like pipe().

The pipe() function creates a pipe (an unnamed FIFO) and places a file descriptor for the read end of the pipe in filedes[0], and a file descriptor for the write end of the pipe in filedes[1]. Their integer values are the two lowest available at the time of the pipe() function call.

The pipe buffer is allocated by the pipe resource manager.

You typically use this function to connect standard utilities acting as filters, passing the write end of the pipe to the data-producing process as its STDOUT_FILENO, and the read end of the pipe to the data-consuming process as its STDIN_FILENO (either via the traditional fork(), dup2(), or exec*, or the more efficient spawn* calls).

If successful, pipe() marks the st_ftime, st_ctime, st_atime and st_mtime fields of the pipe for updating.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EINVAL
The flags argument is neither 0 nor a bitwise combination of the supported flags.
EMFILE
The calling process doesn't have at least two unused file descriptors available.
ENFILE
The number of simultaneously open files in the system would exceed the configured limit.
ENOSPC
There is insufficient space available to allocate the pipe buffer.
ENOSYS
There's no pipe manager running.
EROFS
The pipe pathname space is a read-only filesystem.

Classification:

POSIX 1003.1

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: