Change the signal handler to print a message to standard out (use the MESSAGE format in the starter code) that provides both the total number of reads completed and the time elapsed (s seconds).
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>

/* Message to print in the signal handling function. */
#define MESSAGE "%ld reads were done in %ld seconds.\n"

/* Global variables to store number of read operations and seconds elap> */
long num_reads, seconds;

/* Signal handler.
 */
void handle(int signal) {
    fprintf(stdout, MESSAGE, num_reads, seconds);
    exit(0);
}

/* The first command-line argument is the number of seconds to set a ti> * The second argument is the name of a binary file containing 100 ints. * Assume both of these arguments are correct.
 */
 int main(int argc, char **argv) {
    if (argc != 3) {
        fprintf(stderr, "Usage: time_reads s filename\n");
        exit(1);
    }
    seconds = strtol(argv[1], NULL, 10);

    FILE *fp;
    if ((fp = fopen(argv[2], "r")) == NULL) {
      perror("fopen");
      exit(1);
    }

    /* Signal handler
     */
    struct sigaction sig_action;
    sig_action.sa_handler = &handle;
    sig_action.sa_flags = 0;
    sigemptyset(&sig_action.sa_mask);

    if (sigaction(SIGPROF, &sig_action, NULL) != 0) {
        perror("sigaction");
        exit(1);
    }

    /* Timer
     */
    struct itimerval timer;
    timer.it_value.tv_sec = seconds;
    timer.it_value.tv_usec = 0;
    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_usec = 0;
    if (setitimer(ITIMER_PROF, &timer, NULL) == -1) {
        perror("timer");
        exit(1);
            }

    int randomi;
    int random_offset;
    num_reads = 0;

    /* In an infinite loop, read an int from a random location in the f>     * and print it to stderr.
     */
    for (;;) {
        random_offset = random() % 100 * sizeof(int);
        fseek(fp, random_offset, SEEK_SET);
        fread(&randomi, sizeof(randomi), 1, fp);
        printf("%d\n", randomi);

        num_reads += 1;
    }
    return 1; // something is wrong if we ever get here!
}