user/usertests.c
void
reparent(void)
{
  int master_pid = getpid();
  
  printf("reparent test\n");

  for(int i = 0; i < 200; i++){
    int pid = fork();
    if(pid < 0){
      printf("fork failed\n");
      exit(1);
    }
    if(pid){
      if(wait(0) != pid){
        printf("wait wrong pid\n");
        exit(1);
      }
    } else {
      int pid2 = fork();
      if(pid2 < 0){
        printf("fork failed\n");
        kill(master_pid);
        exit(1);
      }
      if(pid2 == 0){
        exit(0);
      } else {
        exit(0);
      }
    }
  }
  printf("reparent ok\n");
}
// try to find races in the reparenting
// code that handles a parent exiting
// when it still has live children.
try to find races in the reparenting
code that handles a parent exiting
when it still has live children.
try to find races in the reparenting code that handles a parent exiting when it still has live children .
void
reparent(void)
{
  int master_pid = getpid();
  printf("reparent test\n");
  for(int i = 0; i < 200; i++){
    int pid = fork();
    if(pid < 0){
      printf("fork failed\n");
      exit(1);
    }
    if(pid){
      if(wait(0) != pid){
        printf("wait wrong pid\n");
        exit(1);
      }
    } else {
      int pid2 = fork();
      if(pid2 < 0){
        printf("fork failed\n");
        kill(master_pid);
        exit(1);
      }
      if(pid2 == 0){
        exit(0);
      } else {
        exit(0);
      }
    }
  }
  printf("reparent ok\n");
}
void reparent ( void ) { int master_pid = getpid ( ) ; printf ( " \n " ) ; for ( int i = 0 ; i < 200 ; i ++ ) { int pid = fork ( ) ; if ( pid < 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } if ( pid ) { if ( wait ( 0 ) != pid ) { printf ( " \n " ) ; exit ( 1 ) ; } } else { int pid2 = fork ( ) ; if ( pid2 < 0 ) { printf ( " \n " ) ; kill ( master_pid ) ; exit ( 1 ) ; } if ( pid2 == 0 ) { exit ( 0 ) ; } else { exit ( 0 ) ; } } } printf ( " \n " ) ; }
try to find races in the reparenting
code that handles a parent exiting
when it still has live children.
try to find races in the reparenting code that handles a parent exiting when it still has live children .