#include#include using namespace std; void signal_handler(int signal) { cout << "Received signal: " << signal << endl; } int main() { signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); cout << "Waiting for signal..." << endl; while (true) { } return 0; }
#includeThis example sets up a signal handler for the SIGINT signal, and then retrieves the value of the `SIGNAL` environment variable using the `std::getenv` function. The program then compares the retrieved value to the value of the SIGINT signal, and prints an appropriate message to the console. The package library used in this example is `#include #include using namespace std; void signal_handler(int signal) { cout << "Received signal: " << signal << endl; } int main() { signal(SIGINT, signal_handler); int signal = std::getenv("SIGNAL"); if (signal == SIGINT) { cout << "Received SIGINT signal." << endl; } else { cout << "Did not receive SIGINT signal." << endl; } return 0; }