exit(EXIT_FAILURE);
};
+ const char* str_fmt = "[%d] Coucou papa !\n";
pid_t cpid = fork();
if (cpid == -1) {
} else if (cpid == 0) {
printf("Fils:\n");
show_proc_pids();
- const char* msg = "Coucou papa !";
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, strlen(str_fmt));
+ printf(&buf, getpid());
close(pipefd[0]);
wait(NULL);
exit(EXIT_SUCCESS);