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) ??


TYBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
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,
                                    FALSE,
                                    dwPID
                                );

    //  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...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.