Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I createprocess in windows and not wait for it to complete?

Tags:

windows

winapi

I have a little windows c++ program that just fires off other programs, but I find when I kill my parent program, all the children die. I want to spawn them off with no relation to the parent anymore. I don't want to wait for output, I don't even care too much if it worked or not. But it is important that it not be tied to the parent process, because it can go away at random. The docs aren't terribly forthcoming on this subject.

This is what I've got.

if (CreateProcess(NULL, s, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
  {
    // don't wait for it to finish.
    //::WaitForSingleObject(processInfo.hProcess, INFINITE);
    // free up resources...
    CloseHandle(processInfo.hProcess);
    CloseHandle(processInfo.hThread);
  }
else
  log error...
like image 755
stu Avatar asked Jun 14 '13 17:06

stu


1 Answers

You simply need to pass CREATE_NEW_PROCESS_GROUP in the dwCreationFlags parameter.

like image 178
David Heffernan Avatar answered Sep 24 '22 15:09

David Heffernan