Refactoring in chapters
This commit is contained in:
29
process_chp3/ex17.c
Normal file
29
process_chp3/ex17.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user