Skip to content
Signal handler for multithreaded C++ applications on Linux
C++ CMake
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
cmake
example
include/sgnl
test
CMakeLists.txt
LICENSE
README.md

README.md

Signal handler for multithreaded C++ applications on Linux

Signal handler that uses pthread_sigmask and sigwait.

Dependencies

  • C++17
  • Clang or GCC
  • linux
  • pthread
  • cmake (recommended, but optional)
  • Catch2 for testing

Example usage

{
  // Block signals
  sgnl::SignalHandler signal_handler({SIGINT, SIGTERM});

  // Wait for a signal
  int signal_number = signal_handler.sigwait();

  // Or, pass a handler
  auto handler = [](int signum) {
    if( signum == SIGINT )
      // continue waiting for signals
      return false;
    if( signum == SIGTERM )
      // stop waiting for signals
      return true;
  };

  int last_signal = signal_handler.sigwait_handler(handler);
} // signals are unblocked again

See example.cpp for an example using threads.

Build & Install

mkdir -p build/ && cd build/
cmake ..
# build and run tests
make sgnl-test && ./test/sgnl-test
# build and run example
make example && ./example
# install headers and CMake config
make install
You can’t perform that action at this time.