csci4061/lab06-code/cant_catch_sigstop.c
Michael Zhang 041f660ccd
f
2018-01-29 17:28:37 -06:00

30 lines
780 B
C

// A C program that does not terminate from an interrupt signal.
// Usually pressing Ctrl-C sends this to the foreground program.
//
// To stop this program from running, open another terminal and try
// > pkill -9 a.out
// assuming you named the output program a.out
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
// Function run when a SIGINT is sent to the program
void handle_SIGSTOP(int sig_num) {
// Reset handler to catch SIGINT next time.
signal(SIGSTOP, handle_SIGSTOP);
printf("\nThere's no SIGSTOPping me!\n");
fflush(stdout);
}
int main() {
// Set handling functions for programs
signal(SIGSTOP, handle_SIGSTOP);
/* Infinite loop */
while (1) {
sleep(1);
printf("I'm awake, I'm awake!\n");
fflush(stdout);
}
return 0;
}