IML TD first commit
[TD_IML.git] / TD1 / exo.c
1 #include <sys/types.h>
2 #include <sys/wait.h>
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 void show_proc_pids() {
9 pid_t current_pid = getpid();
10 pid_t parent_pid = getppid();
11
12 printf("[%d] Mon PID: %d\n", current_pid, current_pid);
13 printf("[%d] PID du parent: %d\n", current_pid, parent_pid);
14 }
15
16 int main() {
17 int status = 0;
18 printf("Courant:\n");
19 show_proc_pids();
20
21 pid_t rtf = fork();
22
23 if (rtf == -1) {
24 printf("Erreur de clonage\n");
25 exit(EXIT_FAILURE);
26 } else if (rtf == 0) {
27 printf("Fils:\n");
28 show_proc_pids();
29 exit(EXIT_FAILURE);
30 } else {
31 printf("Parent:\n");
32 show_proc_pids();
33 pid_t rtw = wait(&status);
34 system("ps aux");
35 }
36
37 return EXIT_SUCCESS;
38 }