chap3
This commit is contained in:
25
bac2/os/chap3/ex3.c
Normal file
25
bac2/os/chap3/ex3.c
Normal 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));
|
||||
}
|
Reference in New Issue
Block a user