Windows console application - signal for closing event

て烟熏妆下的殇ゞ 提交于 2019-11-29 11:54:49

The correct one is SIGBREAK, you can try it with:

#include <stdio.h>
#include <signal.h>

void SigInt_Handler(int n_signal)
{
    printf("interrupted\n");
    exit(1);
}

void SigBreak_Handler(int n_signal)
{
    printf("closed\n");
    exit(2);
}

int main(int n_arg_num, const char **p_arg_list)
{
    signal(SIGINT, &SigInt_Handler);
    signal(SIGBREAK, &SigBreak_Handler);
    getchar(); // wait for user intervention
    return 0;
}

Upon closing the console window, the program will print "closed" and will return 2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!