Two-way Communication between processes-- sockpair
Sockpair is a socket that can be used for network communication as well as local inter-process communication.
Sockpair is similar to pipes, except that pipes are used for one-way communication and can only be read on one side and written on the other. If you want to use it for two-way communication between processes, you need to pipe twice and create two pipes. Sockpair can directly realize two-way communication between processes.
1 # include 2 # include 3 # include 4 # include 5 # include 6 # include 7 int main () 8 {9 int fd [2] = {0 int sock 0}; 10 int sock = socketpair (AF_LOCAL,SOCK_STREAM,0,fd); 11 if (sock)