惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - 秋雨飘飞

Data type mismatch in criteria expression. 条件表达式中数据类型不匹配 PInvoke 知识记录 近两年的BLOG博龄 前天一道我不能回答好的面试题:内存泄露你怎么解决?希望大家不吝赐教 ACCESS模糊查询出现的变态问题,不知道该问题的希望注意,知道内幕的高手还望给小弟一个解释 Thanks logahead - AJAX的BLOG AJAX淋漓尽致的发挥(Google个性化主页 VS. Windows Live.COM)站在互联网浪尖上窃喜 汉诺塔 - 秋雨飘飞 - 博客园 原来BT也要设置端口映射的,今天才发现 恶心的C语言strtok函数 UNIX网络编程第一次作业基本搞定 发布这几天学习Hook搞出来的一个挺好玩的统计鼠标移动距离和键盘敲击次数的小程序 像素真实的物理长度 学习笔记-HOOK钩子(1)l 监视剪贴板 捕获网页为图像 2D绘图控件 趋势程序大赛第八天 趋势程序大赛第 六&&七 天
dup,dup2函数
秋雨飘飞 · 2006-04-04 · via 博客园 - 秋雨飘飞

这两个函数的功能是输出的重定向
      定义这两个函数的头文件是unistd.h,有兴趣的可以自己看看这个头文件包含的内容
      
      要提的是这个头文件同时定义了下面三个常量

      兄弟们学习网络编程用0,1,2这些参数的时候也得知道代表的意思

      要说这两个函数的意思,还是看一段具体的代码

int fd, fd2;  
mode_t fd_mode 
= S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;  
 
void redir_stdout(const char *filename)  
{  
    fd2
=dup(STDOUT_FILENO);  
    fd 
= open(filename, O_WRONLY|O_CREAT, fd_mode);  //打开文件操作
    dup2(fd, STDOUT_FILENO);  //把输出重定向到fd标识的文件
    close(fd);  
}
  


      fd2=dup(STDOUT_FILENO);说明fd2表示了标准输出
      如果我们想把刚刚定向到fd的输出,再定向回标准输出,我们可以用下面的代码实现:

void resume_stdout()  //恢复输出,把标准输出定向到fd2,fd2代表的是标准输出
{  
    dup2(fd2, STDOUT_FILENO);   
    close(fd2);  
}