#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void catch_int(int sig_num)
{
signal(SIGINT, catch_int);
printf("Don't do that\n");
fflush(stdout);
}
int main(int argc, char* argv[])
{
/* set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT, catch_int);
/* now, lets get into an infinite loop of doing nothing. */
for ( ;; )
pause();
}
Output:
[csuser@localhost ~]$ vi sig.c
[csuser@localhost ~]$ gcc sig.c
[csuser@localhost ~]$ ./a.out
^CDon't do that
^Z
[1]+ Stopped ./a.out
#include <unistd.h>
#include <signal.h>
void catch_int(int sig_num)
{
signal(SIGINT, catch_int);
printf("Don't do that\n");
fflush(stdout);
}
int main(int argc, char* argv[])
{
/* set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT, catch_int);
/* now, lets get into an infinite loop of doing nothing. */
for ( ;; )
pause();
}
Output:
[csuser@localhost ~]$ vi sig.c
[csuser@localhost ~]$ gcc sig.c
[csuser@localhost ~]$ ./a.out
^CDon't do that
^Z
[1]+ Stopped ./a.out