1 / 32

Project #1: Week 3

Project #1: Week 3. Principles of Operating Systems (LAB) COP 4610/CGS 5765. Overview. Pipelining Processes fork() execv () Environment Variables. Clarification in Description. cd "$OLDPWD" && pwd Do not have to implement ‘ && ’

Download Presentation

Project #1: Week 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project #1:Week 3 Principles of Operating Systems (LAB) COP 4610/CGS 5765

  2. Overview • Pipelining • Processes • fork() • execv() • Environment Variables

  3. Clarification in Description • cd "$OLDPWD" && pwd • Do not have to implement ‘&&’ • OLDPWD can be stored as an environment variable, but it is not necessary since there is not requirement to allow user to display them

  4. pipe() • Interprocess data channel #include <unistd.h> intpipe(intfildes[2]); [1] - write [0] - read http://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html

  5. Pipe • ls | grep • fork() x2 • create a pipe • redirect fd=1 of process to be ls to write end of pipe • redirect fd = 0 of process to be grep to read end of pipe • execvgrep and ls binaries

  6. file descriptors 0 stdin 1 stdout 2 stderr Pipe int p1_to_p2[2]; pipe(p1_to_p2); shell

  7. file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); shell

  8. fork() int p1_to_p2[2]; pipe(p1_to_p2); file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell Pipe int p1_to_p2[2]; pipe(p1_to_p2); shell

  9. fork() int p1_to_p2[2]; pipe(p1_to_p2); file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell

  10. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  11. dup(4) file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  12. dup(4) file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  13. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  14. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  15. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  16. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  17. dup(3) file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  18. dup(3) file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  19. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  20. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  21. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  22. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  23. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  24. file descriptors file descriptors file descriptors 0 stdin 1 stdout 2 stderr waitpid(…) waitpid(…) 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); shell shell shell

  25. Process State Diagram exit, kill start zombie (terminated) event occurs ready (competing for execution time) blocked (waiting) wait*() end of life (no allocated resources) interrupt scheduler dispatch running (executing) event wait

  26. fork() • How does the forked process differ? • http://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html

  27. Process State Data/Code Stack Directly accessible Registers File descriptor Table Entries Indirectly accessible (e.g., OS call) . . . Scheduling Information

  28. execv() Executable File Data/Code copy Code Data Stack Registers initialize File descriptor Table Entries . . . Scheduling Information

  29. Environment Variables extern char **environ; • pointer to an array of strings • Required not to directly modify the pointers to which environ points

  30. Parsing Strings • strtok_r() • See code example on website

  31. Process Groups • See example

  32. Questions

More Related