IPC using Signals on linux

Signals are intended to provide a rudimentary form of control over a process, not as an IPC mechanism. Signals have several issues when used as anything else:

  • A lot of system calls will be interrupted by a signal and need special handling.

  • Accordingly, a lot of code in the wild is not signal-safe.

  • Signals do not have any kind of data content, except for themselves. This makes them mostly useless as a message passing method.

  • There is only so much you can do in a signal handler.

  • Most importantly, subsequent signals of the same type are not queued - they are merged into one instance.

  • Even more important, there is no guarantee that signals are delivered in the same order as they were generated. From the manual page:

    By contrast, if multiple standard signals are pending for a process, the order in which they are delivered is unspecified.

You might theoretically be able set up some kind of channel using several signals going back and forth, with some acting like some sort of acknowledgement, but no sane person would want to attempt something like that. You might as well use smoke signals instead...


It is possible to do IPC (inter process communication) using signal catch and signal raise?

Yes and no. Considering signals only, you can send a signal to another process, but you can't send anything other than just a signal.

I want to pass messages with this signal also. Can i do it? It is possible?

No, not the way you're trying to. You can use sockets, files, pipes, or named pipes to do this. If you want to learn more about UNIX IPC, read Advanced Programming in the UNIX Environment.


No, don't try and use signals for this. You cannot attach extra data with signals other than the siginfo struct. The main problem with using signals though is that so little is signal safe. You have to avoid just about all the C runtime routines, and make sure the recieving program does EINTR checks on all its kernel calls. The only thing you can say about when a signal occurs is that it won't be when you expect it (a bit like the Spanish Inquisition).

I suggest you look into the other IPC mechanisms, such as shared memory, message queues, fifos (named pipes), and sockets.

Tags:

Linux

C

Ipc

Signals