예제 #1
0
파일: fork01.c 프로젝트: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	int fails;
	int kid_status, wait_status;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;
		fails = 0;

		TEST(fork());
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "fork() Failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
			tst_resm(TBROK, "unable to continue");
		}
		if (TEST_RETURN == 0) {
			/* child */
			child_pid();
			exit(KIDEXIT);
		} else {
			/* parent */
			tst_resm(TPASS, "fork() returned %ld",
				 TEST_RETURN);
			/* wait for the child to complete */
			wait_status = waitpid(TEST_RETURN, &kid_status, 0);

			if (wait_status == TEST_RETURN) {
				if (kid_status != KIDEXIT << 8) {
					tst_resm(TBROK,
						 "incorrect child status returned on wait(): %d",
						 kid_status);
					fails++;
				}
			} else {
				tst_resm(TBROK,
					 "wait() for child status failed with %d errno: %d : %s",
					 wait_status, errno,
					 strerror(errno));
				fails++;
			}
			if (fails == 0) {
				/* verification tests */
				parent_pid();
			}
		}		/* TEST_RETURN */
	}

	cleanup();
	tst_exit();
}
예제 #2
0
파일: fork01.c 프로젝트: CSU-GH/okl4_3.0
int
main(int ac, char **av)
{
    int lc;		/* loop counter */
    char *msg;		/* message returned from parse_opts */
    int fails;
    int kid_status, wait_status; 
    
    /***************************************************************
     * parse standard options
     ***************************************************************/
    if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
	tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
    setup();

    /* set the expected errnos... */
    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
    for (lc=0; TEST_LOOPING(lc); lc++) {

      /* reset Tst_count in case we are looping. */
      Tst_count=0;
      fails = 0;
      
      /* 
       * Call fork(2)
       */
      TEST(fork());
      
      /* check return code */
      if ( TEST_RETURN == -1 ) {
	TEST_ERROR_LOG(TEST_ERRNO);
	if ( STD_FUNCTIONAL_TEST ) {
	  tst_resm(TFAIL, "fork() Failed, errno=%d : %s",
		   TEST_ERRNO, strerror(TEST_ERRNO));
	  tst_resm(TBROK,"unable to continue");
	}
      } 
      if (TEST_RETURN == 0) {
	/* child */
	if ( STD_FUNCTIONAL_TEST ) {
	  child_pid();
	}
	exit(KIDEXIT);
      } else {
	/* parent */
	if ( STD_FUNCTIONAL_TEST ) {
	  tst_resm(TPASS, "fork() returned %d", TEST_RETURN);
	}
	/* wait for the child to complete */
	wait_status = waitpid(TEST_RETURN, &kid_status, 0);
	if ( STD_FUNCTIONAL_TEST ) {
	  if (wait_status == TEST_RETURN) {
	    if (kid_status != KIDEXIT << 8) {
	      tst_resm(TBROK,
		       "incorrect child status returned on wait(): %d", 
		       kid_status);
	      fails++;
	    }
	  }
	  else {
	    tst_resm(TBROK, 
		     "wait() for child status failed with %d errno: %d : %s", 
		     wait_status,errno,strerror(errno));
	    fails++;
	  }
	  if (fails == 0 ) {
	    /* verification tests */
	    parent_pid();
	  }
	}	 	  /* STD_FUNCTIONAL_TEST */
      }  /* TEST_RETURN */
    }	/* End for TEST_LOOPING */
    
    /***************************************************************
     * cleanup and exit
     ***************************************************************/
    cleanup();

    return 0;
}	/* End main */