Added task 3.1
This commit is contained in:
parent
34e453a786
commit
bc7045ddcc
36
Topic-3/task_3_1.c
Normal file
36
Topic-3/task_3_1.c
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user