The usage case is that one application generates an event and sends out a signal that any application that cares to listen for it will get. E.g. an application updates the contents of a file and signals this. On Linux this could be done by the waiters calling inotify on the file. One portable way would be for listeners to register with a well-known server, but I would prefer something simpler if possible. As portable as possible ideally means using only POSIX features which are also widely available.
You can do this by locking a file.
Signal emitter initial setup:
fcntl(F_SETLK)
with F_WRLCK
or flock(LOCK_EX)`).Signal receiver procedure:
fcntl(F_SETLK)
with F_RDLCK
or flock(LOCK_SH)
).Signal emission:
In the signal emitter, the temporary lock file which has been renamed over top of the original lock file now becomes the new current lock file.
Have the receivers join a multicast group and wait for packets. Have the signal emitter send UDP packets to that multicast group.
You can bind both the sending and receiving UDP sockets to the loopback interface if you want it to use only host-local communication.