Computer
Systems

Fall 2018
course
site

Oct 30

aside : Teaching C | HackerNews discussion

Continuing to discuss chap 8 , 14-ecf-procs.pdf & 15-ecf-signals.pdf ...

homework

practice 8.3 : fork , fflush , waitpid

int main(){ 
  if (Fork() == 0) {
    printf("a"); fflush(stdout); 
  } else { 
    printf("b"); fflush(stdout); 
    waitpid(-1, NULL, 0); 
  } 
  printf("c"); fflush(stdout); 
  exit(0); 
}
/* from Bryant, Randal E., David O'Hallaron. Computer Systems, 3rd Edition */

practice 8.7 ... discuss after talking about signals.

signals

Trick stuff ...

topics

practice 8.7 ...

/***********
 * snooze2.c
 * 
 *  on shannon : 
 *  $ gcc -O -pthread csapp.c snooze.c -o snooze
 *  $ ./snooze 10   # control-c 
 * 
 * Minor changes to snooze.c
 * from Bryant, Randal E., David O'Hallaron. Computer Systems, 3rd Edition. 
 ***********/
#include "csapp.h"
void sigint_handler(int sig){
  return; /* Catch the signal and return */
}
void snooze(unsigned int secs) {
  unsigned int slept = sleep(secs);
  printf ("Slept for %d of %d secs.\n", secs - slept, secs);
}
int main(int argc, char **argv){
  if (argc != 2) { 
    fprintf (stderr, "usage: %s <secs>\n", argv[0]);
    exit(0);
  }
  if (signal(SIGINT, sigint_handler) == SIG_ERR){ 
    unix_error("signal error\n");
  }
  snooze(atoi(argv[1]));
  exit(0);
}

Discuss

To do for Thursday :

https://cs.marlboro.college /cours /fall2018 /systems /notes /killdash9
last modified Sun October 17 2021 1:40 pm

attachments [paper clip]

  last modified size
TXT snooze2.c Sun Oct 17 2021 01:40 pm 855B