I called strace
on some program A
which forks two child programs: B
and C
.
In strace
, I have the following syscalls
:
pipe[([3,4]) = 0
pipe([5,6]) = 0
fork(wc) = 7135
fork (gnetcat) = 7136
close(3) = 0
close(5) = 0
close(4) = 0
close(6) = 0
wait4(-1, NULL, 0, NULL) = 7136
wait4(-1, NUKLL, 0, NULL) = 7135
I am trying to rewrite the program A
in C. In that case, I really never really have to know what those file descriptors 3
,4
,5
and 6
stand for, do I? Is there a way to find out what they are? I know 3
is for stderr
.
0 ist STDIN, 1 is STDOUT and 2 is STDERR. All higher numbers are up to the application. In this case I suspect they are used to capture stdout/stderr of the freshly forked programs. This would mean that "wc" probably runs with its stdout connected to fd 3 and stderr to fd 4, so the main application can could the output of wc.