use sigactionLinks to add a signal handler to your program. Start with something simple that just prints a message to standard out and exits (with termination code 0) when it receives a SIGPROF.
void handler(int sig){
  printf("SIGPROF received");
  exit(0);
}
int main(int argc, char **argv) {
    struct sigaction newact;
    newact.sa_handler = handler;
    newact.sa_flags = 0;
    sigemptyset(&newact.sa_mask);
    sigaction(SIGINT, &newact, NULL);

    /* In an infinite loop, read an int from a random location in the file,
     * and print it to stderr.
     */
    for (;;) {

      int offset = rand() % 100;
      int read_num;

      fseek(fp, offset, SEEK_SET);
      fread(&read_num, sizeof(int), 1, fp);
      fprintf(stderr, "%d", read_num);

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