Brock University -- Department of Computer Science

COSC 4P13 - Operating Systems Design and Implementation - Fall 2010

Assignment #3

Due:      Nov 02, 2010, 3:30 in the class                                                                           
Late :    Nov 05, 2010, 1 p.m. to the secretary


1. Study the program given below, find out what is it supposed to do and run it appropriately. Log the output.

2. Replace then the y++ function by another mathematical function which will take more time to compute so you have

   more time to test the program. Run it and log the output.

3. Modify then the program of p.2 in such a way that it can block and unblock the SIGQUIT signal

   in addition to the SIGINT and will print a message appropriate to the signal. Run the modified program and log

   its output.

4. Modify then the program of p.3 in such a way that it will use its own exit handler "show_times" which will cause statistics

   about the time used by the program to be output to the standard error before the program terminates. You may use for this the atexit C function,

   which installs a user-defined exit  handler.To get the timing information use the times function, which returns the number of clock ticks.

   Convert the time to seconds by dividing it by the number of   clock ticks per second found by calling sysconf.


#include <math.h>

#include <signal.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>


int main(int argc,  char *argv[]) {

   int i;

   sigset_t intmask;

   int repeatfactor;

   double y = 0.0;


   if (argc != 2) {

      fprintf(stderr, "Usage: %s repeatfactor\n", argv[0]);

      return 1;


   repeatfactor = atoi(argv[1]);

   if ((sigemptyset(&intmask) == -1) || (sigaddset(&intmask, SIGINT) == -1)){

      perror("Failed to initialize the signal mask");

      return 1;


   for ( ; ; ) {

      if (sigprocmask(SIG_BLOCK, &intmask, NULL) == -1)


      fprintf(stderr, "SIGINT signal blocked\n");

      for (i = 0; i < repeatfactor; i++)


      fprintf(stderr, "Blocked calculation is finished, y = %f\n", y);

      if (sigprocmask(SIG_UNBLOCK, &intmask, NULL) == -1)


      fprintf(stderr, "SIGINT signal unblocked\n");

      for (i = 0; i < repeatfactor; i++)


      fprintf(stderr, "Unblocked calculation is finished, y=%f\n", y);


   perror("Failed to change signal mask");

   return 1;





1. Run your programs under Centos in J 310. 

2. Submit program listings and all the output logs in an assignment envelope

    and copy your executable files to the assignment directory by using the command submit4p13.



HomeComputer Science home page UpCOSC 4P13 Home Page

URL of this document:

Instructor: J. A. Barchanski
copyright Jerzy A. Barchanski