Refactoring in chapters

This commit is contained in:
Fabio Scotto di Santolo
2024-09-02 13:43:29 +02:00
parent 1cf2ae29e8
commit 497e87c3a3
23 changed files with 16 additions and 114 deletions

29
process_chp3/ex17.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0, 1, 2, 3, 4};
int main(void) {
int i;
pid_t pid;
pid = fork();
if (pid == 0) {
for (i = 0; i < SIZE; i++) {
nums[i] *= -i;
printf("CHILD : %d\n", nums[i]); // Linea X
}
} else if (pid > 0) {
wait(NULL);
for (i = 0; i < SIZE; i++) {
printf("PARENT: %d\n", nums[i]); // Linea Y
}
}
return EXIT_SUCCESS;
}