Итак, вот моя дилемма: почему, когда я fork();
является дочерним элементом процесса и он завершается, возвращаемое &status
дочернего элемента смещается влево на 8 бит?
Например, скажем, у меня есть exit(4);
в конце разветвленного ребенка, мой статус в wait(&status);
отцовского процесса дает мне 0x400
.
, поэтому вот некоторыекод, который иллюстрирует, что я имею в виду
#include <stdio.h>
main() {
int n, status, cpid;
printf("Parent pid = %d\n", getpid());
n = fork();
if (n != 0) {
// parent code
printf ("I'm the parent with PID %d \t fork returned %d \t my parent is %d\n", getpid(), n, getppid());
status = 0;
sleep(5); // verify status of child
cpid = wait(&status);
// so when i printf the hex value of status it gets shifted
printf("I received from my child %d this information %x\n", cpid, status);
} else {
// child code
printf ("I'm the child with PID %d \t fork returned %d \t my parent is %d\n", getpid(), n, getppid());
sleep(20);
printf("Child complete\n");
status=12345;
// the line that returns the shifted value
exit(4);
}
printf("Parent complete\n");
exit(15);
}