We can therefore compute the total time in clock

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 23 24 25 26 27 28 29 #include "csapp.h" int counter = 0; void handler(int sig) { counter++; sleep(1); /* do some work in the handler */ return; } int main() { int i; Signal(SIGUSR2, handler); if (Fork() == 0) { /* child */ for (i = 0; i < 5; i++) { Kill(getppid(), SIGUSR2); printf("sent SIGUSR2 to parent\n"); } exit(0); } Wait(NULL); printf("counter=%d\n", counter); exit(0); } code/ecf/counterprob.c Figure 8.35: Counter program referenced in Problem 8.18. Homework Problem 8.19 [Category 3]: Write a version of the fgets function, called tfgets, that times out after 5 seconds. The tfgets 8.8. SUMMARY 447 function accepts the same inputs as fgets. If the user doesn’t type an input line within 5 seconds, tfgets returns NULL. Otherwise it returns a pointer to the input line. Homework Problem 8.20 [Category 4]: Using the example in Figure 8.20 as a starting point, write a shell program that supports job control. Your shell should have the following features: ¯ The command li...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online