The only restrictions that the system adds to the pipeline and FIFO are:
1. Open_max the maximum number of descriptors that a process opens at any time. You can query by calling the Sysconf function.
2. Pipe_buf can be atomically written to the maximum amount of data in a pipe or FIFO. POSIX task It is a pathname variable whose value can vary with the specified pathname, because different pathname can fall on different file systems, and these file systems may have different characteristics. So pipe_buf can be obtained by pathconf function.
Pipeconf.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h>intmain (int argc, char **argv) {if (argc! = 2) printf ("usage:pipeconf <pathname>");p rintf ("pipe_buf =%ld, Open_max =%ld\n", pathconf (Argv[1], _pc_pipe_buf), Sysconf (_sc_open_max)); exit (0);}
Compiling: gcc pipeconf.c-o pipeconf
Run:./pipeconf
Results show: Pipe_buf = 4096, Open_max = 1024
The pipeline or FIFO can be set to non-blocking in two ways:
1. When you call open, you can specify the O_NONBLOCK flag.
WRITEFD = open (FIFO1, o_wronly | O_nonblock, 0);
2. If a descriptor is already open, call Fcntl to enable the O_nonblock flag. For pipelines, this technique must be used because the pipe does not have an open call and the O_NONBLOCK flag cannot be specified in the pipe call. When using FCNTL, use the F_GETFL command to get the current file status flag, place it with the O_NONBLOCK flag, or use the F_SETFL command to store these file status flags.
int flags;if (flags = FCNTL (FD, F_GETFL, 0) < 0)) Err_sys ("F_GETEFL error"); Flags |= o_nonblock;if ((flags = FCNTL (F D, F_SETFL, 0) < 0) Err_sys ("F_SETEFL error");