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