Last active
December 15, 2016 13:50
-
-
Save dvtate/adafbf71f87c6562824398808fbc5adc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <signal.h> | |
unsigned long long int numLaughs = 0; | |
void normalExit(void){ | |
printf("\nI laughed %llu times、\n\n", numLaughs); | |
} | |
void bye(const int signal){ | |
if (signal == SIGINT) | |
printf("\n\n哈哈, I caught your SIGINT!\n"); | |
else if (signal == SIGABRT) | |
printf("\n\n哈哈, I caught your SIGABRT!\n"); | |
else if (signal == SIGTERM) | |
printf("\n\n哈哈, I caught your SIGINT!\n"); | |
else if (signal == SIGTSTP) | |
printf("\n\n哈哈, I caught your SIGTSTP!\n"); | |
else | |
printf("\n\n0____o ummmmmm err#%d", signal); | |
exit(0); // calls normalExit() | |
} | |
int main(){ | |
atexit(normalExit); | |
//^C | |
signal(SIGINT, bye); | |
//abort() | |
signal(SIGABRT, bye); | |
//sent by "kill" command | |
signal(SIGTERM, bye); | |
//^Z | |
signal(SIGTSTP, bye); | |
putchar('X'); | |
while (1) { | |
putchar('D'); | |
numLaughs++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment