不死进程

利用WindowsAPI创建子进程获取子进程退出代码从而让子进程不死。只应用于Windows平台。

#define exeName "E:/workCode/c/connRedis/connRedis/Debug/connRedis.exe"
#define exePath "E:/workCode/c/connRedis/connRedis/Debug/"
int main()
{
	PROCESS_INFORMATION pid;
	DWORD exitCode=0;
	STARTUPINFO si = { sizeof(si) };
	BOOL ProcessFlag = CreateProcess(TEXT(exeName), NULL, NULL, NULL, FALSE, 0, NULL, TEXT(exePath), &si, &pid);
	while (1) {
		GetExitCodeProcess(pid.hProcess, &exitCode);
		if ( exitCode != STILL_ACTIVE) {
			BOOL ProcessFlag = CreateProcess(TEXT(exeName), NULL, NULL, NULL, FALSE, 0, NULL, TEXT(exePath), &si, &pid);
			printf("create process secuess");
		}
		Sleep(3000);
	}
    return 0;
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页