1
1
---
2
2
title : " _cwait"
3
- ms.date : " 4/2/2020"
3
+ description : " API reference for the Microsoft Visual C runtime `_cwait()` function."
4
+ ms.date : " 10/23/2020"
4
5
api_name : ["_cwait", "_o__cwait"]
5
6
api_location : ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-process-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll"]
6
7
api_type : ["DLLExport"]
@@ -28,13 +29,13 @@ intptr_t _cwait(
28
29
29
30
### Parameters
30
31
31
- * termstat* < br />
32
+ * termstat* \
32
33
Pointer to a buffer where the result code of the specified process will be stored, or ** NULL** .
33
34
34
- * procHandle* < br />
35
+ * procHandle* \
35
36
The handle to the process to wait on (that is, the process that has to terminate before ** _ cwait** can return).
36
37
37
- * action* < br />
38
+ * action* \
38
39
NULL: Ignored by Windows operating system applications; for other applications: action code to perform on * procHandle* .
39
40
40
41
## Return Value
@@ -89,44 +90,46 @@ For more compatibility information, see [Compatibility](../../c-runtime-library/
89
90
90
91
struct PROCESS
91
92
{
92
- int nPid ;
93
- char name[ 40] ;
93
+ intptr_t hProcess ;
94
+ char name[40];
94
95
} process[4 ] = { { 0, "Ann" }, { 0, "Beth" }, { 0, "Carl" }, { 0, "Dave" } };
95
96
96
- int main( int argc, char * argv[ ] )
97
+ int main(int argc, char* argv[ ] )
97
98
{
98
- int termstat, c;
99
- unsigned int number;
100
-
101
- srand ( (unsigned)time( NULL ) ); // Seed randomizer
102
-
103
- // If no arguments, this is the calling process
104
- if ( argc == 1 )
105
- {
106
- // Spawn processes in numeric order
107
- for ( c = 0; c < 4; c++ ) {
108
- _ flushall();
109
- process[ c] .nPid = _ spawnl( _ P_NOWAIT, argv[ 0] , argv[ 0] ,
110
- process[ c] .name, NULL );
111
- }
112
-
113
- // Wait for randomly specified process, and respond when done
114
- c = getrandom( 0, 3 );
115
- printf ( "Come here, %s.\n", process[ c] .name );
116
- _ cwait( &termstat, process[ c] .nPid , _ WAIT_CHILD );
117
- printf( "Thank you, %s.\n", process[ c] .name );
118
-
119
- }
120
- // If there are arguments, this must be a spawned process
121
- else
122
- {
123
- // Delay for a period that's determined by process number
124
- Sleep( (argv[ 1] [ 0 ] - 'A' + 1) * 1000L );
125
- printf( "Hi, Dad. It's %s.\n", argv[ 1] );
126
- }
99
+ int termstat, c;
100
+ unsigned int number;
101
+
102
+ srand ((unsigned)time(NULL) ); // Seed randomizer
103
+
104
+ // If no arguments, this is the calling process
105
+ if (argc == 1)
106
+ {
107
+ // Spawn processes in numeric order
108
+ for (c = 0; c < 4; c++) {
109
+ _flushall ();
110
+ process[ c] .hProcess = _ spawnl(_ P_NOWAIT, argv[ 0] , argv[ 0] ,
111
+ process[ c] .name, NULL);
112
+ }
113
+
114
+ // Wait for randomly specified process, and respond when done
115
+ c = getrandom(0, 3);
116
+ printf ("Come here, %s.\n", process[ c] .name);
117
+ _ cwait(&termstat, process[ c] .hProcess , _ WAIT_CHILD);
118
+ printf("Thank you, %s.\n", process[ c] .name);
119
+
120
+ }
121
+ // If there are arguments, this must be a spawned process
122
+ else
123
+ {
124
+ // Delay for a period that's determined by process number
125
+ Sleep ((argv[ 1] [ 0 ] - 'A' + 1) * 1000L);
126
+ printf("Hi, Dad. It's %s.\n", argv[ 1] );
127
+ }
127
128
}
128
129
```
129
130
131
+ The order of the output will vary from run to run.
132
+
130
133
```Output
131
134
Hi, Dad. It's Ann.
132
135
Come here, Ann.
@@ -138,5 +141,5 @@ Hi, Dad. It's Dave.
138
141
139
142
## See also
140
143
141
- [ Process and Environment Control] ( ../../c-runtime-library/process-and-environment-control.md ) < br />
142
- [ _ spawn, _ wspawn Functions] ( ../../c-runtime-library/spawn-wspawn-functions.md ) < br />
144
+ [ Process and Environment Control] ( ../../c-runtime-library/process-and-environment-control.md ) \
145
+ [ _ spawn, _ wspawn Functions] ( ../../c-runtime-library/spawn-wspawn-functions.md )
0 commit comments