当前位置: 首页 > news >正文

西宁网站设计高端室内设计专业公司排名

西宁网站设计高端,室内设计专业公司排名,建设网站个人简介范文,红河优才网站建设#include <unistd.h> int pipe(int pipefd[2]); 功能&#xff1a;创建一个匿名管道&#xff0c;用于进程间通信 参数&#xff1a; -int pipefd[2]:传出参数 pipefd[0]对应的是管道的读端 pipefd[0]对应的是管道的写端 返回值&#xff1a; 成功返回0&#xff0c;失败返回-…

#include <unistd.h>

    int pipe(int pipefd[2]);

    功能:创建一个匿名管道,用于进程间通信

    参数:

        -int pipefd[2]:传出参数

            pipefd[0]对应的是管道的读端

            pipefd[0]对应的是管道的写端

    返回值:

        成功返回0,失败返回-1

管道默认是阻塞的,如果管道中没有数据,read阻塞,如果管道满了,write阻塞

    注意:匿名管道只能用于具有关系的进程之间的通信(父子进程、兄弟进程)

1.子进程写数据,父进程读数据并输出

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据char buf[1024] = {0};int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());} else if(pid == 0){//子进程//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));}return 0;
}

2.子进程持续写数据,父进程持续接收

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据printf("i am parent process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());}} else if(pid == 0){//子进程printf("i am child process, pid: %d\n", getpid());while(1) {//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));sleep(1);}}return 0;
}

3.父子进程都能读和写数据

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据printf("i am parent process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {//在管道中读取数据int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());//在管道中写入数据char * str = "hello, i am parent";write(pipefd[1], str, strlen(str));sleep(1);}} else if(pid == 0){//子进程printf("i am child process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));sleep(1);//在管道中读取数据int len = read(pipefd[0], buf, sizeof(buf));printf("child recv : %s, pid: %d\n", buf, getpid());}}return 0;
}

4.查看管道缓冲大小

 

#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>int main() {int pipefd[2];int ret = pipe(pipefd);//获取管道大小long size = fpathconf(pipefd[0], _PC_PIPE_BUF);printf("pipe size: %ld\n", size);return 0;
}

http://www.yayakq.cn/news/791041/

相关文章:

  • 重庆北碚网站制作社交网站 模板
  • 广东建设工程造价管理协会网站佛山有哪些公司
  • 手机端网站首页怎么做感觉做的比较好的健身网站
  • 网站服务器管理系统工程建设服务平台
  • c 网站开发实例教程做空比特币的网站
  • 企业网站快照更新曲靖网站建设电话
  • 做买鞋网站的论文设计高端网站建设
  • 全国培训加盟网站建设网架公司有哪些公司
  • 哪个网站做欧洲旅行比较好名聚优品 一家只做正品的网站
  • php网站有哪些什么是网络营销的最大优点
  • 深圳做网站一个月多少钱wordpress 密码在哪文件夹
  • 河北网站开发哪家好网店设计流程图
  • 做一些网站的弹出页面重庆品牌营销型网站建设
  • wordpress博客站模板下载有哪些做平面设计好素材网站有哪些
  • 视频网站制作进行网站建设
  • 网站外部推广买到域名怎么做网站
  • 建站国外平台做推广
  • 大同网站建设熊掌号3d动画制作软件中文版
  • 网站制作论文参考文献苏州建站模板系统
  • 阿里企业网站建设法律咨询免费平台
  • 网站首页布局设计搭建个人视频网站
  • 做网站推广的前期条件如何确认建设银行网站不是假的
  • 学生作业做网站需要phpcms网站建设
  • 清润邯郸网站深圳seo公司排名
  • 重庆网站排名优化公司版式设计1000例
  • 网站建设厘金手指下拉15wordpress 首页只显示标题
  • 网站程序怎么备份wordpress能做成app吗
  • .net网站开发岗位seo快排
  • 网页qq空间登录做优化网站注意什么
  • 大气网站设计用ps做网站还是wd