-
-
Save xudifsd/6332668 to your computer and use it in GitHub Desktop.
compile C and execute "python t.py", press CTRL+C or CTRL+\ when executing python. will print "^Cgot signal" in my laptop
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <signal.h> | |
int signaled = 0; | |
void handler(int ignored) { | |
signaled = 1; | |
} | |
int main() { | |
if (signal(SIGINT, handler) == SIG_ERR) | |
return 1; | |
if (sleep(10) == 0) | |
printf("no signal\n"); | |
else | |
printf("got signal\n"); | |
return 0; | |
} |
This file contains 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
#!/usr/bin/env python | |
import os | |
def main(): | |
try: | |
os.system("./a.out"); | |
except KeyboardInterrupt as e: | |
print "got signal in os.system" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment