Is it ok using WaitForChildExit(0) this way?

2 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 3 days 13 hours ago
Joined: 2013-05-30 00:53
Is it ok using WaitForChildExit(0) this way?

Hi, I open some window using CreateNewProcTags()

and then when quitting main program I use:

  1. ...
  2. if(/*dd->win[WID_MAIN]==NULL &&*/ dd->WinProc) {
  3. IExec->Signal( (struct Task *)dd->WinProc, SIGBREAKF_CTRL_F );
  4. }
  5.  
  6. if(/*dd->win[WID_PREFS]==NULL &&*/ dd->PrefsProc) {
  7. IExec->Signal( (struct Task *)dd->PrefsProc, SIGBREAKF_CTRL_F );
  8. }
  9.  
  10. IDOS->WaitForChildExit(0);
  11. ...

is it ok?

Or "better" GetPID() of win/prefs process and then " IDOS->WaitForChildExit();"

TiA

cwenzel
cwenzel's picture
Offline
Last seen: 19 hours 31 min ago
Joined: 2021-01-12 07:05
Re: Is it ok using WaitForChildExit(0) this way?

There is no point in specifying a particular PID unless that's a feature you actually need.
As long as the parent process created all child processes with NP_Child,TRUE
then DOS knows which child process/es are created by this main parent process.

So, WaitForChildExit(0); is perfectly fine for ANY and ALL child processes
created by the parent, that may still be running, be that none or one or any number.

As long as you call it from the spawning parent process before leaving main() or _start().
Otherwise a child could still be running in freed memory when the main program unloads,
which is never going to end well.

PS: I would enclose those two tests and the signalling calls within Forbid() / Permit() block,
because the pointer check may become invalid in between the test and the Signal() calls.
So Forbid() at line 1 and Permit() at line 9.

Log in or register to post comments