util/xlaunch.c
/* wait for child process to start, using waitpid() */
wait for child process to start, using waitpid()
wait for child process to start using waitpid ()
static int launch_waitstart(pid_t pid){
  int i, got;
  int status=0;
  struct timeval tv;
  for(i=0; i<LAUNCH_WAIT_TRIES; i++){
    errno = 0;
    got=waitpid(pid, &status, WNOHANG);
    if( (got < 0) || ((got == 0) && xerrno) ){
      got = -1;
      if( status == 0 )
	status = -1;
      break;
    }
    else if( got > 0 ){
      break;
    }
    else{
      tv.tv_sec = 0;
      tv.tv_usec = LAUNCH_WAIT_MSEC;
      xselect(1, NULL, NULL, NULL, &tv);
    }
  }
  if( got == 0 ) status = 0;
  return status;
}
static int launch_waitstart ( pid_t pid ) { int i , got ; int status = 0 ; struct timeval tv ; for ( i = 0 ; i < LAUNCH_WAIT_TRIES ; i ++ ) { errno = 0 ; got = waitpid ( pid , & status , WNOHANG ) ; if ( ( got < 0 ) || ( ( got == 0 ) && xerrno ) ) { got = -1 ; if ( status == 0 ) status = -1 ; break ; } else if ( got > 0 ) { break ; } else { tv . tv_sec = 0 ; tv . tv_usec = LAUNCH_WAIT_MSEC ; xselect ( 1 , NULL , NULL , NULL , & tv ) ; } } if ( got == 0 ) status = 0 ; return status ; }
wait for child process to start, using waitpid()
wait for child process to start using waitpid ()
/* wait up to LAUNCH_WAIT_TRIES millisec to make sure the child started,
     but if we get an error, we can exit immediately */ /* look for error termination */ /* make sure status shows error */ /* look for normal termination */ /* no termination, sleep and wait some more */ /* no termination means the child is still running */ /* return the news */