os:lab02
Return to Home page
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab02?do=diff&rev2%5B0%5D=1566254072&rev2%5B1%5D=1566254249&difftype=sidebyside
Differences
This shows you the differences between two versions of the page.
— | os:lab02 [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Return to [[os: | ||
+ | ---- | ||
+ | ====== Operating Systems Course: Lab02 ====== | ||
+ | ===== Laboratory number 02 ===== | ||
+ | |||
+ | |||
+ | ==== Exercise 01: Analysis of concurrent programs ==== | ||
+ | |||
+ | Represent the //control flow graph// (CFG) and the //process generation tree// of the following pieces of code. In addition, indicate the output produced on the video. Check the results you predicted, by executing the program. | ||
+ | |||
+ | A. | ||
+ | <code c lab02_e01_A.c> | ||
+ | for (i=1; i<=2; i++) { | ||
+ | if (!fork ()) | ||
+ | printf (" | ||
+ | } | ||
+ | printf (" | ||
+ | </ | ||
+ | |||
+ | B. | ||
+ | <code c lab02_e01_B.c> | ||
+ | for(i=3; i>1; i--) { | ||
+ | if (fork ()) | ||
+ | printf (" | ||
+ | } | ||
+ | printf (" | ||
+ | </ | ||
+ | |||
+ | C. | ||
+ | <code c lab02_e01_C.c> | ||
+ | for (i=0; i<2; i++) { | ||
+ | if (fork ()) | ||
+ | fork (); | ||
+ | } | ||
+ | printf (" | ||
+ | </ | ||
+ | |||
+ | D. | ||
+ | <code c lab02_e01_D.c> | ||
+ | for (i=2; i>=1; i--) { | ||
+ | if (!fork ()) | ||
+ | printf (" | ||
+ | else | ||
+ | printf (" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Exercise 02: System call fork and shell commands related to processes ==== | ||
+ | |||
+ | A program receives two integer values on the command line, called '' | ||
+ | |||
+ | Once the program has been executed: | ||
+ | * look for the pid of the various processes with the command ps | ||
+ | - from the same shell | ||
+ | - from another shell | ||
+ | * terminate the execution of some processes with the kill command executed | ||
+ | - from the same shel | ||
+ | - from another shell | ||
+ | |||
+ | |||
+ | ==== Exercise 03: Precedence graph ==== | ||
+ | |||
+ | Using the system calls fork and wait, realize the following precedence graph. | ||
+ | |||
+ | < | ||
+ | P1 | ||
+ | / | ||
+ | / \ | ||
+ | P2 P3 | ||
+ | /\ /\ | ||
+ | / | ||
+ | | ||
+ | | ||
+ | \/ \/ | ||
+ | P7 P8 | ||
+ | \ / | ||
+ | | ||
+ | P9 | ||
+ | </ | ||
+ | |||
+ | Note that all arcs are oriented downwards. Each Pi process corresponds to a print message (print the string " | ||
+ | |||
+ | Check the precedence are respected by inserting the system call '' | ||
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab02?do=diff&rev2%5B0%5D=1566254072&rev2%5B1%5D=1566254249&difftype=sidebyside
/web/htdocs/www.skenz.it/home/data/pages/os/lab02.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1