#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
int main()
{
int fd = open("data", O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
if(fd < 0)
{
perror("open:");
return -1;
}
int irst = dup2(fd, STDOUT_FILENO);
if(irst < 0)
{
perror("dup2:");
return -1;
}
cout << "pid = " << getpid() << endl;
cout << "dup2 result is " << irst <<endl;
cout << "this is just a dup2 test!" <<endl;
close(fd);
return 0;
}
dup重定向到标准
最新推荐文章于 2024-06-11 00:59:05 发布