#include #include #include #include int main (int argc, char **argv) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof (sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE event0, event1; int child_pid; char buf[1024]; DWORD dwresult; printf ("MASTER: i am %d\n", getpid()); if (argc != 2 || (strcmp (argv[1], "child") != 0 && strcmp (argv[1], "grandchild") != 0)) { printf ("argv[1] must be either `child' or `grandchild'\n"); return 0; } event0 = CreateEvent (&sa, TRUE, FALSE, NULL); event1 = CreateEvent (&sa, TRUE, FALSE, NULL); printf ("MASTER: Created events %08X and %08X\n", event0, event1); sprintf (buf, "SECRETHANDLEVALUE0=%X", event0); printf ("MASTER: calling putenv(%s)\n", buf); putenv (buf); sprintf (buf, "SECRETHANDLEVALUE1=%X", event1); printf ("MASTER: calling putenv(%s)\n", buf); putenv (buf); SetLastError (0); child_pid = _spawnl (_P_NOWAIT, "handlepasstest_slave.exe", "handlepasstest_slave.exe", argv[1], NULL); printf ("MASTER: spawned a child (handle=%d), GLE is %d\n", child_pid, GetLastError ()); SetLastError (0); dwresult = WaitForSingleObject (event0, INFINITE); printf ("MASTER: Wait for %08X returned %d, GLE is %d\n", event0, dwresult, GetLastError ()); SetLastError (0); BOOL bresult = SetEvent (event1); printf ("MASTER: SetEvent for %08X returned %d, GLE is %d\n", event1, bresult, GetLastError ()); _getch(); return 0; }