Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent IPC between Bash script and C++

Tags:

c++

linux

bash

ipc

Problem: There is a C application that calls a Bash script each time an event happens. And there is also a C++ application that needs to track down those events. The C++ application is driven by a select() event loop. What would be the most simplest IPC to implement between Bash script and C++ application?

C Application ---Each time calls Bash script---> Bash application ---???---> C++ Application

Few solutions that came into my mind:

  1. To use TCP networking sockets, but this would mean that select will have to handle events for both Listening and Actual sockets
  2. To use Named pipes, but once the bash script terminates then the other end of the pipe is closed as well

Is there something simpler that would allow me to use only one File Descriptor in select()?

like image 351
user389238 Avatar asked Aug 16 '11 17:08

user389238


1 Answers

Unix datagram or UDP socket would do. The bash script would just send a datagram to that socket (you may need a helper program that does sendmsg() or sendto() on that socket, such as socat or netcat/nc). The receiver does not need to accept connections for datagram sockets, once it is ready for read there must be a datagram waiting. Subject to datagram length restrictions.

like image 166
Maxim Egorushkin Avatar answered Sep 26 '22 01:09

Maxim Egorushkin