C csapp improperly synchronized pthreads program 574

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: “1” in line 10 and “Bye” in line 16, and then terminates with an exit status of 2 in line 17. After the child terminates, the parent resumes, printing the child’s exit status in line 14 and “Bye” in line 16. Problem 8.5 Solution: [Pg. 415] code/ecf/snooze.c 1 2 3 4 5 unsigned int snooze(unsigned int secs) { unsigned int rc = sleep(secs); printf("Slept for %u of %u secs.\n", secs - rc, secs); return rc; } code/ecf/snooze.c Problem 8.6 Solution: [Pg. 417] code/ecf/myecho.c 1 2 3 4 5 #include "csapp.h" int main(int argc, char *argv, char *envp) { int i; B.8. EXCEPTIONAL CONTROL FLOW 6 7 8 9 10 11 12 13 14 15 16 17 727 printf("Command line arguments:\n"); for (i=0; argv[i] != NULL; i++) printf(" argv[%2d]: %s\n", i, argv[i]); printf("\n"); printf("Environment variables:\n"); for (i=0; envp[i] != NULL; i++) printf(" envp[%2d]: %s\n", i, envp[i]); exit(0); } code/ecf/myecho.c Problem 8.7 Solution: [Pg. 429] The sleep...
View Full Document

Ask a homework question - tutors are online