标签:
1 int main(void) 2 { 3 char s[] = "abc.txt"; 4 int i = 0; 5 6 close(STDOUT_FILENO);//关闭标准输出文件描述符 7 int fd1 = open("/dev/pts/1", O_WRONLY);//打开设备文件/dev/pts/1,该设备将做为标准输出文件描述符 8 int fd = open(s, O_RDONLY);// 9 if (-1 == fd) 10 { 11 printf("%s\n", strerror(errno));// 12 } 13 else 14 { 15 while(1) 16 { 17 printf("fd1 = %d, fd = %d:%d\n", fd1, fd, i++);//printf语句将会打印到/dev/pts/1上 18 sleep(1);// 19 } 20 close(fd); 21 } 22 return EXIT_SUCCESS; 23 }
标签:
原文地址:http://www.cnblogs.com/shichuan/p/4374179.html