这是
here的引用:
#include <windows.h> #include <stdio.h> #include <tchar.h> #include <conio.h> void _tmain( int argc,TCHAR *argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; STARTUPINFO sj; PROCESS_INFORMATION pj; ZeroMemory( &si,sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi,sizeof(pi) ); ZeroMemory( &sj,sizeof(sj) ); sj.cb = sizeof(sj); ZeroMemory( &pj,sizeof(pj) ); // Start the child process p1.exe. Make sure p1.exe is in the // same folder as current application. Otherwise write the full path in first argument. if(!CreateProcess(L".\\p1.exe",NULL,FALSE,&sj,&pj)) { printf( "Hello CreateProcess Failed (%d)\n",GetLastError() ); getch(); return; } // Start child process p2.exe. Make sure p2.exe is in the // same folder as current application. Otherwise write the full path in first argument. if(!CreateProcess(L".\\p2.exe",&si,&pi)) { printf( "CreateProcess2 Failed (%d)\n",GetLastError() ); getch(); return; } // Wait until child processes exit. WaitForSingleObject( pi.hProcess,INFINITE ); WaitForSingleObject( pj.hProcess,INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); CloseHandle( pj.hProcess ); CloseHandle( pj.hThread ); getch(); }