X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TD1%2Fpart_two%2Fexo.c;h=430e74c089d001f28eb25490c34b7dc2914b776a;hb=c2f07545723c5a934de76453e8a7986ad1726e1c;hp=0194d04e47ec22387c9aaa95ce3c5a13079de811;hpb=bb3dd2915f58fa911e2d5df37bc2d2327c5c8430;p=TD_IML.git diff --git a/TD1/part_two/exo.c b/TD1/part_two/exo.c index 0194d04..430e74c 100644 --- a/TD1/part_two/exo.c +++ b/TD1/part_two/exo.c @@ -33,21 +33,17 @@ int main() { } else if (cpid == 0) { printf("Fils:\n"); show_proc_pids(); - const char* msg = "Coucou papa !"; + const char* str_fmt = "[%d] Coucou papa !\n"; close(pipefd[0]); - write(pipefd[1], msg, strlen(msg)); + write(pipefd[1], str_fmt, strlen(str_fmt)); close(pipefd[1]); exit(EXIT_SUCCESS); } else { printf("Parent:\n"); show_proc_pids(); close(pipefd[1]); - - while (read(pipefd[0], &buf, 1) > 0) { - write(STDOUT_FILENO, &buf, 1); - } - - write(STDOUT_FILENO, "\n", 1); + read(pipefd[0], &buf, 20*sizeof(buf)); + printf(&buf, getpid()); close(pipefd[0]); wait(NULL); exit(EXIT_SUCCESS);