1#include"windows.h"2#include"iostream"3#include"stdio.h"4 using namespacestd;5 6 StaticLPCTSTR q_szmutexname="W2KDG. ProcTerm.mutex.Suicide";7 8 HANDLE Startclone () {9 TCHAR Szfilename[max_path];Ten GetModuleFileName (null,szfilename,max_path); One A TCHAR Szcmdline[max_path]; -sprintf_s (szCmdLine, "\"%s\ "\" child\ "", szFileName); - the startupinfo si; - -ZeroMemory (reinterpret_cast<void*> (&si),sizeof(SI)); -si.cb=sizeof(SI); + process_information Pi; - +BOOL bcreateok=CreateProcess ( A szFileName, at szCmdLine, - NULL, - NULL, - FALSE, - Create_new_console, - NULL, in NULL, -&Si, to&Pi + ); - the if(bcreateok) { * CloseHandle (pi.hprocess); $ CloseHandle (pi.hthread);Panax Notoginseng returnpi.hprocess; - } the + Else returnInvalid_handle_value; A } the + voidParent () { -cout<<"Creating The child process and waited child process to quit."<<Endl; $HANDLE hchild=Startclone (); $ if(hchild!=Invalid_handle_value) - { - WaitForSingleObject (hchild,infinite); thecout<<"The child process had quited."<<Endl; - Wuyi } the - Else Wucout<<"Create child process failed."<<Endl; - } About $ - voidChild () { -cout<<"Child ID quiting"<<Endl; -Sleep ( the); A + } the - intMainintargcChar*argv[]) { $ if(argc>1&&STRCMP (argv[1]," Child")==0){ the Child (); the } the Else{ the Parent (); - } in return 0; the the}