Tuesday, October 21, 2008

Operating Systems: UNIX: Realtime Signals pointer payload option

So I have been working with real-time signals on Linux. I wanted a way to have two processes signal each other and be able to pass some data in addition to the actual signal. The way this works is to use the int sigqueue(pid_t pid, int signo, const union sigval value); system call to send a signal. The usual parameters are in play here and obvious (pid,signo). What I found interesting is how the value parameter is specified.

The union sigval has the following members:

    int sival_int;  // a simple integer value
void *sival_ptr; // a pointer

The sival_in met my needs, but I then got curious as to how one would/could use the pointer value instead. According to the documentation, sival_ptr enables the sending process to send a pointer to the receiving process. This confused me at first glance because both processes would have their own address space, so an address in one is not the same in another. One possiblitly could be if the two processes had a shared memory region between them. But even then, I might just pass an index to that region (via the sival_int) union member and have the receiving process then go lookup the correct address of the shared memory address.

Anyone have any experiance with sival_ptr ? Any idea what the original intent of this field was ?

1 comment:

St. Mayhem said...

My guess would be for in-process use of signals (somewhat like the use of signals for "alarm" notifications), where you wanted to communicate something like the address of some buffer/object/whatever that was ready for use.

Alternatively, this could be for indicating control/data registers for hardware access that tied to a given address in memory.

But I would bet that most folks aren't using this option for much....