sandbox/ostep/hw5/hw5_1.c

29 lines
332 B
C
Raw Permalink Normal View History

2018-08-30 04:04:35 +00:00
#include <stdio.h>
#include <unistd.h>
int
main(void)
{
int x = 10;
pid_t pid;
pid = fork();
if (pid < 0) {
}
else if (pid > 0) {
for (int i = 0; i < 5; i++) {
printf("child: x=%d\n", x);
x++;
sleep(1);
}
} else {
for (int i = 0; i < 5; i++) {
printf("parent: x=%d\n", x);
x--;
sleep(1);
}
}
}