1 #include "windows.h"
2 #include "iostream"
3 #include "stdio.h"
4
5 void StartClone(int nCloneID){
6 TCHAR szFilename[MAX_PATH];
7 GetModuleFileName(NULL,szFilename,MAX_PATH);
8
9 TCHAR szCmdLine[MAX_PATH];
10 sprintf(szCmdLine,"\"%s\"%d",szFilename,nCloneID);
11
12 STARTUPINFO si;
13 ZeroMemory(reinterpret_cast<void*>(&si),sizeof(si));
14 si.cb=sizeof(si);
15 PROCESS_INFORMATION pi;
16
17 BOOL bCreateOK=CreateProcess(
18 szFilename,
19 szCmdLine,
20 NULL,
21 NULL,
22 FALSE,
23 CREATE_NEW_CONSOLE,
24 NULL,
25 NULL,
26 &si,
27 &pi
28 );
29
30
31 if(bCreateOK){
32 CloseHandle(pi.hProcess);
33 CloseHandle(pi.hThread);
34 }
35 }
36
37
38 int main(int argc,char *argv[]){
39 int nClone(0);
40 if(argc>1){
41 sscanf(argv[1],"%d",&nClone);
42 }
43
44 printf("process ID:%d,,clone ID:%d\n",GetCurrentProcessId(),nClone);
45
46
47 const int c_nCloneMAX=25;
48
49 if(nClone<c_nCloneMAX){
50
51 StartClone(++nClone);
52 Sleep(1000);
53 }
54
55 Sleep(500);
56
57 return 0;
58
59 }
Thread create 创建进程
时间: 2024-10-12 20:25:50