Replacing (Ctrl-C) signal with (Ctrl-D) [Archive] - C Board

PDA

View Full Version : Replacing (Ctrl-C) signal with (Ctrl-D)


Lord CyKill
10-30-2003, 06:40 PM
I want to have my program ignore the (Ctrl-C) signal and instead should terminate on (Ctrl-D).
How can i do that?

twm
10-30-2003, 08:51 PM
Ctrl-C is usually SIGINT, so all you need to ignore it. :)

struct sigaction sac;

if (sigaction(SIGINT, NULL, &sac) == -1)
perror("Couldn't get old handler");
else {
sac.sa_handler = SIG_IGN;
if (sigaction(SIGINT, &sac, NULL) == -1)
perror("Couldn't ignore SIGINT");
}

Salem
10-31-2003, 01:47 AM
And ctrl-D generates EOF on the input stream.
Aren't you glad you learnt how to use fgets :)


while ( fgets( buff, sizeof buff, stdin ) != NULL ) {
// do stuff
}
if ( feof(stdin) ) {
// user pressed ctrl-D
}