From c2f07545723c5a934de76453e8a7986ad1726e1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 1 Jun 2017 19:14:48 +0200 Subject: [PATCH] Clearly separate the code between the parent and the child MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD1/part_two/exo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TD1/part_two/exo.c b/TD1/part_two/exo.c index bb6f3a5..430e74c 100644 --- a/TD1/part_two/exo.c +++ b/TD1/part_two/exo.c @@ -25,7 +25,6 @@ int main() { exit(EXIT_FAILURE); }; - const char* str_fmt = "[%d] Coucou papa !\n"; pid_t cpid = fork(); if (cpid == -1) { @@ -34,6 +33,7 @@ int main() { } else if (cpid == 0) { printf("Fils:\n"); show_proc_pids(); + const char* str_fmt = "[%d] Coucou papa !\n"; close(pipefd[0]); write(pipefd[1], str_fmt, strlen(str_fmt)); close(pipefd[1]); @@ -42,7 +42,7 @@ int main() { printf("Parent:\n"); show_proc_pids(); close(pipefd[1]); - read(pipefd[0], &buf, strlen(str_fmt)); + read(pipefd[0], &buf, 20*sizeof(buf)); printf(&buf, getpid()); close(pipefd[0]); wait(NULL); -- 2.34.1