diff --git a/2A/systeme/tp/1_tp/ex1 b/2A/systeme/tp/1_tp/ex1 index aa4e379..92e8fd4 100755 Binary files a/2A/systeme/tp/1_tp/ex1 and b/2A/systeme/tp/1_tp/ex1 differ diff --git a/2A/systeme/tp/1_tp/ex1.c b/2A/systeme/tp/1_tp/ex1.c index f1193f6..8525cf0 100644 --- a/2A/systeme/tp/1_tp/ex1.c +++ b/2A/systeme/tp/1_tp/ex1.c @@ -5,8 +5,9 @@ int main(int argc, char* argv[]) { for(int i = 0; i < argc; ++i) printf("argument %d : %s \n", i, argv[i]); + puts("\n----------------\n"); //mieux qu'un printf car moins gourmand pour char() printf("PATH => %s\n", getenv("PATH")); - + return 0; } diff --git a/2A/systeme/tp/1_tp/ex3.c b/2A/systeme/tp/1_tp/ex3.c index 70aacf6..4d0f8ed 100644 --- a/2A/systeme/tp/1_tp/ex3.c +++ b/2A/systeme/tp/1_tp/ex3.c @@ -13,13 +13,12 @@ int main(int argc, char **argv) { struct timespec t; switch(pid=fork()) { - - case -1 : /* Oups !!! fork n'a pas marché !*/ - perror("fork"); exit(errno); + case -1 : /* Oups !!! fork n'a pas marché !*/ + perror("fork"); exit(errno); case 0 : /* Code du fils */ - printf("[fils]: je suis le fils de pid %d\n", getpid()); - for (i=0; i<10 ; i++) { + printf("[fils]: je suis le fils de pid %d\n", getpid()); + for (i=0; i<10 ; i++) { printf("[fils]: %d\n",i); t.tv_sec=0; t.tv_nsec=500000000; @@ -27,19 +26,18 @@ int main(int argc, char **argv) { } system("ps -f"); exit(2); - break; + break; - default : /* Code du père*/ + default : /* Code du père*/ if ((pid=wait(&etat))==-1) { perror("pb avec le wait"); exit(errno); - } + } if (WIFEXITED(etat)) printf("[pere]: mon fils %d a retourne le code %d\n", pid, WEXITSTATUS(etat)); else printf("[pere]: mon fils %d s est mal termine\n",pid); - - printf("[pere]: Fin du processus pere de pid %d.\n", getpid()); + printf("[pere]: Fin du processus pere de pid %d.\n", getpid()); } diff --git a/2A/systeme/tp/1_tp/exo4.c b/2A/systeme/tp/1_tp/exo4.c index cd88ac2..c00825c 100644 --- a/2A/systeme/tp/1_tp/exo4.c +++ b/2A/systeme/tp/1_tp/exo4.c @@ -9,54 +9,54 @@ /* Correction TP1 exo4 by O Guinaldo */ void codeDuFils(int n) { - int i; - struct timespec t; - - for (i=0 ; i<10 ; i++) { - printf("(numero %d dit :) %d\n", n, i); - t.tv_sec=0; - t.tv_nsec=300000000+n*100000000; - /* il n'affiche pas au meme rythme */ - nanosleep(&t, NULL); + int i; + struct timespec t; + + for (i=0 ; i<10 ; i++) { + printf("(numero %d dit :) %d\n", n, i); + t.tv_sec=0; + t.tv_nsec=300000000+n*100000000; + /* il n'affiche pas au meme rythme */ + nanosleep(&t, NULL); } - exit(n); /*le fils retourne son numero comme code de retour */ + exit(n); /*le fils retourne son numero comme code de retour */ } int main (int argc, char* argv[]){ - int i, etat, N; - pid_t pid; + int i, etat, N; + pid_t pid; - if (argc!=2) { - fputs("Donner un arg entier\n", stderr); - exit(1); + if (argc!=2) { + fputs("Donner un arg entier\n", stderr); + exit(1); } -/* le atoi ne gère pas les erreurs - preferer le sscanf (un scanf dans une chaine) */ - N=atoi(argv[1]); - - /* le pere va creer N fils */ - for (i=0 ; i