text: #include "apue.h"
  
  #define BUFFSIZE    1024
  
  static void sig_tstp(int signo)
  {
      sigset_t mask;
  
      sigemptyset(&mask);
      sigaddset(&mask, SIGTSTP);
      sigprocmask(SIG_UNBLOCK, &mask, NULL);
      signal(SIGTSTP, SIG_DFL);
      kill(getpid(), SIGTSTP);
      signal(SIGTSTP, sig_tstp);
  }
  
  int main(void)
  {
      int n = 0;
      char buf[BUFFSIZE] = {'\0'};
  
      if (SIG_DFL == signal(SIGTSTP, SIG_IGN)) {
          signal(SIGTSTP, sig_tstp);
      }
  
      while (1) {
          n = read(STDIN_FILENO, buf, BUFFSIZE);
          if (n <= 0) {
              break;
          }
  
          if (write(STDOUT_FILENO,buf,n) != n) {
              err_sys("write error");
          }
      }
  
      if (n < 0) {
          err_sys("read error");
      }
  
      return 0;
  }
  