Skip to content

Instantly share code, notes, and snippets.

@xudifsd
Created August 25, 2013 08:24
Show Gist options
  • Save xudifsd/6332668 to your computer and use it in GitHub Desktop.
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
#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;
}
#!/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