previous | start | next

Ch 8 Review Problem 1

What is the output of this program?

      int val;
      void handler(sig)
      {
        val += 5;
        return;
      }

      int main()
      {
         pid_t pid;
         
         signal(SIGCHLD, handler);
         if ((pid = fork()) == 0 ) {
            val -= 3;
            exit(0);
         }
         waitpid(pid, NULL, 0);
         printf("val = "%d\n", val);
         exit(0);
      }
    
   


previous | start | next