Windows System Programming Third Edition [Electronic resources]

Johnson M. Hart

نسخه متنی -صفحه : 291/ 94
نمايش فراداده

  • Waiting for a Process to Terminate

    The simplest, and most limited, method of synchronizing with another process is to wait for that process to complete. The general-purpose Windows wait functions introduced here have several interesting features.

    • The functions can wait for many different types of objects; process handles are just the first use of the wait functions.

    • The functions can wait for a single process, the first of several specified processes, or all processes in a group to complete.

    • There is an optional time-out period.

    The two general-purpose wait functions wait for synchronization objects to become signaled. The system sets a process handle, for example, to the signaled state when the process terminates or is terminated. The wait functions, which will get lots of future use, are as follows:

    DWORD WaitForSingleObject (
    HANDLE hObject,
    DWORD dwMilliseconds)
    

    DWORD WaitForMultipleObjects (
    DWORD nCount,
    CONST HANDLE *lpHandles,
    BOOL fWaitAll,
    DWORD dwMilliseconds)
    

    Return: The cause of the wait completion, or 0XFFFFFFFF for an error (use GetLastError for more information).

    Specify either a single process handle (hObject) or an array of distinct object handles in the array referenced by lpHandles. nCount, the size of the array, should not exceed MAXIMUM_WAIT_OBJECTS (defined as 64 in WINNT.H).Chapter 8.Chapter 8 along with mutex handles.

  • Determine the exit code of a process using GetExitCodeProcess, as described in the preceding section.