Can a parent process determine its child's status ?

Thomas Tornblom thomas at uplog.se
Thu Feb 22 22:44:43 AEST 1990


In article <5090.25e135aa at mva.cs.liv.ac.uk> adh at mva.cs.liv.ac.uk writes:

   Does anyone know how a parent process can determine the status of one
   of its children if it *hasn't* executed a wait ? It could arrange to 
   catch a SIGCLD signal, but if the parent had several children it
   wouldn't know which one had sent it the SIGCLD ... would it ?


Yes it would.
Arrange to catch SIGCLD and do a wait in the catcher:

main()
{
	.
	.
	signal(SIGCLD, reaper);
	.
	.
}

reaper()
{
	int pid;
	int status;

	pid = wait(&status);

	/* pid is now the pid of the child that has died/changed status */

	signal(SIGCLD, reaper);		/* have to re-initialize in sysV */
}

Hope this helps.
Thomas
-- 
Real life:	Thomas Tornblom		Email:	thomas at uplog.se
Snail mail:	TeleLOGIC Uppsala AB		Phone:	+46 18 189406
		Box 1218			Fax:	+46 18 132039
		S - 751 42 Uppsala, Sweden



More information about the Comp.unix.questions mailing list