Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Socketpair implements interprocess communication and redirection in advanced IO

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report