Hi,
if(dup2(fileno(stdout),fds[1]) == -1) {
IEEE Std 1003.1, 2004 Edition:
RETURN VALUE
Upon successful completion, fileno() shall return the integer value of the file descriptor associated with stream. Otherwise, the value -1 shall be returned and errno set to indicate the error.
ERRORS
The fileno() function may fail if:
[EBADF] The stream argument is not a valid stream.
Das ist bei "stdout" kaum anzunehmen, ist aber technisch durchaus moeglich (ich hab' da schon Dinger gesehn, ich kann Dir sagen! ;-). Man sollte aber den OP zumindest darauf hinweisen finde ich.
waitpid(p,&status,0);
Auch waitpid() gibt etwas zurueck, ist jedoch in diesem Beispiel nicht wirklich relevant. Dem OP sei aber auch hier die relevante Manpage zur Lektuere empfohlen.
if(WEXITSTATUS(status) != EXIT_SUCCESS) {
Davor fehlt etwas. Was? Nun, ein Blick in die Manpage:
WIFEXITED(status)
is non-zero if the child exited normally.
WEXITSTATUS(status)
evaluates to the least significant eight bits of
the return code of the child which terminated,
which may have been set as the argument to a call
to exit() or as the argument for a return statement
in the main program. This macro can only be evalu
ated if WIFEXITED returned non-zero.
Entspricht damit POSIX:
IEEE Std 1003.1, 2004 Edition:
WIFEXITED(stat_val)
Evaluates to a non-zero value if status was returned for a child process that terminated normally.
WEXITSTATUS(stat_val)
If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().
return EXIT_SUCCESS;
Eigentlich gehoeren die beiden Macros EXIT_SUCCESS und EXIT_FAILURE zu exit() und sollten nicht ausserhalb diesen Zusammenhanges benutzt werden.
Aber wie gesagt: "eigentlich", denn es macht ja doch jeder, auch ich.
Entschuldige bitte, das ich mal wieder voellig uebertrieben pingelig bin, mir war einfach danach, denn <http://www.niscc.gov.uk/niscc/docs/br-20051114-01013.html@das hier> trifft fuer meine zwei Netze, die das nutzen aufgrund meiner Paranoia^WPingeligkeit nicht zu ;-)
so short
Christoph Zurnieden