question on order of headers and wexitstatus
question on order of headers and wexitstatus
in one of the unix programming faq's they have the following headers in the program to catch sigchld
code:
#include <sys/types.h> /* include this before any other sys headers */
#include <sys/wait.h> /* header for waitpid() and various macros */
#include <signal.h> /* header for signal functions */
#include <stdio.h> /* header for fprintf() */
#include <unistd.h> /* header for fork() */
why does <sys/types.h> have to be placed before any other sys headers in this case?
and the second question. in the following code snippet, when i have status>>8 on a sep. line, i get an exit status of 256 when no one is logged on.
code:
if (status != 0) {
fprintf(stderr, "no one logged on.\n");
wexitstatus(status);
status>>8;
printf("%d\n", status);
exit(exit_failure);
}
however, when i put status>>8 in printf() like in the following
code:
if (status != 0) {
fprintf(stderr, "no one logged on.\n");
wexitstatus(status);
printf("%d\n", status>>8);
exit(exit_failure);
}
i get an exit status of 1 when no one is logged on. i don't understand how the placement of status>>8 has an impact on the exit code.
|