Named Pipes for interprocess communication

Source: Internet
Author: User

Named Pipes (FIFO) is a way of interprocess communication, with the following demo:

//Write ProcessintMainintargcChar**argv) {    CharFilename[] ="/tmp/my_fifo"; if(Mkfifo (filename,0777) <0) {perror ("Mkfifo Error"); Exit (1); }    intFD =open (filename, o_wronly); Charbuffer[ -] ="Hello World";    Write (fd, buffer, strlen (buffer)); printf ("Write done\n"); return 0;}//Read ProcessintMainintargcChar**argv) {    CharFilename[] ="/tmp/my_fifo"; intFD =open (filename, o_rdonly); Charbuffer[ -]; intn = read (fd, buffer, -); Buffer[n]=' /'; printf ("input is:%s\n", buffer); return 0;}

Two places to be aware of:

1. Mkfifo will create the file in the/tmp directory MY_FIFO

2. The write process is blocked before the read process open

(It has-to-be-open at both ends simultaneously before-can proceed to does any input or output operations on it.)

Named pipes can be used for communication between any of the two processes, compared to a pipeline.

Named Pipes for interprocess communication

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.