Skip to content
Advertisement

How do I install a signal handler for a custom I/O signal?

I am trying to set up a signal and signal handler to rebuffer CAN frames as they arrive. Below is my code. I can send a frame from the computer running this code, but when I send a frame back the other way, nothing happens. I am holding the programme with scanf(). Can you see why this signal handler is never called?

Admission of guilt: I tailored this code very little from some tutorial. I’ve read the relevent manual pages, but I’m a socket noob.

JavaScript

Advertisement

Answer

On Linux at least, and perhaps other platforms, F_SETOWN is required for F_SETFL/O_ASYNC to take effect: you must specify the recipient pid of the signal. See, for example, a similar situation in Perl.

For your C code, then, you’d want something like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement