TCP/IP network programming (transcription note 4)--Pipelines: interprocess communication

Source: Internet
Author: User

<title>TCP/IP network programming (transcription note 4) – Pipeline: interprocess communication</title> TCP/IP network programming (transcription note 4) – Pipeline: interprocess communication
int fds[2];p ipe (FDS); write (fds[1], buf, strlen (BUF)); Read (Fds[0], buf, buf_size);

If the communication of two processes is simply written by one side, then the other party reads the case, then our pipeline operation is no problem, but:

Char str1 "str1"; Char str2 "str2"; int FDS [2];p ipe (FDS); if (PID = = 0) {        read (fds[0], buf1, buf_size);        These two read requests can cause problems, time-sequential questions        else {        write (fds[1], str2, strlen (str2));        Read (Fds[0], buf2, buf_size);        These two read requests can cause problems, time-related issues }

FIX: Create 2 pipelines for communication

Examples of piping usage

PID = fork (); if (PID = = 0) {    read (fds[0], buf, buf_size);     Do Else {    ...    Write (Fds[1], buf, strlen (BUF));    ...}

The benefit of doing this is that if we start with "do other things" in the parent process, the processing is OK, but this increases
The burden of the parent process, if we open a sub-process to read the pipeline data, then this "parent process can be freed from the dirty work"

TCP/IP network programming (transcription note 4)--Pipelines: 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.