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

📄 p11-3.c

📁 SUN Solaris8平台下进程间通信
💻 C
字号:
#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include "err_exit.h"int main (void){    pid_t pid;    int n, mypipe[2];    char buffer[BUFSIZ+1];    /* 创建管道 */    if (pipe (mypipe))         err_exit("Pipe failed.\n");    /* 派生子进程 */     pid = fork ();      if (pid < (pid_t) 0)           err_exit ("Fork failed.\n");       /* fork 失败 */    else if (pid == (pid_t) 0) {           /* 这是子进程 */        sprintf(buffer, "%d",mypipe[0]);    /* 转换描述字为字符 */        execl("p11-4", "p11-4", buffer, (char *)0);          exit (EXIT_SUCCESS);    }    else {   /* 这是父进程 */        close(mypipe[0]);        n = write(mypipe[1], "Hello world!\n", strlen("Hello world!\n"));        printf("%d: write %d bytes\n", getpid(),n);        n = write(mypipe[1], "Greeting from father",                                         strlen("Greeting from father"));        printf("%d: write %d bytes\n", getpid(),n);        exit(EXIT_SUCCESS);    }}

⌨️ 快捷键说明

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