This commit is contained in:
Debucquoy
2023-11-08 09:42:46 +01:00
parent dfe4fd3729
commit 58acfde2b4
6 changed files with 148 additions and 3 deletions

25
bac2/os/chap3/ex3.c Normal file
View File

@ -0,0 +1,25 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#define printvi(X) printf("%s = %d\n", #X, X);
int main(void)
{
pid_t f = fork();
if(f == 0){
srand(time(NULL));
int delay = 1 + rand() % 10;
int value = rand() % 256;
printvi(delay);
printvi(value);
sleep(delay);
return value;
}
int child_ret = 0;
wait(&child_ret);
printvi(WEXITSTATUS(child_ret));
}