Hi!
I'm trying to find out what is wrong with the next code which I'm trying to run in Linux:
int e1;
int e2;
pid_t pid1; // pid of child
pid_t pid2;
pid_t w1; // return code of wait()
pid_t w2;
// child process 1
pid1 = fork();
if (pid1 == 0) {
// some code...
exit(e1);
}
// child process 2
pid2 = fork();
if (pid2 == 0) {
// some code
exit(e2);
}
// wait for children to terminate
w1 = waitpid(pid1, &e1, WEXITED);
if (w1 == -1) perror("");
w2 = waitpid(pid2, &e2, WEXITED);
if (w2 == -1) perror("");
The problem here is that even if the program compiles all right and runs all the way to end and does what supposed in the child processes, I get "invalid argument" error message from waitpid's and the flow of program just happily passes those waits. What's that? What I don't do right? I have also tried _exit() but with no different results.
I have printed out pids to see what they are and they seem to be ok.
All help appreciated!