• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Is there a message sent when a process goes down ?

I would like to know when a process (any process, no specific info needed about the process goind down) is going down... Is there any message that I can recieve to detect such a event (in another process) ??

1 Solution
Assuming that you're talking about windows - there's no message sent, but you could do the following to get notified when a process terminates:

DWORD   WaitForPID  (   DWORD   dwPID)
    DWORD                           dwExitCode =   0xffffffff;
    DWORD                           dwWait;

    HANDLE                          hProcess;

    //  get process handle
    hProcess    =   OpenProcess (   PROCESS_QUERY_INFORMATION   |   SYNCHRONIZE,

    //  could fail due to invalid PID or insufficiant privileges
    if  (   !hProcess)
            return  (   0xffffffff);

    dwWait  =   WaitForSingleObject (   hProcess,   INFINITE);

    if  (   WAIT_FAILED ==  dwWait)
            printf  (   "wait operation failed, reason == '%d'\n",
                        GetLastError    ()

            return  (   0);

    GetExitCodeProcess  (   hProcess,   &dwExitCode);

    CloseHandle (   hProcess);

    return  (   dwExitCode);

When this function returns, the process specified with its PID (process id) has terminated...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now