-1

For example, we have 2 executable files on windows. (EXE_1.exe, EXE_2.exe)

EXE_1.exe is calling EXE_2.exe with arguments. I want to detect when EXE_2 Closed(Terminated, killed etc.)

I can't use WaitForSingleObject in C++ or Psutil process wait in python. Because it is returns when First executable its closed. (Remember: First exe start Second exe and closing himself)

So I need a function which one returns called exes called exe's pid or something like that.

I Tried GetChildProcessID in c++, its works but its returns CMD.exe's pid. It is fine, if i check this cmd exe; when it is closed that means my created second exe too closed. But i am looking to get pid of second exe.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Emrexdy
  • 156
  • 1
  • 2
  • 8
  • 1
    [How do I wait until all processes in a job have exited?](https://devblogs.microsoft.com/oldnewthing/20130405-00/?p=4743). The key is that, once the process is attached to a job, all processes it creates are also attached to that job by default (unless `CREATE_BREAKAWAY_FROM_JOB` is passed to `CreateProcess`, and the job can be configured to prohibit this). – Igor Tandetnik Nov 07 '20 at 22:40

1 Answers1

0
info = subprocess.STARTUPINFO()
info.dwFlags = subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = EmreWin32Con.SW_MINIMIZE
EXE = subprocess.Popen([EXE_KONUM], cwd=KLASOR_KONUM_EXE,
                                    creationflags=subprocess.CREATE_NO_WINDOW, 
                                    startupinfo=info, stderr=subprocess.DEVNULL,
                                    stdout=subprocess.DEVNULL,
                                    shell=False)
def GetChildProcessIDList(pid):
    prc = psutil.Process(pid)
    return prc.children(recursive=True)


Childrens = GetChildProcessIDList(EXE.pid)
isCmd = False
for chcmd in Childrens:
    if chcmd.name() == "cmd.exe":
        isCmd=True
        Childrens.remove(chcmd)
        break
# variable Childrens: list of process created process PID's.
Emrexdy
  • 156
  • 1
  • 2
  • 8