user/usertests.c
void
forktest(void)
{
  enum{ N = 1000 };
  int n, pid;

  printf("fork test\n");

  for(n=0; n<N; n++){
    pid = fork();
    if(pid < 0)
      break;
    if(pid == 0)
      exit(0);
  }

  if (n == 0) {
    printf("no fork at all!\n");
    exit(1);
  }

  if(n == N){
    printf("fork claimed to work 1000 times!\n");
    exit(1);
  }

  for(; n > 0; n--){
    if(wait(0) < 0){
      printf("wait stopped early\n");
      exit(1);
    }
  }

  if(wait(0) != -1){
    printf("wait got too many\n");
    exit(1);
  }

  printf("fork test OK\n");
}
// test that fork fails gracefully
// the forktest binary also does this, but it runs out of proc entries first.
// inside the bigger usertests binary, we run out of memory first.
test that fork fails gracefully
the forktest binary also does this, but it runs out of proc entries first.
inside the bigger usertests binary, we run out of memory first.
test that fork fails gracefully the forktest binary also does this but it runs out of proc entries first . inside the bigger usertests binary we run out of memory first .
void
forktest(void)
{
  enum{ N = 1000 };
  int n, pid;
  printf("fork test\n");
  for(n=0; n<N; n++){
    pid = fork();
    if(pid < 0)
      break;
    if(pid == 0)
      exit(0);
  }
  if (n == 0) {
    printf("no fork at all!\n");
    exit(1);
  }
  if(n == N){
    printf("fork claimed to work 1000 times!\n");
    exit(1);
  }
  for(; n > 0; n--){
    if(wait(0) < 0){
      printf("wait stopped early\n");
      exit(1);
    }
  }
  if(wait(0) != -1){
    printf("wait got too many\n");
    exit(1);
  }
  printf("fork test OK\n");
}
void forktest ( void ) { enum { N = 1000 } ; int n , pid ; printf ( " \n " ) ; for ( n = 0 ; n < N ; n ++ ) { pid = fork ( ) ; if ( pid < 0 ) break ; if ( pid == 0 ) exit ( 0 ) ; } if ( n == 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } if ( n == N ) { printf ( " \n " ) ; exit ( 1 ) ; } for ( ; n > 0 ; n -- ) { if ( wait ( 0 ) < 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } } if ( wait ( 0 ) != -1 ) { printf ( " \n " ) ; exit ( 1 ) ; } printf ( " \n " ) ; }
test that fork fails gracefully
the forktest binary also does this, but it runs out of proc entries first.
test that fork fails gracefully the forktest binary also does this but it runs out of proc entries first .