首页 > 编程语言 >C/C++single

C/C++single

时间:2022-10-21 16:46:59浏览次数:40  
标签:std SIGABRT cout signal C++ single handler include

#include <iostream>
#include <unistd.h>
#include <csignal>
#include <string.h>


using namespace std;

void signal_handler(int signal)
{
cout << "Caught signal number " << std::to_string(signal) << " (" << strsignal(signal) << ")" << endl;
if ((signal == SIGABRT) || (signal == SIGTERM) || (signal == SIGINT)) {
cout << "Example program exit." << endl;
exit(0);
}
}


int main()
{
cout << "Example application started" << endl;
// Set signal handlers
std::signal(SIGABRT, &signal_handler);
std::signal(SIGTERM, &signal_handler);
std::signal(SIGINT, &signal_handler);

// loop
for (;;) {
cout << "for -----" << endl;
pause();
}

return 0;
}

标签:std,SIGABRT,cout,signal,C++,single,handler,include
From: https://www.cnblogs.com/liangzige/p/16813955.html

相关文章

  • 实验3 数组、指针与现代c++标准库
    1.实验任务1程序源码task1_1#include<iostream>usingstd::cout;usingstd::endl;classA{public:A(intx0,inty0):x{x0},y{y0}{}voidshow......
  • 2022年10月20日 C++类模型漫谈(四)
    系统基于32位,MSVC编译器,VS开发工具1、之前看到的都是简单一点的类型继承,现在看下另外一个例子,菱形继承(又称钻石继承)。一个TypeA基类,TypeB和TypeC继承TypeA,TypeD同时继承Ty......
  • 集成 CDT 插件至 Eclipse 全过程,并开发你第一个 Eclipse 下的 C/C++ 程序
    集成CDT插件至Eclipse全过程,并开发你第一个Eclipse下的C/C++程序本文示例用CDT插件已经上传,​​点击这里进入下载页面​​。       集成CDT插件至Ecl......
  • C++调用C#DLL并调试
    使用C++来调用C#DLL并且调试程序环境:使用VSstudio2019C#项目的设置1、C#->属性->应用程序->目标框架->.NETFramework42、C#->属性->调试->调试程......
  • C++之虚函数
    最近在看侯捷的深入浅出MFC时,了解到C++的相关知识,比如this指针到底是怎么出现的?虚函数是如何做到准确调用某个函数的,明明大家都长的一样?普通的成员函数是怎么被调用的?覆盖......
  • C++20高级编程 第五版 电子书 pdf
    作者:[比]马克·格雷戈勒(MarcGregoire)出版社:清华大学出版社原作名:ProfessionalC++,FifthEdition 链接:C++20高级编程第五版 拥抱C++的深度和复杂性,挖掘更多......
  • 在旧版本centos上编译c++11的程序
    runac++programwithc++11supportinolderCentOSmachine从extras安装SoftwareCollections(SCL)yuminstallcentos-release-scl-rh安装devtoolset:yumin......
  • 【C++入门】(九)使用继承拓展类
    1.什么是继承?基类(classAnimal)可以有多个派生类(classDog:publicAnimal)classAnimal//基类{public:stringname="123";intage;};​classDo......
  • 【C++入门】(七)高级函数
    1.如何重载成员函数?函数重载:编写多个名称相同但参数不同的函数成员函数也可以重载编译器根据参数数量和类型决定调用哪个构造函数classRectangle{public......
  • C++中的四种强制类型转换
    ①static_cast(expression)<type-id>该运算符把expression转换为type_id类型,但没有运行时类型检查来保证转换的安全性,最常用的是基本数据类型之间的转换 ②const_cast......