2

Here is my code:

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;
}

when i terminated it via the windows taskmgr,that DebugString did't show up. is something wrong with my code?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
H.C.Chou
  • 43
  • 1
  • 4
  • 2
    The code is unreadable, please check how to format code in the edit help. You just need to indent with four spaces. – πάντα ῥεῖ Jul 11 '16 at 06:07
  • 2
    "The SIGILL and SIGTERM signals are not generated under Windows. They are included for ANSI compatibility." Windows doesn't use unix signals. They are a C runtime concept. Task Manager terminates the application without generating a signal. – Raymond Chen Jul 11 '16 at 06:15

2 Answers2

3

Windows does not use signals in the same way that Unix systems do.

For example, it does not generate SIGTERM.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
0

TaskManager uses TerminateProcess API call to kill selected process. Terminated process does not get any notification. So you could not handle it with the SIGTERM signal.

Ari0nhh
  • 5,720
  • 3
  • 28
  • 33