Reliable bidirectional communication with the Linux process?

What is a reliable way to implement bidirectional communication with a Linux process?

I see that popen doesn't seem to support "r" and "w" at the same time ... or at least that is implied:

The type argument is a pointer to a null-terminated string which must be either 'r' for reading or 'w' for writing.

(I'm so losing Erlang at the moment)

+2
source share
2 answers

Unix domain sockets are your friend.

A Unix domain connector or an IPC socket (interprocess communication socket) is a data transfer endpoint that is similar to an Internet socket but does not use a network protocol for communication. It is used in POSIX operating systems for interprocess communication communication.

You reserve a name for your communication channel, for example /myapp/ipc , and then both processes open this address using a UNIX socket:

 struct sockaddr_un local; int len; s = socket(AF_UNIX, SOCK_STREAM, 0); local.sun_family = AF_UNIX; strcpy(local.sun_path, "/myapp/ipc"); len = strlen(local.sun_path) + sizeof(local.sun_family); bind(s, (struct sockaddr *)&local, len); 

Now you can use listen or connect or something else in the socket family. This works a little, but it is the best way to achieve IPC on Linux.

Since Erlang is just a good language for specifying small servers (processes) that exchange data over named pipes (processes), this model should feel comfortable for you.

+8
source

Good old TCP / IP connections always worked well for me.

+2
source

Source: https://habr.com/ru/post/1399585/


All Articles