⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dup.c

📁 Linux0.01内核分析与操作系统设计 随书源代码
💻 C
字号:
/* dup.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

void DisplayOutput()
{
    fprintf(stdout, "This is to stdout\n");
    fprintf(stderr, "This is to stderr\n");
}
int main(int argc, char **argv)
{
    int _newStdOut, _newStdErr;

    //call the output routine
    DisplayOutput();
    //change the stdout and stderr file descriptors
    _newStdOut = open("out", O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
    _newStdErr = open("err", O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
    dup2(_newStdOut, 1);
    dup2(_newStdErr, 2);
    //call the output routine again
    DisplayOutput();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -