user/usertests.c
void
preempt(void)
{
  int pid1, pid2, pid3;
  int pfds[2];

  printf("preempt: ");
  pid1 = fork();
  if(pid1 < 0) {
    printf("fork failed");
    exit(1);
  }
  if(pid1 == 0)
    for(;;)
      ;

  pid2 = fork();
  if(pid2 < 0) {
    printf("fork failed\n");
    exit(1);
  }
  if(pid2 == 0)
    for(;;)
      ;

  pipe(pfds);
  pid3 = fork();
  if(pid3 < 0) {
     printf("fork failed\n");
     exit(1);
  }
  if(pid3 == 0){
    close(pfds[0]);
    if(write(pfds[1], "x", 1) != 1)
      printf("preempt write error");
    close(pfds[1]);
    for(;;)
      ;
  }

  close(pfds[1]);
  if(read(pfds[0], buf, sizeof(buf)) != 1){
    printf("preempt read error");
    return;
  }
  close(pfds[0]);
  printf("kill... ");
  kill(pid1);
  kill(pid2);
  kill(pid3);
  printf("wait... ");
  wait(0);
  wait(0);
  wait(0);
  printf("preempt ok\n");
}
// meant to be run w/ at most two CPUs
meant to be run w/ at most two CPUs
meant to be run w / at most two CPUs
void
preempt(void)
{
  int pid1, pid2, pid3;
  int pfds[2];
  printf("preempt: ");
  pid1 = fork();
  if(pid1 < 0) {
    printf("fork failed");
    exit(1);
  }
  if(pid1 == 0)
    for(;;)
      ;
  pid2 = fork();
  if(pid2 < 0) {
    printf("fork failed\n");
    exit(1);
  }
  if(pid2 == 0)
    for(;;)
      ;
  pipe(pfds);
  pid3 = fork();
  if(pid3 < 0) {
     printf("fork failed\n");
     exit(1);
  }
  if(pid3 == 0){
    close(pfds[0]);
    if(write(pfds[1], "x", 1) != 1)
      printf("preempt write error");
    close(pfds[1]);
    for(;;)
      ;
  }
  close(pfds[1]);
  if(read(pfds[0], buf, sizeof(buf)) != 1){
    printf("preempt read error");
    return;
  }
  close(pfds[0]);
  printf("kill... ");
  kill(pid1);
  kill(pid2);
  kill(pid3);
  printf("wait... ");
  wait(0);
  wait(0);
  wait(0);
  printf("preempt ok\n");
}
void preempt ( void ) { int pid1 , pid2 , pid3 ; int pfds [ 2 ] ; printf ( " " ) ; pid1 = fork ( ) ; if ( pid1 < 0 ) { printf ( " " ) ; exit ( 1 ) ; } if ( pid1 == 0 ) for ( ; ; ) ; pid2 = fork ( ) ; if ( pid2 < 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } if ( pid2 == 0 ) for ( ; ; ) ; pipe ( pfds ) ; pid3 = fork ( ) ; if ( pid3 < 0 ) { printf ( " \n " ) ; exit ( 1 ) ; } if ( pid3 == 0 ) { close ( pfds [ 0 ] ) ; if ( write ( pfds [ 1 ] , " " , 1 ) != 1 ) printf ( " " ) ; close ( pfds [ 1 ] ) ; for ( ; ; ) ; } close ( pfds [ 1 ] ) ; if ( read ( pfds [ 0 ] , buf , sizeof ( buf ) ) != 1 ) { printf ( " " ) ; return ; } close ( pfds [ 0 ] ) ; printf ( " " ) ; kill ( pid1 ) ; kill ( pid2 ) ; kill ( pid3 ) ; printf ( " " ) ; wait ( 0 ) ; wait ( 0 ) ; wait ( 0 ) ; printf ( " \n " ) ; }
meant to be run w/ at most two CPUs
meant to be run w / at most two CPUs