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;
    }
}

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2021-07-01
  • 2022-01-13
  • 2021-06-15
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-06-05
  • 2022-12-23
相关资源
相似解决方案