-#include <sys/types.h>
-#include <sys/wait.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
void show_proc_pids() {
pid_t current_pid = getpid();
pid_t parent_pid = getppid();
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* str_fmt = "[%d] Coucou papa !\n";
close(pipefd[0]);
write(pipefd[1], str_fmt, strlen(str_fmt));
close(pipefd[1]);
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);
exit(EXIT_SUCCESS);
}
-
+
/* unreachable code */
return EXIT_SUCCESS;
}