【问题标题】:Why doesn't SIGTERM Works On Windows [duplicate]为什么 SIGTERM 在 Windows 上不起作用 [重复]
【发布时间】:2016-11-12 23:56:45
【问题描述】:

这是我的代码:

void signalHandler(int sigNum) {
    OutputDebugStringA("i'm terminated\n");
    exit(sigNum);
}

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPTSTR    lpCmdLine,
    _In_ int       nCmdShow)
{
    signal(SIGTERM, signalHandler);
    while (1)
    {
        Sleep(100);
    }
    return 0;
}

当我通过 windows taskmgr 终止它时,DebugString 没有出现。 我的代码有问题吗?

【问题讨论】:

  • 代码不可读,请在编辑帮助中查看如何格式化代码。你只需要缩进四个空格。
  • "SIGILL 和 SIGTERM 信号不是在 Windows 下生成的。它们是为了 ANSI 兼容性而包含在内的。" Windows 不使用 unix 信号。它们是 C 运行时概念。任务管理器在不产生信号的情况下终止应用程序。

标签: c++ windows


【解决方案1】:

Windows 使用信号的方式与 Unix 系统不同。

比如does not generate SIGTERM

【讨论】:

    【解决方案2】:

    TaskManager 使用TerminateProcess API 调用来杀死选定的进程。终止的进程没有收到任何通知。所以你无法用SIGTERM 信号处理它。

    【讨论】:

      猜你喜欢
      • 2021-07-19
      • 1970-01-01
      • 2021-11-15
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多