dup()函数的使用

来源:互联网 发布:小说地图生成软件 编辑:程序博客网 时间:2024/06/12 00:10
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#define FNAME "/tmp/out"int main(){    int fd;//    close(1);    fd = open(FNAME,O_WRONLY|O_CREAT|O_TRUNC,0600);    if( fd < 0 )    {        perror("open");        exit(1);    }//    close(1);//    dup(fd);    dup2(fd,1);    close(fd);    puts("hello!\n");    exit(0);}

1 0