By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,484 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,484 IT Pros & Developers. It's quick & easy.

Why isn't my array saving in c?

P: 1
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]);
}
Nov 4 '08 #1
Share this Question
Share on Google+
1 Reply


gpraghuram
Expert 100+
P: 1,275
Every process will have a separate copy of the array and thats why you dont see any PID's getting printed.

raghu
Nov 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.