, , , ( ) stdout, stdout ls, ( ) 4 . .
stdout . , open(), stdout. - ( , ):
int filefd = open("foo.txt", O_WRONLY|O_CREAT, 0666);
if (!fork()) {
close(1);//Close stdout
dup(filefd);
execlp("ls", "ls", NULL);
} else {
close(filefd);
wait(NULL);
}
return 0;
, freopen, .
:
pipe() open() . .
fork() . .
dup2() dup(); , stdin , .
execlp() . .
, wait() (EINTR). , , (errno == EINTR).