text: // a program that uses UNIX system calls to ''ping-pong'' 
  // a byte between two processes over a pair of pipes, 
  // one for each direction
  
  #include "kernel/types.h"
  #include "kernel/stat.h"
  #include "user/user.h"
  
  int main(){
      
      // pipe
      int p[2];
      pipe(p);
  
      // the string buffer containing one char
      char buf[1];
  
      if(fork() == 0){ //the child process
  
          // receive information from parent
          if(read(p[0], buf, 1) != 1){
              printf("child read error\n");
              exit(1);
          }else{
              printf("%d: received ping\n", getpid());
          }
  
          // leave message to parent through pipe
          if(write(p[1], buf, 1) != 1){
              printf("child write error\n");
              exit(1);
          }
  
          close(p[0]);
          close(p[1]);
          exit(0);
  
      }else{ // the parent process
  
          // send information to child through pipe
          if(write(p[1], "a", 1) != 1){
              printf("parent write error\n");
              exit(1);
          }
  
          // waiting for the termination of child 
          if(wait((int *) 0) < 0) {
              printf("waiting error\n");
              exit(1);
          }
  
          // receive information from child
          if(read(p[0], buf, 1) != 1){
              printf("parent read error\n");
              exit(1);
          }else{
              printf("%d: received pong\n", getpid());
          }
  
  
          close(p[1]);
          close(p[0]);
      }
      
      exit(0);
  }