user/usertests.c
void
forkfork(void)
{
  int ppid = getpid();
  enum { N=2 };
  
  printf("forkfork test\n");

  for(int i = 0; i < N; i++){
    int pid = fork();
    if(pid < 0){
      printf("fork failed");
      exit(1);
    }
    if(pid == 0){
      for(int j = 0; j < 200; j++){
        int pid1 = fork();
        if(pid1 < 0){
          printf("fork failed\n");
          kill(ppid);
          exit(1);
        }
        if(pid1 == 0){
          exit(0);
        }
        wait(0);
      }
      exit(0);
    }
  }

  for(int i = 0; i < N; i++){
    wait(0);
  }

  printf("forkfork ok\n");
}
// concurrent forks to try to expose locking bugs.
concurrent forks to try to expose locking bugs.
concurrent forks to try to expose locking bugs .
void
forkfork(void)
{
  int ppid = getpid();
  enum { N=2 };
  printf("forkfork test\n");
  for(int i = 0; i < N; i++){
    int pid = fork();
    if(pid < 0){
      printf("fork failed");
      exit(1);
    }
    if(pid == 0){
      for(int j = 0; j < 200; j++){
        int pid1 = fork();
        if(pid1 < 0){
          printf("fork failed\n");
          kill(ppid);
          exit(1);
        }
        if(pid1 == 0){
          exit(0);
        }
        wait(0);
      }
      exit(0);
    }
  }
  for(int i = 0; i < N; i++){
    wait(0);
  }
  printf("forkfork ok\n");
}
void forkfork ( void ) { int ppid = getpid ( ) ; enum { N = 2 } ; printf ( " \n " ) ; for ( int i = 0 ; i < N ; i ++ ) { int pid = fork ( ) ; if ( pid < 0 ) { printf ( " " ) ; exit ( 1 ) ; } if ( pid == 0 ) { for ( int j = 0 ; j < 200 ; j ++ ) { int pid1 = fork ( ) ; if ( pid1 < 0 ) { printf ( " \n " ) ; kill ( ppid ) ; exit ( 1 ) ; } if ( pid1 == 0 ) { exit ( 0 ) ; } wait ( 0 ) ; } exit ( 0 ) ; } } for ( int i = 0 ; i < N ; i ++ ) { wait ( 0 ) ; } printf ( " \n " ) ; }
concurrent forks to try to expose locking bugs.
concurrent forks to try to expose locking bugs .