Wednesday, June 17, 2009

The virtue of documenting obscure behavior

In the hope that people in the same situation as me can find this through google: Some shells run signal(SIGINT, SIG_IGN) before they execute your program if you run it in the background. This interferes with sigwait.

I think the reason for this is dubious implementation of background processes. Instead of checking which processes are background process and foreground processes, and only sending SIGINT to the foreground processes, the background processes are told to ignore SIGINT, and the signal is sent to all processes when ^C is received.

You can clear this by putting signal(SIGINT, SIG_DFL) in the beginning of your program, if you want it to behave like a regular foreground process, despite being run in the background.

This is a quite poorly documented fact, that took major hair-pulling to deduce. There are two lessons to be learned:
  1. Don't make assumptions about the standard behavior of anything.
  2. Document obscure behavior.

Thus endeth the frustrated rant.

No comments:

Post a Comment