可以參考以下程式碼唷!
#include <stdio.h>
#include <signal.h>
void handler1(int sig) {
printf(" Your input is Ctrl + C\n");
signal(SIGINT, SIG_DFL);
}
void handler2(int sig) {
printf(" Your input is Ctrl + Z\n");
signal(SIGTSTP, SIG_DFL);
}
void main(void)
{
/* I/O detect */
signal(SIGINT, handler1);
signal(SIGTSTP, handler2);
while (1) {
printf("waiting ...\n");
sleep(5);
}
}
執行結果:參考資料:
http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html
No comments:
Post a Comment