Converting wait3() to System V

Chip Salzenberg chip at ateng.com
Fri Sep 22 10:14:15 AEST 1989


According to vijay at bradley.UUCP:
>	I hope you can give me some pointers. I am trying to port 
>an application from a 4.3 BSD UNIX to System V. There is a 
>wait3() call in the application that needs to be converted to
>System V wait() or equivalent. And that's where I am stuck. Any help 
>would be appreciated.

A non-blocking wait can be simulated (badly) with the already-suggested:

	int wstat, pid;
	alarm(1);
	pid = wait(&wstat);
	alarm(0);
	if (pid != -1) {
		/* We got a dead child */
	}

An alternative is to keep track of children as they die by strategic use of
the SIGCLD signal.  A SIGCLD signal catching routine will be called when a
child process dies; it can then call wait() with the calm assurance that it
won't block.  Read the manual pages signal(2) and wait(2).

A caveat:  You'll pick up child processes created by library subroutines,
too; this can mess up both them and you.  Be careful with getpwd(), popen(),
system() and any other forking library routines you may have.



More information about the Comp.unix.questions mailing list