M
Mike
Hi everyone
i am currently learning about child processes. can anyone explain this
code:
#define N (10)
int i;
int pidarray[N];
void main(argc, argv)
int argc; char *argv[];
{
printf("Create Children ...\n");
for (i = 0; i < N; i++)
if (!fork()) {
printf("Child %d createdwith pid %d \n", i + 1, getpid());
pidarray = getpid();
_exit(0);
}
sleep(3);
for (i = 1; i < N; i++) {
printf("%d\n", pidarray);
}
}
It prints out the child pid values, but when i try to read the values back
from the array, they are all zero. Why?
i am currently learning about child processes. can anyone explain this
code:
#define N (10)
int i;
int pidarray[N];
void main(argc, argv)
int argc; char *argv[];
{
printf("Create Children ...\n");
for (i = 0; i < N; i++)
if (!fork()) {
printf("Child %d createdwith pid %d \n", i + 1, getpid());
pidarray = getpid();
_exit(0);
}
sleep(3);
for (i = 1; i < N; i++) {
printf("%d\n", pidarray);
}
}
It prints out the child pid values, but when i try to read the values back
from the array, they are all zero. Why?