1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
/*
* This is test to trace child task after calling fork().
*/
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
static int a(void);
static int b(void);
static int c(void);
static int a(void)
{
return b() - 1;
}
static int b(void)
{
return c() + 1;
}
static int c(void)
{
return getpid() % 100000;
}
int main(int argc, char *argv[])
{
int ret = 0;
if (argc > 1)
ret = atoi(argv[1]);
switch (fork()) {
case -1:
return 1;
default:
wait(NULL);
/* fall through */
case 0:
ret += a();
break;
}
return ret ? 0 : 1;
}
|