Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试过实现这个功能:
void alarm_handler(int signal) { if(signal==SIGKILL) { fprintf(stderr,"Process killed\n"); exit(SIGKILL); } }
并以这种方式主要使用它:
signal(SIGKILL,alarm_handler);
因此,如果我按 ctrl+c,在退出之前它会打印“进程已终止”,但 id 不打印它。为什么?
Ctrl+C 通常发送SIGINT,而不是SIGKILL。
SIGINT
SIGKILL
信号 SIGKILL 和 SIGSTOP 不能被捕获、阻止或忽略。
使用 SIGINT。