+++ /dev/null
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-void show_proc_pids() {
- pid_t current_pid = getpid();
- pid_t parent_pid = getppid();
-
- printf("[%d] Mon PID: %d\n", current_pid, current_pid);
- printf("[%d] PID du parent: %d\n", current_pid, parent_pid);
-}
-
-int main() {
- int status = 0;
- printf("Courant:\n");
- show_proc_pids();
-
- pid_t rtf = fork();
-
- if (rtf == -1) {
- printf("Erreur de clonage\n");
- exit(EXIT_FAILURE);
- } else if (rtf == 0) {
- printf("Fils:\n");
- show_proc_pids();
- exit(EXIT_FAILURE);
- } else {
- printf("Parent:\n");
- show_proc_pids();
- pid_t rtw = wait(&status);
- system("ps aux");
- }
-
- return EXIT_SUCCESS;
-}