AAE-CNAS-Labs/Topic-4-Forking-2/task_3_1.c

36 lines
646 B
C
Raw Permalink Normal View History

2021-03-17 15:58:00 +01:00
//
// Written for Computer Networks and Systems lab classes
// AUTHOR : Sergiusz Warga
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void child_task() {
for (int i = 1; i <= 10; ++i) {
printf("%d\n", i);
fflush(stdout);
if (i < 10) sleep(1);
}
}
int main() {
pid_t pid;
pid = fork();
if (pid == -1) { // If something went wrong.
perror("Fork: ");
exit(EXIT_FAILURE);
}
if (pid == 0) { // If this is a child process.
child_task();
exit(EXIT_SUCCESS);
}
wait();
printf("END OF WORK\n");
return 0;
}