From bc7045ddccf3762d749b97f8d8d41c1a7d76826e Mon Sep 17 00:00:00 2001 From: EdwardEisenhauer Date: Wed, 17 Mar 2021 15:58:00 +0100 Subject: [PATCH] Added task 3.1 --- Topic-3/task_3_1.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Topic-3/task_3_1.c diff --git a/Topic-3/task_3_1.c b/Topic-3/task_3_1.c new file mode 100644 index 0000000..b904b9a --- /dev/null +++ b/Topic-3/task_3_1.c @@ -0,0 +1,36 @@ +// +// Written for Computer Networks and Systems lab classes +// AUTHOR : Sergiusz Warga + +#include +#include +#include +#include + +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; +} \ No newline at end of file