Unix to Windows Porting Dictionary for HPC |
|
|
RSS
LinksFunction List
|
Table of Contents header file: windows.h
DWORD WINAPI WaitForMultipleObjects(
__in DWORD nCount,
__in const HANDLE *lpHandles,
__in BOOL bWaitAll,
__in DWORD dwMilliseconds
);
The purpose of the waitpid() function is to have the calling process pause while waiting to detect when a particular process or processes have exited and to reap any zombies. The waited for process must be a child process of the process calling the waitpid() function. On Unix systems, the parent-child relationship between processes is information that is retained by the system. Windows does not maintain this information. This means that it is the complete responsibility of a Windows process to track the parent-child relationship. When a process is created with Windows a handle relating to the new process is provided instead of a process ID (PID). Additional status information that is returned with waitpid() is not available with Windows because of the different paradigm. For example, there are no signals with Windows which is something that waitpid() can report about the process receiving for termination. Maintaining the parent-child relationship can be more easily handled when re-hosting from Unix to Windows by using helper functions rather than expanding the source code at each location that waitpid() is used.
/* This code is an example */
pidcnt=0, pidsiz=0;
HANDLE *pidarray;
/* To be called when a new process is created to keep track of it */
BOOL
store_pid(HANDLE h)
{
if (pidcnt == pidsiz) {
pidsiz += 8;
pidarray = realloc(pidarray, pidsiz * sizeof(HANDLE));
}
pid_array[pid_cnt++] = h;
}
/* Return the handle of a process that has completed */
HANDLE
our_waitpid()
{
DWORD rez;
HANDLE h;
rez = WaitForMultipleObjects(pidcnt, pidarray, FALSE, 0);
h = pidarray[rez];
memmove(&pidarray[rez], &pidarray[rez+1], (pidsiz-rez)*sizeof(HANDLE));
pidcnt--;
return(h);
}
|
|
|
|