[comp.os.os2.misc] knowing when a child process has died

ilene@zeb.USWest.COM (02/20/91)

 I need to know how to determine when a particular child process has 
 died - at any given time in my program.  

 I started my child processes with DosExecPgm with the EXEC_ASYNCRESULT
 constant.  These processes are running as the parent process is
 running. AT given times in my program, I need to know if these
 child processes are still alive.  I tried using DosCwait with the 
 DCWW_NOWAIT constant and the particular child process id.  This doesn't
 seem to give me any useful info.  I looked in microsoft os2 programmers
 reference (pg 595) and it says that this willl retrieve the termination
 reference (pg. 595) and it says that this use of DosCwait retrieves the
 termination status from the most RECENT process to end.  This brings me

 back to the drawing board.  Anybody out there know how to find out
 about  the status of a particular child process at any given time in 
 the program.  Thanks .

 Ilene

mikem@panews (02/21/91)

In article <15458@uswat.UUCP> ilene@zeb.USWest.COM () writes:
>
> I need to know how to determine when a particular child process has 
> died - at any given time in my program.  
>
> Ilene

Have the program create a System Semaphore. If the parent wants to
check if the child is still around, have it try to create the same
system semaphore (eg "\sem\child.sem"). There are other variations,
You could use shared memory, or install a signal handler, or use
a User message (if using PM).

Hope this gives you some ideas.

Regards,
Michael R. MacFaden    IBM Palo Alto     Marketing Systems
mikem@ibmpa.awdpa.ibm.com, macfaden@paloic1.iinus1.ibm.com 
disclaimer:...the usual... 

hdg@otter.hpl.hp.com (Hugh Duggan) (02/21/91)

>  I need to know how to determine when a particular child process has 
>  died - at any given time in my program.  
> 
>  ...
> 
>  Ilene
> ----------

    You could create a thread which would block on a DosCWait() call.
This could then change some global data (protected by semaphore), or
post a message on a queue to inform the main thread.  I do something
very close to this in some code that I am developing, and it works
very well.  The thread procedure looks something like this:



VOID FAR CrashDetectThread()
{
    while ( TRUE )
    {
	RESULTCODES rc;
	PID	    pidEnded;

	DosCwait( DCWA_PROCESS, DCWW_WAIT, &rc, &pidEnded, 0 );

	//  Once I have got to here, a child process has died.
	
	if ( rc.codeTerminate != TC_EXIT )
	{
	    //  ---------------- A child has died abnormally ------------- 

	    //  Do stuff
	}
    }
}


    I hope this helps,

    Hugh Duggan,
    HP Labs, Bristol

jka@niksula.hut.fi (Jari Petri Karjala) (02/22/91)

In article <15458@uswat.UUCP> ilene@zeb.USWest.COM writes:
>  I need to know how to determine when a particular child process has 
>  died - at any given time in my program.  

	You can call DosGetPriority with the child's PID. It returns error
	if the process has died. 


--
/*    Jari Karjala    **  "Mathematics is a subject in which we never know  */
/* jka@niksula.hut.fi **    what we are talking about" -- Bertrand Russel   */

seg@ingres.com (scott e garfinkle) (02/23/91)

In article <15458@uswat.UUCP> ilene@zeb.USWest.COM () writes:
>...
> back to the drawing board.  Anybody out there know how to find out
> about  the status of a particular child process at any given time in 
> the program.  Thanks .
>
> Ilene

Why not spawn off a thread that does nothing but DosCwait for children?
You can arrange with RAM semaphores so that is only waits when there
are one or more processes outstanding.

	-scott e. garfinkle

cscullio@ncratl.AtlantaGA.NCR.COM (Chris Scullion) (02/25/91)

In <1991Feb20.173755.14036@ibmpa.awdpa.ibm.com> mikem@panews writes:

>In article <15458@uswat.UUCP> ilene@zeb.USWest.COM () writes:
>>
>> I need to know how to determine when a particular child process has 
>> died - at any given time in my program.  
>>
>> Ilene

>Have the program create a System Semaphore. If the parent wants to
>[balance deleted]

Or you could just use DosCwait (child wait) to detect child process
termination.  It allows for detection "on-the-fly" or indefinite wait (use a
new thread in this case).

CKS
-- 
Chris Scullion   | NCR Corporation 2651 Satellite Blvd., Duluth, GA 30136 |
| (404)623-7352  | VoicePlus 751-7352 | cscullio@ncratl.AtlantaGA.NCR.COM |

mbhat@pcserver2.naitc.com (Manoj Bhat) (02/27/91)

Why don't you spawn the child process using DosStartSession()?
Before the call , create a queue and provide the queue name in the call to
DosStartSession. Then after some time interval, read the queue and check
the value. The child process's termination code will be put into the queue
by PM.
Hope this helps.

Manoj Bhat.