#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) 發送給本程序的終止請求信號。