<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
The benefits of piping
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