cs 110 summer 2018 midterm review session
play

CS 110 Summer 2018 Midterm Review Session Matthew Katzman Thanks - PowerPoint PPT Presentation

CS 110 Summer 2018 Midterm Review Session Matthew Katzman Thanks to Ryan Eberhardt Kristine Guo Grace Hong Hemanth Kini for some slide materials. Exam Time Monday, July 23 7PM-9PM Hewlett 201 Study Resources Be sure to look over:


  1. CS 110 Summer 2018 Midterm Review Session Matthew Katzman Thanks to Ryan Eberhardt Kristine Guo Grace Hong Hemanth Kini for some slide materials.

  2. Exam Time Monday, July 23 7PM-9PM Hewlett 201

  3. Study Resources Be sure to look over: ● Assignments and Class Notes ● Labs and Handouts ● Practice Midterms

  4. FILESYSTEMS See assign1

  5. The Important Types ● The Inode ● The File ● The Directory ● The Link

  6. The Inode/FIle Layers

  7. Directories ● A DIRECTORY IS A FILE ● Stores some important information, but mostly made up of dirEnt’s (directory entries) ● Each of these consists of a filename and an inumber.

  8. Links (two types) HARD LINKS: SYMBOLIC (soft) LINKS: ● The SAME as directory entries ● Different type of file ● Map a filename to an inumber ● File contents include path to file ● Increase the file’s reference count ● Does not increase reference count

  9. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him?

  10. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (/) Inode Block 1 . 2 1 .. Refcnt: 4 DIRECTORY 2 MCU ( /MCU ) 3 wormhole

  11. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (MCU) Inode Block 2 . 4 1 .. Refcnt: 4 DIRECTORY 4 space ( /MCU/space ) 5 quinjet

  12. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (space) Inode Block 4 . 6 2 .. Refcnt: 3 DIRECTORY 6 Sakaar ( /MCU/space/ Sakaar ) 7 Asgard

  13. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (Sakaar) Inode Block 6 . 8 4 .. Refcnt: 3 DIRECTORY 8 arena ( /MCU/space/ Sakaar/arena ) 9 monster.smash

  14. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (arena) Inode Block 5 . 9 2 .. Refcnt: 2 9 Hulk.smash “HULK...SMASH!” 10 Waititi

  15. Where’s Hulk? Hulk is located at /MCU/space/Sakaar/arena/Hulk.smash. How can we find him? DIRECTORY (/) Inode Block 1 . 3 1 .. Refcnt: 1 “/MCU/space/ 2 MCU Sakaar” 3 wormhole

  16. The Filesystem Tables (stored in Kernel Space) Vnode table a.txt b.txt c.txt d.txt

  17. The Filesystem Tables status = r, refcnt = ? status = r, refcnt = ? status = w, refcnt = ? status = w, refcnt = ? File entry cursor = 10 cursor = 0 cursor = 50 cursor = 15 table refcnt = 1 refcnt = 2 refcnt = 1 type = FILE type = FILE type = FILE Vnode table inumber = 17 inumber = 32 inumber = 5

  18. The Filesystem Tables 0 1 2 3 4 5 6 7 File STDIN STDOUT STDERR descriptor table status = r, refcnt = 2 status = r, refcnt = 1 status = w, refcnt = 1 status = w, refcnt = 1 File entry cursor = 10 cursor = 0 cursor = 50 cursor = 15 table refcnt = 1 refcnt = 2 refcnt = 1 type = FILE type = FILE type = FILE Vnode table inumber = 17 inumber = 32 inumber = 5

  19. The Filesystem Tables 0 1 2 3 4 5 6 7 File STDIN STDOUT STDERR descriptor table status = r, refcnt = 2 status = r, refcnt = 1 status = w, refcnt = 1 status = w, refcnt = 0 File entry cursor = 10 cursor = 0 cursor = 50 cursor = 15 table refcnt = 1 refcnt = 2 refcnt = 1 type = FILE type = FILE type = FILE Vnode table inumber = 17 inumber = 32 inumber = 5

  20. The Filesystem Tables 0 1 2 3 4 5 6 7 File STDIN STDOUT STDERR descriptor table status = r, refcnt = 2 status = r, refcnt = 1 status = w, refcnt = 1 File entry cursor = 10 cursor = 0 cursor = 50 table refcnt = 1 refcnt = 2 refcnt = 0 type = FILE type = FILE type = FILE Vnode table inumber = 17 inumber = 32 inumber = 5

  21. The Filesystem Tables 0 1 2 3 4 5 6 7 File STDIN STDOUT STDERR descriptor table status = r, refcnt = 2 status = r, refcnt = 1 status = w, refcnt = 1 File entry cursor = 10 cursor = 0 cursor = 50 table refcnt = 1 refcnt = 2 type = FILE type = FILE Vnode table inumber = 17 inumber = 32

  22. MULTIPROCESSING See assign2, assign3

  23. System Calls Interact with the raw blocks that users do not (and ● Syscalls you should know: should not) have access to (privileged operations) ○ open() ○ read() ○ write() ○ close() ○ pipe() ○ dup2() ○ fork() ○ execvp() ○ kill() ○ waitpid() ○ kill() ○ signal() ○ sigprocmask() ○ sigsuspend()

  24. pipe(int[] fds) STDIN STDOUT STDERR

  25. pipe(int[] fds) STDIN STDOUT STDERR status = r, refcnt = 1, cursor = 0 status = w, refcnt = 1, cursor = 0 refcnt = 1, type = PIPE refcnt = 1, type = PIPE

  26. fork() STDIN STDOUT STDERR status = r, refcnt = 1, cursor = 0 status = w, refcnt = 1, cursor = 0 refcnt = 1, type = PIPE refcnt = 1, type = PIPE

  27. fork() STDIN STDOUT STDERR STDIN STDOUT STDERR status = r, refcnt = 2, cursor = 0 status = w, refcnt = 2, cursor = 0 refcnt = 1, type = PIPE refcnt = 1, type = PIPE

  28. dup2(int oldfd, int newfd) Calling dup2(3, STDIN_FILENO) in child: STDIN STDOUT STDERR STDIN STDOUT STDERR status = r, refcnt = 2, cursor = 0 status = w, refcnt = 2, cursor = 0 refcnt = 1, type = PIPE refcnt = 1, type = PIPE

  29. dup2(int oldfd, int newfd) Calling dup2(3, STDIN_FILENO) in child: STDIN STDOUT STDERR STDIN STDOUT STDERR status = r, refcnt = 3, cursor = 0 status = w, refcnt = 2, cursor = 0 refcnt = 1, type = PIPE refcnt = 1, type = PIPE

  30. What will print here? void createUltron() { int main(int argc, char* argv[]) { pid_t pid = fork(); createUltron(); if (pid == 0) { while(true) { printf(“Ultron is here.”); pid_t pid = waitpid(-1, NULL, 0); } if (pid == -1) break; printf(“Jarvis is here.”); } } assert(errno == ECHILD); printf(“The world is safe.”); }

  31. What will print here? void createUltron() { int main(int argc, char* argv[]) { pid_t pid = fork(); createUltron(); if (pid == 0) { while(true) { printf(“Ultron is here.”); pid_t pid = waitpid(-1, NULL, 0); return; if (pid == -1) break; } } printf(“Jarvis is here.”); assert(errno == ECHILD); } printf(“The world is safe.”); }

  32. What will print here? void createUltron() { int main(int argc, char* argv[]) { pid_t pid = fork(); createUltron(); if (pid == 0) { while(true) { printf(“Ultron is here.”); pid_t pid = waitpid(-1, NULL, 0); exit(0); if (pid == -1) break; } } printf(“Jarvis is here.”); assert(errno == ECHILD); } printf(“The world is safe.”); }

  33. waitpid() First argument ( pid_t pid ): Third argument ( int options ) ● <-1 (any child with pgid = | pid | ● 0 (returns only after child terminates) ● -1 (any child) ● WUNTRACED (also after child stops) ● 0 (any child with pgid = getpgid()) ● WNOHANG (returns immediately) ● >0 the child with pid = pid . ● WCONTINUED (also after child continues) Second argument ( int* status ): ● Create int status and pass in &status ○ WIFEXITED(status) ○ WIFSTOPPED(status) ○ WIFCONTINUED(status)

  34. Signals The ones you should know: ● SIGINT (ctrl + C) ● SIGTSTP (ctrl + Z) The two above can be caught and handled. The two below cannot: ● SIGKILL ● SIGSTOP Wrong universe, but it worked too well... These have the same respective behavior, but cannot be caught. ● SIGCHLD ● SIGCONT

  35. sigsuspend(const sigset_t* mask) Does the following ATOMICALLY: sigprocmask(SIG_SETMASK, &mask, &old); ● sleep(); // wait for signal to wake us up ● sigprocmask(SIG_SETMASK, &old, NULL); ●

  36. What will print? int counter = 0; static void reapChild(int sig) { printf(“Wakanda Forever!”); counter++; } int main(int argc, char* argv[]) { pid_t pid = fork(); if (pid == 0) { char[] argv = [“echo”, “Black Panther”, NULL]; execvp(argv[0], argv); } sigset_t mask; sigemptyset(&mask); while (counter < 1) { sigsuspend(&mask); } printf(“T\’Challa has won.”); }

  37. What will print? int counter = 0; static void reapChild(int sig) { printf(“Wakanda Forever!”); counter++; } int main(int argc, char* argv[]) { pid_t pid = fork(); if (pid == 0) { char[] argv = [“echo”, “Black Panther”, NULL]; execvp(argv[0], argv); } sigset_t mask; RACE CONDITION!!! sigemptyset(&mask); while (counter < 1) { sigsuspend(&mask); } printf(“T\’Challa has won.”); }

  38. What will print? int counter = 0; static void reapChild(int sig) { printf(“Wakanda Forever!”); counter++; } int main(int argc, char* argv[]) { pid_t pid = fork(); if (pid == 0) { char[] argv = [“echo”, “Black Panther”, NULL]; execvp(argv[0], argv); } sigset_t mask; sigemptyset(&mask); sigset_t existing = blockSIGCHLD(); while (counter < 1) { sigsuspend(&mask); } unblockSIGCHLD(existing); printf(“T\’Challa has won.”); }

  39. sigprocmask(int how, const sigset_t* set, sigset_t* oldset) sigset_t blockSIGCHLD() { sigset_t mask; sigset_t existing; sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_BLOCK, &mask, &existing); return existing; } void unblockSIGCHLD(sigset_t existing) { sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_UNBLOCK, &mask, &existing); }

  40. Virtual Memory

Recommend


More recommend