x
Loading
 Loading
Hello, Guest | Login | Register

How to Make Use of Signals When Writing Linux Applications

Let me start off with a correction (sigh). Last month I described the difference between slow and fast system calls and then described select() as a slow system call. That was incorrect. Since select() takes a timeout value, it always returns in a predictable amount of time, so it’s considered a fast system call.

Let me start off with a correction (sigh). Last month I described the difference between slow and fast system calls and then described select() as a slow system call. That was incorrect. Since select() takes a timeout value, it always returns in a predictable amount of time, so it’s considered a fast system call.

I spent my last column giving an overview of the role signals play in the Linux system-call API and explaining the different ways signals could be handled by the kernel. Now that the background information is out of the way, I’ll describe how to make use of signals in Linux applications. I’m going to describe only the POSIX signal API; it has all the richness you need and is portable. Legacy applications should be rewritten to use it because it’s the best-defined signal API.

The data type that the signal functions rely on is called sigset_t. It represents a set of signals. If you remember fd_set you’ll notice that sigset_t is quite similar. Every signal is either contained in or absent from each sigset_t you use, which lets programs use sigset_t to easily pass a list of signals to the kernel. You should never manipulate a sigset_t object directly; always use the following functions:

 int sigemptyset(sigset_t * set); int sigfillset(sigset_t * set); int sigaddset(sigset_t * set, int signo); int sigdelset(sigset_t * set, int signo); int sigismember(const sigset_t * set, int signo); 

The first argument to all of these…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace