Why isn't my array saving in c?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lovelyasha
    New Member
    • Nov 2008
    • 1

    Why isn't my array saving in c?

    i'm trying to print the children of a process backwards, but once i exit the for loop the children are getting printed as 0

    for(i = 0; i < counter; i++)
    {
    switch(pid = fork())
    {

    case -1:
    perror("Could not fork\n");
    exit(1);


    case 0:
    reverse[arrayCount] = getpid();
    arrayCount++;
    exit(0);

    /*parent*/
    default:
    wait(NULL);
    }
    }

    int count;
    for(count = depth; count >= 0; count--)
    {
    printf("child: %d\n", reverse[count]);
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Every process will have a separate copy of the array and thats why you dont see any PID's getting printed.

    raghu

    Comment

    Working...