10.9 I/O 重定向
linux> ls > foo.txt#include <unistd.h>
int dup2(int oldfd, int newfd);
// 返回:若成功则为非负的描述符,若出错则为 -1。
练习题 10.4
练习题 10.5
最后更新于
linux> ls > foo.txt#include <unistd.h>
int dup2(int oldfd, int newfd);
// 返回:若成功则为非负的描述符,若出错则为 -1。
最后更新于
#include "csapp.h"
int main()
{
int fd1, fd2;
char c;
fd1 = Open("foobar.txt", O_RDONLY, 0);
fd2 = Open("foobar.txt", O_RDONLY, 0);
Read(fd2, &c, 1);
Dup2(fd2, fd1);
Read(fd1, &c, 1);
printf("c = %c\n", c);
exit(0);
}