Difference between revisions of "Prove pratiche 2022"
Jump to navigation
Jump to search
(Created page with " = 2022-09-07 = == Esercizio 1 == == Esercizio 2 == == Esercizio 3 == == Esercizio 4 ==") |
|||
| Line 3: | Line 3: | ||
== Esercizio 1 == | == Esercizio 1 == | ||
| + | |||
| + | === Proposta 1 === | ||
| + | |||
| + | Da controllare, 09/03/2023 | ||
| + | |||
| + | <syntaxhighlight lang="C"> | ||
| + | |||
| + | #include <stdio.h> | ||
| + | #include <unistd.h> | ||
| + | #include <sys/wait.h> | ||
| + | #include <sys/types.h> | ||
| + | #include <stdlib.h> | ||
| + | |||
| + | int main(int argc, char *const argv[]) { | ||
| + | if (argc < 2) { | ||
| + | fprintf(stderr, "Non ci sono abbastanza parametri per lo script\n"); | ||
| + | return 1; | ||
| + | } | ||
| + | |||
| + | while (1) { | ||
| + | int wstatus; | ||
| + | if (fork()) { | ||
| + | execvp(argv[1], argv + 1); | ||
| + | } else { | ||
| + | wait(&wstatus); | ||
| + | int status = WEXITSTATUS(wstatus); | ||
| + | printf("return value ***************** %d\n", status); | ||
| + | if (status != 0) { | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </syntaxhighlight> | ||
== Esercizio 2 == | == Esercizio 2 == | ||
Revision as of 14:17, 9 March 2023
2022-09-07
Esercizio 1
Proposta 1
Da controllare, 09/03/2023
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
int main(int argc, char *const argv[]) {
if (argc < 2) {
fprintf(stderr, "Non ci sono abbastanza parametri per lo script\n");
return 1;
}
while (1) {
int wstatus;
if (fork()) {
execvp(argv[1], argv + 1);
} else {
wait(&wstatus);
int status = WEXITSTATUS(wstatus);
printf("return value ***************** %d\n", status);
if (status != 0) {
break;
}
}
}
return 0;
}