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