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

📄 pipe5.c

📁 Example for linux,hope you like it
💻 C
字号:
#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>int main(){    int data_processed;    int file_pipes[2];    const char some_data[] = "123";    pid_t fork_result;    if (pipe(file_pipes) == 0) {        fork_result = fork();        if (fork_result == (pid_t)-1) {            fprintf(stderr, "Fork failure");            exit(EXIT_FAILURE);        }        if (fork_result == (pid_t)0) {            close(0);            dup(file_pipes[0]);            close(file_pipes[0]);            close(file_pipes[1]);            execlp("od", "od", "-c", (char *)0);            exit(EXIT_FAILURE);        }        else {            close(file_pipes[0]);            data_processed = write(file_pipes[1], some_data,                                   strlen(some_data));            close(file_pipes[1]);            printf("%d - wrote %d bytes\n", (int)getpid(), data_processed);        }    }    exit(EXIT_SUCCESS);}

⌨️ 快捷键说明

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