This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
2019-10-13 15:11:06 +02:00
build initial import 2019-09-14 22:41:56 +02:00
cmake initial import 2019-09-14 22:41:56 +02:00
example add example using threads 2019-10-13 15:06:50 +02:00
include/sgnl v0.2 2019-10-13 15:00:20 +02:00
test v0.2 2019-10-13 15:00:20 +02:00
CMakeLists.txt add example using threads 2019-10-13 15:06:50 +02:00
LICENSE initial import 2019-09-14 22:41:56 +02:00
README.md readme: add Catch2 to dependencies 2019-10-13 15:11:06 +02:00

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, SIGINT});

  // 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