os:lab03
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/lab03?rev=1572441475&do=diff
Differences
This shows you the differences between two versions of the page.
— | os:lab03 [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Return to [[os: | ||
+ | ---- | ||
+ | ====== Operating Systems Course: Lab03 ====== | ||
+ | ===== Laboratory number 03 ===== | ||
+ | |||
+ | |||
+ | ==== Exercise 01: System call fork, exec, system ==== | ||
+ | |||
+ | Report the //control flow graph// (CFG) and the //process generation tree// for the following C program. | ||
+ | |||
+ | In addition, indicate what it produces in output on the screen and for which reason. | ||
+ | |||
+ | <code c lab04_e01.c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main () { | ||
+ | char str[100]; | ||
+ | int i; | ||
+ | |||
+ | setbuf(stdout, | ||
+ | fork(); | ||
+ | for (i=0; i<2; i++){ | ||
+ | if (fork()!=0) { | ||
+ | sprintf (str, "echo system with i=%d", i); | ||
+ | system (str); | ||
+ | } else { | ||
+ | sprintf (str, "exec with i=%d", i); | ||
+ | execlp (" | ||
+ | } | ||
+ | } | ||
+ | return (0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Exercise 02: System call fork, exec, system ==== | ||
+ | |||
+ | Report the //control flow graph// (CFG) and the //process generation tree// for the following C program. | ||
+ | |||
+ | In addition, indicate what it produces in output on the screen and for which reason. | ||
+ | |||
+ | <code c lab04_e02.c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main () { | ||
+ | int i = 0; | ||
+ | |||
+ | setbuf(stdout, | ||
+ | while (i<=2 && fork()){ | ||
+ | if (!fork()) { | ||
+ | fprintf (stdout, " | ||
+ | execlp (" | ||
+ | } | ||
+ | i++; | ||
+ | fprintf (stdout, " | ||
+ | system ("echo i+i"); | ||
+ | } | ||
+ | |||
+ | return (0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Exercise 03: System call fork, wait, exec, system ==== | ||
+ | |||
+ | A file contains strings logically grouped into distinct sets. | ||
+ | Any set of strings indicates a Unix/Linux command and the related parameters. | ||
+ | Each set is terminated with the string " | ||
+ | The following is an example of correct file: | ||
+ | |||
+ | <code bash commands.txt> | ||
+ | touch mioFile.c end | ||
+ | ls -laR end | ||
+ | cat mioFile.c end | ||
+ | mkdir -p tmpDir end | ||
+ | cp -f mioFile.c tmpDir end | ||
+ | </ | ||
+ | |||
+ | Observe that, if you prefer, you can assume that the string " | ||
+ | |||
+ | Write a program that, after receiving the name of the file through the command line, executes the Unix/Linux command listed in the file by using: | ||
+ | * the system call '' | ||
+ | * 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/lab03?rev=1572441475&do=diff