changelog
play

Changelog Changes made in this version not seen in fjrst lecture: 6 - PowerPoint PPT Presentation

Changelog Changes made in this version not seen in fjrst lecture: 6 September: fjx stray @s on implementing fjle descriptors in xv6 slide 6 September: typical pattern with redirection: hilite parts of code more sensibly 6 September: exec


  1. Changelog Changes made in this version not seen in fjrst lecture: 6 September: fjx stray @s on ‘implementing fjle descriptors in xv6 slide’ 6 September: typical pattern with redirection: hilite parts of code more sensibly 6 September: exec preserves open fjles: add slide 6 September: dup2 example: clarify comment, note overall purpose at top 6 September: read’ing one byte at a time: missing ) 6 September: layering: annotate to indicate read/write are system calls, kernel bufgers in layers, user bufgers in layers 0

  2. Unix API 2: fjles 1

  3. last time POSIX — standardized Unix process control blocks fork, exec, waitpid 2

  4. post-quizzes starting this week, post-quizzes link ofg course website same software as CS 3330 box around question turns green: answer recorded no time limits, due before Tuesday’s class released Friday morning or possibly earlier (e.g. Thursday evening) 3

  5. shell allow user (= person at keyborad) to run applications user’s wrapper around process-management functions upcoming homework — make a simple shell 4

  6. aside: shell forms POSIX: command line you have used before also: graphical shells e.g. OS X Finder, Windows explorer other types of command lines? completely difgerent interfaces? 5

  7. some POSIX command-line features searching for programs (not in assignment) running in background (not in assignment) ./someprogram & redirection: ./someprogram >output.txt ./someprogram <input.txt pipelines: ./someprogram | ./somefilter 6 ls -l ≈ /bin/ls -l make ≈ /usr/bin/make

  8. some POSIX command-line features searching for programs (not in assignment) running in background (not in assignment) ./someprogram & redirection: ./someprogram >output.txt ./someprogram <input.txt pipelines: ./someprogram | ./somefilter 7 ls -l ≈ /bin/ls -l make ≈ /usr/bin/make

  9. searching for programs POSIX convention: PATH environment variable example: /home/cr4bd/bin:/usr/bin:/bin checked in order one way to implement: [pseudocode] for (directory in path) { } 8 execv(directory + "/" + program_name, argv);

  10. some POSIX command-line features searching for programs (not in assignment) running in background (not in assignment) ./someprogram & redirection: ./someprogram >output.txt ./someprogram <input.txt pipelines: ./someprogram | ./somefilter 9 ls -l ≈ /bin/ls -l make ≈ /usr/bin/make

  11. running in background $ ./long_computation >tmp.txt & [1] 4049 $ ... [1]+ Done ./long_computation > tmp.txt $ cat tmp.txt the result is ... & — run a program in “background” initially output PID (above: 4049) print out after terminated one way: use waitpid with option saying “don’t wait” 10

  12. some POSIX command-line features searching for programs (not in assignment) running in background (not in assignment) ./someprogram & redirection: ./someprogram >output.txt ./someprogram <input.txt pipelines: ./someprogram | ./somefilter 11 ls -l ≈ /bin/ls -l make ≈ /usr/bin/make

  13. shell redirection ./my_program ... <input.txt : run ./my_program ... but use input.txt as input like we copied and pasted the fjle into the terminal echo foo >output.txt : runs echo foo , sends output to output.txt like we copied and pasted the output into that fjle (as it was written) 12

  14. exec preserves open fjles the process control block discarded old memory not changed! copy arguments new stack, heap, … executable fjle loaded from memory … user regs … fd 1: … fd 0: (terminal …) open fjles user memory kernel stack ecx=133 init. val. , … eax=42 init. val. , 13

  15. exec preserves open fjles the process control block discarded old memory not changed! copy arguments new stack, heap, … executable fjle loaded from memory … user regs … fd 1: … fd 0: (terminal …) open fjles user memory kernel stack ecx=133 init. val. , … eax=42 init. val. , 13

  16. exec preserves open fjles the process control block discarded old memory not changed! copy arguments new stack, heap, … executable fjle loaded from memory … user regs … fd 1: … fd 0: (terminal …) open fjles user memory kernel stack ecx=133 init. val. , … eax=42 init. val. , 13

  17. exec preserves open fjles the process control block discarded old memory not changed! copy arguments new stack, heap, … executable fjle loaded from memory … user regs … fd 1: … fd 0: (terminal …) open fjles user memory kernel stack ecx=133 init. val. , … eax=42 init. val. , 13

  18. fork copies open fjles eax=420, copy copy child process control block … … fd 1: … fd 0: … open fjles user memory kernel stack ecx=133, … user regs user regs memory parent process control block … … fd 1: … fd 0: … open fjles user memory kernel stack ecx=133, … pid , eax=42 child (new) 14

  19. typical pattern with redirection } else if (pid > 0) { … pid = fork(); if (pid == 0) { open new files; exec…(…); … waitpid(pid,…); … … } … main() { … } } waitpid(pid,…); pid = fork(); … if (pid == 0) { open new files; exec…(…); … } else if (pid > 0) { waitpid(pid,…); } } else if (pid > 0) { … pid = fork(); if (pid == 0) { open new files; exec…(…); … 15

  20. redirecting with exec std output, std error are fjles yes, your terminal is a fjle more on this later after forking, open fjles to redirect …and make them be standard output/error missing pieces: how open fjles becomes default output/input 16

  21. some POSIX command-line features searching for programs (not in assignment) running in background (not in assignment) ./someprogram & redirection: ./someprogram >output.txt ./someprogram <input.txt pipelines: ./someprogram | ./somefilter 17 ls -l ≈ /bin/ls -l make ≈ /usr/bin/make

  22. shell assignment implement a simple shell that supports redirection and pipeline …and prints the exit code of program in the pipeline simplifjed parsing: space-seperated: 18 okay: /bin/ls ␣ -1 ␣ > ␣ tmp.txt not okay: /bin/ls ␣ -l ␣ >tmp.txt okay: /bin/ls ␣ -1 ␣ | ␣ /bin/grep ␣ foo ␣ > ␣ tmp.txt not okay: /bin/ls ␣ -1 ␣ |/bin/grep ␣ foo ␣ >tmp.txt

  23. POSIX: everything is a fjle the fjle: one interface for devices (terminals, printers, …) regular fjles on disk networking (sockets) local interprocess communication (pipes, sockets) basic operations: open(), read(), write(), close() 19

  24. the fjle interface open before use setup, access control happens here byte-oriented real device isn’t? operating system needs to hide that explicit close 20

  25. the fjle interface open before use setup, access control happens here byte-oriented real device isn’t? operating system needs to hide that explicit close 20

  26. kernel bufgering (reads) …via bufger …via bufger data from disk bufger: recently read read block of data from disk from fjle read char from terminal program read char waiting for program bufger: keyboard input keypress happens, read disk keyboard operating system 21

  27. kernel bufgering (reads) …via bufger …via bufger data from disk bufger: recently read read block of data from disk from fjle read char from terminal program read char waiting for program bufger: keyboard input keypress happens, read disk keyboard operating system 21

  28. kernel bufgering (reads) …via bufger …via bufger data from disk bufger: recently read read block of data from disk from fjle read char from terminal program read char waiting for program bufger: keyboard input keypress happens, read disk keyboard operating system 21

  29. kernel bufgering (reads) …via bufger …via bufger data from disk bufger: recently read read block of data from disk from fjle read char from terminal program read char waiting for program bufger: keyboard input keypress happens, read disk keyboard operating system 21

  30. kernel bufgering (reads) …via bufger …via bufger data from disk bufger: recently read read block of data from disk from fjle read char from terminal program read char waiting for program bufger: keyboard input keypress happens, read disk keyboard operating system 21

  31. kernel bufgering (writes) to remote machine to be written on disk bufger: data waiting write block of data from disk (when ready) to fjle write char print char program waiting for network bufger: output send data (when ready) disk network operating system 22

  32. kernel bufgering (writes) to remote machine to be written on disk bufger: data waiting write block of data from disk (when ready) to fjle write char print char program waiting for network bufger: output send data (when ready) disk network operating system 22

  33. kernel bufgering (writes) to remote machine to be written on disk bufger: data waiting write block of data from disk (when ready) to fjle write char print char program waiting for network bufger: output send data (when ready) disk network operating system 22

  34. kernel bufgering (writes) to remote machine to be written on disk bufger: data waiting write block of data from disk (when ready) to fjle write char print char program waiting for network bufger: output send data (when ready) disk network operating system 22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend