core files under SV

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Nov 16 11:13:02 AEST 1989


In article <11613 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>	if ( fork() == 0 )
>		abort();

As somebody else pointed out, if you do lots of these you also need
to reap the zombies.  The simplest solution to that is

	if ( (pid = fork()) == 0 )
		abort();
	else
		while ( wait( (int*)0 ) != pid )
			;

If you don't want to wait for the core dump to complete before
proceeding, arrange for the dumping child to be detached:

	if ( (pid = fork()) == 0 )
		if ( fork() == 0 )
	                abort();
		else
			_exit( 0 );
	else
		while ( wait( (int*)0 ) != pid )
			;

Note that I've assumed that you aren't performing any wait()s in
signal handlers, because you really shouldn't.



More information about the Comp.unix.questions mailing list