CS 3733 Operating Systems Classroom Activity on Sigaction


Note: if you have done the previous activty on signals, you can skip steps 3-7
  1. Log on to your Linux account.
  2. Run ~srobbins/cr3733 and log your progress on this activity.
  3. Make a directory called ch08.
  4. Download the USP Chapter 8 tar file from here.
  5. Untar the program into your ch08 directory.
  6. Execute convertlinux in this directory.
  7. Execute make in this directory.
  8. Execute:
         blocktest 100000000.
    The parameter is 100 million.
    If you use a value that is too small, there will be little time between the messages.
    This value will give you about 4 seconds between them using our current hardware.
    You can double this value if you want more time.
  9. Try pushing CTRL-C while the signal is blocked and while it is not.
  10. Modify blocktest so that it catches the SIGINT signal as in Example 8.16:
    1. Copy the following code and put it above main:
            void catchctrlc(int signo) {
               char handmsg[] = "I found Ctrl-C\n";
               int msglen = sizeof(handmsg);
               write(STDERR_FILENO, handmsg, msglen);
            }
          
    2. Copy the following line with your declarations in main:
               struct sigaction act;
           
    3. Insert the following in blocktest.c before the for loop:
            newact.sa_handler = SIG_DFL;    /* new handler set to default */
            newact.sa_flags = 0;            /* no special options */
            if ((sigemptyset(&newact.sa_mask) == -1) ||
                (sigaction(SIGINT, &newact, NULL) == -1))
               perror("Failed to set SIGINT to the default action");
           
  11. Run the program with:
    ./blocktest 100000
  12. Try to kill the program.
  13. Answer the question about how you killed the program.