当前位置: 代码迷 >> 综合 >> 不死进程
  详细解决方案

不死进程

热度:46   发布时间:2023-10-29 03:56:59.0

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

 

  相关解决方案