I have a code in C that forks itself sometimes, each fork does something then returns an error code. Currently, each child process returns its ID (0..n).
void other(int numero){
...
exit(numero);
}
int main(...){
for(int i = 0; i < 6; i++){
if(fork() == 0){
other(i);
}
}
int order[6];
for(int i = 0; i < 6; i++){
int code;
waitpid(0, &code, 0);
order[i] = code; // <-- HERE
}
}
Weirdly, this returns a multiple of the real value. By replacing the line I marked with :
order[i] = code >> 8;
I managed to get the expected result of 0..5. However, I really don't understand why this happens. I expect it's because of some kind of type problem, but I don't see it, I'm always using ints.