mirror of
https://github.com/drasko/codezero.git
synced 2026-04-21 11:19:05 +02:00
Forktest file added.
This commit is contained in:
38
tasks/test0/src/forktest.c
Normal file
38
tasks/test0/src/forktest.c
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Fork test.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <tests.h>
|
||||||
|
|
||||||
|
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)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user