系统相关
首页 > 系统相关> > 不死进程

不死进程

作者:互联网

利用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;
}

 

标签:TEXT,pid,si,不死,进程,exePath,NULL,connRedis
来源: https://blog.csdn.net/qq_36797488/article/details/111384318