Created
July 29, 2020 14:46
-
-
Save igricart/d36bcf268bdf26b637f580c6e8655802 to your computer and use it in GitHub Desktop.
Script to handle interruption signal in c++ while also closing a log (Although it is unnecessary)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <syslog.h> | |
#include <string> | |
#include <csignal> | |
void signal_handler(int signal_num) | |
{ | |
std::cout << "The interrupt signal is (" << signal_num << "). \n"; | |
// terminate program | |
closelog(); | |
std::cout << " Closed log " << std::endl; | |
exit(signal_num); | |
} | |
int main() | |
{ | |
openlog("Logs", LOG_PID, LOG_USER); | |
std::string msg; | |
int i = 0; | |
//openlog("ConnectivityManager", LOG_PID, LOG_USER); | |
signal(SIGINT, signal_handler); | |
while (true) | |
{ | |
syslog(LOG_INFO, "Start logging"); | |
syslog(LOG_DEBUG, "oh yeah"); | |
++i; | |
if (i == 10) | |
{ | |
//raise(SIGINT); | |
} | |
} | |
//closelog(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment