1_topology_3.c 1.3 KB
Newer Older
H
uint3  
hypox64 已提交
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 47 48 49 50 51 52 53 54 55
#include <stdio.h>
#include <unistd.h>
/*
  |   |   `-1_topology_3
  |   |       |-1_topology_3
  |   |       |   |-1_topology_3
  |   |       |   |   |-1_topology_3
  |   |       |   |   `-1_topology_3
  |   |       |   `-1_topology_3
  |   |       |       |-1_topology_3
  |   |       |       `-1_topology_3
  |   |       `-1_topology_3
  |   |           |-1_topology_3
  |   |           |   |-1_topology_3
  |   |           |   `-1_topology_3
  |   |           `-1_topology_3
  |   |               |-1_topology_3
  |   |               `-1_topology_3
  |   |   |-grep --color=auto 1_topology_3

*/
void btree_fork(num)
{
    num--;
    if (num != -1)
    {
        int j = 0;
        for (j = 0; j < 2; ++j)
        {
            int pid = fork();
            if(pid == -1) 
            {
                printf("error!\n");
            } 
            else if(pid ==0) 
            {
                printf("This is the child process %d_%d\n",j);
                btree_fork(num);
                getchar();
            } 
        }

    }
}

int main(int argc, char ** argv )
{   
    int i = 0;
    btree_fork(3);
    {
        printf("This is the parent process!\n");
        getchar();
        wait(NULL);
    }
    return 0;
H
hypo 已提交
56
}