diff --git a/tasks/test0/src/forktest.c b/tasks/test0/src/forktest.c new file mode 100644 index 0000000..c7fe3f8 --- /dev/null +++ b/tasks/test0/src/forktest.c @@ -0,0 +1,38 @@ +/* + * Fork test. + */ + +#include +#include +#include +#include + +int global = 0; + +int forktest(void) +{ + pid_t myid; + + for (int i = 0; i < 4; i++) + fork(); + + myid = getpid(); + if (global != 0) { + printf("-- FAILED --\n"); + goto out; + } + global = myid; + + if (global != myid) { + printf("-- FAILED --\n"); + goto out; + } + + /* Print only when failed, otherwise too many pass messages */ + // printf("PID: %d, my global: %d\n", myid, global); + // printf("-- PASSED --\n"); +out: + while(1) + ; +} +