IPC interprocess communication for Linux environment Programming (IV): Pipeline and FIFO comparison

Source: Internet
Author: User

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");



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.