Pausing a child process

I am creating a child process with creatprocess api. And I created a job object and assigned this child process to jobobject.
Now, if I kill my parent process, the child process will also end. But if I paused the parent process, the child process does not pause or continue execution.
is it possible to pause the child process when the parent process is paused?

Delphi code that I used to create the process

Function ExecuteProcess(EXE : String) : THandle; Var SI : TStartupInfo; PI : TProcessInformation; Begin Result := INVALID_HANDLE_VALUE; FillChar(SI,SizeOf(SI),0); SI.cb := SizeOf(SI); If CreateProcess(nil,PChar('.\'+EXE),nil,nil,False,CREATE_SUSPENDED, nil,nil,SI,PI) Then Begin ResumeThread(PI.hThread); CloseHandle(PI.hThread); Result := PI.hProcess; End Else ShowMessage('CreateProcess failed: '+ SysErrorMessage(GetLastError)); End; 
+4
source share
1 answer

From a Windows API perspective, there is no such thing as a process pause. Only threads can be paused, but between threads there is no relationship between parents and children. Since there are no "child threads", there is no automatic mechanism to suspend them when the parent is suspended. (You can create a suspended process, but this is because when it was first created, there is only one thread, and it is created suspended.)

If you want to pause all threads of a child process, list them and pause them the same way you pause threads of a parent process.

You can also try the undocumented function NtSuspendProcess , as indicated in Windows: Atomically suspend the whole process?

+4
source

Source: https://habr.com/ru/post/1390531/


All Articles