O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Alternate ways to be safe within a signal handler

What if we must access some global state within our signal handler routine? There do exist some alternate ways of making it signal-safe:

  • At the point you must access these variables, ensure that all signals are blocked (or masked), and, once done, restore the signal state (unmask).
  • Perform some kind of locking on shared data while accessing it.
    • In multiprocess applications (the case we are talking about here), (binary) semaphores can be used as a locking mechanism to protect shared data across processes.
    • In multithreaded applications, the use of an appropriate locking mechanism (mutex locks, perhaps; we shall, of course, cover this in a later chapter in detail).
  • If your requirement is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required