kill -9 [pid] 该信号不能被捕获
#include <iostream>
#include <csignal>
static void vSignalHandler(int signum) {
std::cout<<__FUNCTION__<<":"<<signum<<std::endl;
//start
//stop
exit(signum);
}
static void vSignalRegister() {
//SIGINT:ctrl+c
//auto res = signal(SIGINT,vSignalHandler);
//SIGTERM:kill [pid]
auto res = signal(SIGTERM,vSignalHandler);
if(res == SIG_ERR) {
std::cout<<__FUNCTION__<<":false"<<std::endl;
}
else {
std::cout<<__FUNCTION__<<":true"<<std::endl;
}
}