gpt4 book ai didi

c - 处理中断 :

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:50 24 4
gpt4 key购买 nike

In the following program:

Ctrl+z and ctrl+c both are interrupts.
The code is supposed to handle any interrupt.


Then why does only one of them(ctrl+c) work?

代码:

#include <signal.h>
#include<stdio.h>
void handler(int sig)
{
printf("Caught SIGINT\n");
exit(0);
}

int main()
{
printf("\nYou can press ctrl+c to test this program\n");
if (signal(SIGINT, handler) == SIG_ERR)
perror("signal error");

pause(); /* wait for the receipt of a signal */

exit(0);
}

用户输入:必须是中断输出必须是:Caught sigint

最佳答案

因为 Ctrl-Z 导致 SIGTSTP,而不是 SIGINT

关于c - 处理中断 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com