ALPS Project: scheduler library

Header file scheduler/signal.hpp

This header contains a signal handler class.

Synopsis

namespace alps {
namespace scheduler {
class SignalHandler 
{
public:
  enum SignalInfo { NOSIGNAL, USER1, USER2, STOP, TERMINATE };

  SignalHandler();
   
  SignalInfo operator()(); 
  
  static void stopprocess();  
};
}
}

The SignalHandler class

SignalHandler();
The first time an object of type SignalHandler is constructed, it installs functions to catch the signals SIGINT, SIGQUIT, SIGTERM, SIGTSTP, SIGUSR1 and SIGUSR2 if they exist on the operating system. These signal handler remain installed until the program terminates. Any SignalHandler object allows inquiry about signal caught. Note that at the moment this is not thread-safe.
enum SignalInfo { NOSIGNAL, USER1, USER2, STOP, TERMINATE };
To ensure independence from the operating system the signals get mapped to type SignalInfo. The standard mapping on Unix-like operating systems is:
SignalSignalInfo
SIGINTTERMINATE
SIGQUITTERMINATE
SIGTERMTERMINATE
SIGTSTPSTOP
SIGUSR1USER1
SIGUSR2USER2
SignalInfo operator()(); 
returns a caught signal or NOSIGNAL if no signal was caught. If more than one signal was caught the signal with highest priority is returned first, where the priority decreases as USER1 > USER2 > STOP > TERMINATE. This allows user signals to be processed before the process is stopped or interrupted.
static void stopprocess();  
send its own process a noncatchable stop signal. This is useful to actually stop the process after intercepting a stop signal.

copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)