1 /* This is a test case where the parent process forks 10 children
2 * which contend to merge profile data to the same file. With
3 * file locking support, the data from each child should not
10 void spawn_child(PROCESS_INFORMATION
*pi
, int child_num
) {
11 wchar_t child_str
[10];
12 _itow(child_num
, child_str
, 10);
13 if (!SetEnvironmentVariableW(L
"CHILD_NUM", child_str
)) {
14 printf("SetEnvironmentVariableW failed (0x%8lx).\n", GetLastError());
20 memset(&si
, 0, sizeof(si
));
23 memset(pi
, 0, sizeof(PROCESS_INFORMATION
));
25 if (!CreateProcessW(NULL
, // No module name (use command line)
26 GetCommandLineW(), // Command line
27 NULL
, // Process handle not inheritable
28 NULL
, // Thread handle not inheritable
29 TRUE
, // Set handle inheritance to TRUE
31 NULL
, // Use parent's environment block
32 NULL
, // Use parent's starting directory
34 printf("CreateProcess failed (0x%08lx).\n", GetLastError());
40 int wait_child(PROCESS_INFORMATION
*pi
) {
41 WaitForSingleObject(pi
->hProcess
, INFINITE
);
44 if (!GetExitCodeProcess(pi
->hProcess
, &exit_code
)) {
45 printf("GetExitCodeProcess failed (0x%08lx).\n", GetLastError());
50 CloseHandle(pi
->hProcess
);
51 CloseHandle(pi
->hThread
);
56 #define NUM_CHILDREN 10
59 if (num
< (NUM_CHILDREN
/ 2)) {
61 } else if (num
< NUM_CHILDREN
) {
67 int main(int argc
, char *argv
[]) {
68 char *child_str
= getenv("CHILD_NUM");
70 PROCESS_INFORMATION child
[NUM_CHILDREN
];
72 for (int i
= 0; i
< NUM_CHILDREN
; i
++) {
73 spawn_child(&child
[i
], i
);
75 for (int i
= 0; i
< NUM_CHILDREN
; i
++) {
76 wait_child(&child
[i
]);
81 int child_num
= atoi(child_str
);
82 int result
= foo(child_num
);
84 fprintf(stderr
, "Invalid child count!");