文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>dup and dup2

dup and dup2

时间:2006-03-18  来源:deb

dup, dup2 - duplicate a file descriptor

#include <unistd.h>
int dup(int oldfd);
int dup2(int oldfd, int newfd);

dup and dup2 create a copy of the file descriptor oldfd.

After successful return of dup or dup2, the old and new descriptors may be used interchangeably.

dup uses the lowest-numbered unused descriptor for the new descriptor.

dup2 makes newfd be the copy of oldfd, closing newfd first if necessary.

EXAMPLES
Redirecting Standard Output to a File
The following example closes standard output for the current processes, reassigns standard output to go to the file referenced by pfd, and closes the o riginal file descriptor to clean up.
#include <unistd.h>
...
int pfd;
...
close(1);
dup(pfd);
close(pfd);
...

Redirecting Error Messages
The following example redirects messages from stderr to stdout.
#include <unistd.h>
...
dup2(1, 2);
...
相关阅读 更多 +
排行榜 更多 +
我的酒厂

我的酒厂

音乐节奏 下载
飓风大作战

飓风大作战

休闲益智 下载
逸拍卖

逸拍卖

购物比价 下载