void main(){ int i; if ( fork() == 0 ) { /* 子进程程序 */ for ( i = 1; i <1000; i ++ ) PRintf("This is child process/n"); } else { /* 父进程程序*/ for ( i = 1; i <1000; i ++ ) printf("This is process process/n"); } }
int g; DWord WINAPI ChildProcess( LPVOID lpParameter ){ int i; for ( i = 1; i <1000; i ++) { g ++; printf( "This is Child Thread: %d/n", g ); } ExitThread( 0 ); };
void main() { int threadID; int i; g = 0; CreateThread( NULL, 0, ChildProcess, NULL, 0, &threadID ); for ( i = 1; i <1000; i ++) { g ++; printf( "This is Parent Thread: %d/n", g ); } }