Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Socketpair implements interprocess communication and redirection in advanced IO

Shulou Source: shulou.com Published: 2022-06-01 04:43:32 09月29日 Update

Realization of Interprocess Communication with sockpair

We have previously learned to use pipes (anonymous pipes here) to achieve inter-process communication, which can only be one-way, one side can only read and the other can only write, and can only communicate between processes that are related by consanguine. if we want to achieve two-way communication, we must create two-way pipes, and the implementation of sockpair is two-way pipes for communication. It can be used to create a two-way communication pipeline.

1 # include 2 # include 3 # include 4 # include 5 # include 6 # include 7 # include 8 9 int main () 10 {11 int sv [2] = {0if 0}; 12 char buf [1024]; 13 int sock_pair=socketpair (AF_LOCAL,SOCK_STREAM,0,sv); 14 if (sock_pair < 0) 15 {16 perror ("socketpair"); 17 exit (1); 18} 19 pid_t id=fork (); 20 if (id)

Tags: File process standard content communication pipeline output bidirectional input terminal procedure that is function one-way prototype example factor that is program result Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS MySQL Shulou Technology OPPO Reno