Return to Operationg Systems home
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.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main () { char str[100]; int i; setbuf(stdout,0); 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 ("echo", "myPgrm", str, NULL); } } return (0); }
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.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main () { int i = 0; setbuf(stdout,0); while (i<=2 && fork()){ if (!fork()) { fprintf (stdout, "Running Exec ..."); execlp ("echo", "echo", "i*i", (char *) 0); } i++; fprintf (stdout, "Running System ..."); system ("echo i+i"); } return (0); }
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 “end”. The following is an example of correct file:
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 “end” is not present in the file, and it can be substituted with the end-of-line character \n
to indicate the end of the strings associated with a certain command.
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:
system
, executing one command after anotherexec
, executing a command every 3 seconds (you can decide with version of the exec
to use).