windows系统调用 进程终止

 #include "windows.h"
#include "iostream"
#include "stdio.h"
using namespace std; static LPCTSTR q_szMutexName="w2kdg.ProcTerm.mutex.Suicide"; HANDLE StartClone(){
TCHAR szFilename[MAX_PATH];
GetModuleFileName(NULL,szFilename,MAX_PATH); TCHAR szCmdLine[MAX_PATH];
sprintf_s(szCmdLine,"\"%s\" \"child\"",szFilename);
STARTUPINFO si; ZeroMemory(reinterpret_cast<void*>(&si),sizeof(si));
si.cb=sizeof(si);
PROCESS_INFORMATION pi; BOOL bCreateOK=CreateProcess(
szFilename,
szCmdLine,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi
); if(bCreateOK){
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return pi.hProcess;
} else return INVALID_HANDLE_VALUE;
} void Parent(){
cout<<"Creating the child process and waited child process to quit."<<endl;
HANDLE hchild=StartClone();
if(hchild!=INVALID_HANDLE_VALUE)
{
WaitForSingleObject(hchild,INFINITE);
cout<<"The child process had quited."<<endl; } else
cout<<"Create child process failed."<<endl;
} void Child(){
cout<<"Child id quiting"<<endl;
Sleep(); } int main(int argc,char * argv[]){
if(argc>&&strcmp(argv[],"child")==){
Child();
}
else{
Parent();
}
return ; }
上一篇:笑话库存加网址http://www.jokeji.cn/list18_11.htm


下一篇:BZOJ1300 [LLH邀请赛]大数计算器