c signal函数与system函数小应用

#include<sys/types.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/stat.h>
#include<sys/wait.h>
#include<signal.h>


void sighandler(int);

int main()
{
	signal(SIGINT, &sighandler);

	while(1)
	{
		std::string cmd = "";
		cmd = "clear";
		system(cmd.c_str());

		std::string cmd1 = "";
		cmd1 = "date";
		system(cmd1.c_str());
		printf("\n");

		printf("sleep 1 sec...\n");
		sleep(1);
	}

	return 0;
}

void sighandler(int signum)
{
	printf("messgae %d. jump:...\n", signum);
	exit(EXIT_FAILURE);
}
SIGABRT	(Signal Abort) 程序异常终止。
SIGFPE	(Signal Floating-Point Exception) 算术运算出错,如除数为 0 或溢出(不一定是浮点运算)。
SIGILL	(Signal Illegal Instruction) 非法函数映象,如非法指令,通常是由于代码中的某个变体或者尝试执行数据导致的。
SIGINT	(Signal Interrupt) 中断信号,如 ctrl-C,通常由用户生成。
SIGSEGV	(Signal Segmentation Violation) 非法访问存储器,如访问不存在的内存单元。
SIGTERM	(Signal Terminate) 发送给本程序的终止请求信号。

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值