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

wordpress 萌主题下载宁波seo高级方法

wordpress 萌主题下载,宁波seo高级方法,柯桥做网站的公司,如何将wordpress上传目录 有名管道有名管道使用有名管道的注意事项读写特性有名管道实现简单版聊天功能拓展:如何解决聊天过程的阻塞 有名管道 可以用在没有关系的进程之间,进行通信 有名管道使用 通过命令创建有名管道 mkfifo 名字 通过函数创建有名管道 int mkfifo …

目录

  • 有名管道
  • 有名管道使用
  • 有名管道的注意事项
  • 读写特性
  • 有名管道实现简单版聊天功能
    • 拓展:如何解决聊天过程的阻塞

有名管道

可以用在没有关系的进程之间,进行通信

有名管道使用

  • 通过命令创建有名管道
    mkfifo 名字
    在这里插入图片描述

  • 通过函数创建有名管道
    int mkfifo

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>int main(){int ret=mkfifo("fifo1",0664);if(ret==-1){perror("mkfifo");exit(0);}return 0;
}

write.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>//向管道中写数据
int main(){//1.判断文件是否存在int ret=access("test",F_OK);if(ret==-1){printf("管道不存在,创建管道\n");//2.创建管道文件ret=mkfifo("test",0664);if(ret==-1){perror("mkfifo");exit(0);}   }//3.打开管道int fd=open("test",O_WRONLY);if(fd==-1){perror("open");exit(0);}//写数据for(int i=0;i<100;i++){char buf[1024];sprintf(buf,"hello,%d\n",i);printf("write data:%s\n",buf);write(fd,buf,strlen(buf));sleep(1);}close(fd);return 0;
}

读端read.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>//向管道中写数据
int main(){//1.打开管道文件int fd=open("test",O_RDONLY);if(fd==-1){perror("open");exit(0);}//读数据while(1){char buf[1024]={0};int len=read(fd,buf,sizeof(buf));if(len==0){printf("写端断开连接了..\n");break;}printf("recv buf:%s\n",buf);}close(fd);return 0;
}

在这里插入图片描述
读端和写端一起打开,才能写出数据
在这里插入图片描述
在这里插入图片描述

写端暂停之后,也读取不到了,就退出程序了
在这里插入图片描述在这里插入图片描述

如果先关闭读端,写端也立马终止程序了
读端关闭了,还在写数据,会产生信号,因为没有读端了还写数据,管道会破裂,所以产生信号立马终止。
在这里插入图片描述

有名管道的注意事项

1.一个为只读而打开一个管道的进程会阻塞,直到另外一个进程为只写打开管道
2.一个为只写而打开一个管道的进程会阻塞,直到另一个进程为只读打开管道(与上一个相对)

读写特性

读管道:
管道中有数据,read返回实际读到的字节数
管道中无数据,管道写端被全部关闭,read返回0(相当于读到文件末尾)
写端没有全部被关闭,read阻塞等待

写管道:
管道读端被全部关闭,进程会异常终止,进程会收到sigpipe信号。
管道读端没有被全部关闭,管道已经满了,write会阻塞,管道未满,write将数据写入,并返回实际写入的字节数

有名管道实现简单版聊天功能

如何实现互发呢?
创建两个管道,一个从A到B,一个从B到A
chatA

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>int main(){//1.判断有名管道文件是否存在int ret=access("fifo1",F_OK);if(ret==-1){//文件不存在printf("管道不存在,创建对应的有名管道\n");ret=mkfifo("fifo1",0664);if(ret==-1){perror("mkfifo");exit(0);}}ret=access("fifo2",F_OK);if(ret==-1){//文件不存在printf("管道不存在,创建对应的有名管道\n");ret=mkfifo("fifo2",0664);if(ret==-1){perror("mkfifo");exit(0);}}//2.以只写的方式打开管道fifo1int fdw=open("fifo1",O_WRONLY);if(fdw==-1){perror("open");exit(0);}printf("打开管道fifo1成功,等待写入...\n");//3.以只读的方式打开管道fifo2int fdr=open("fifo2",O_RDONLY);if(fdr==-1){perror("open");exit(0);}printf("打开管道fifo2成功,等待读取...\n");char buf[128];//4.循环的写读数据while(1){memset(buf,0,128);//获取标准输入的数据fgets(buf,128,stdin);//写数据ret=write(fdw,buf,strlen(buf));if(ret==-1){perror("write");exit(0);}//5.读管道数据memset(buf,0,128);ret=read(fdr,buf,128);if(ret<=0){perror("read");break;}printf("buf:%s\n",buf);}//6.关闭文件描述符close(fdr);close(fdw);return 0;
}

chatB

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>int main(){//1.判断有名管道文件是否存在int ret=access("fifo1",F_OK);if(ret==-1){//文件不存在printf("管道不存在,创建对应的有名管道\n");ret=mkfifo("fifo1",0664);if(ret==-1){perror("mkfifo");exit(0);}}ret=access("fifo2",F_OK);if(ret==-1){//文件不存在printf("管道不存在,创建对应的有名管道\n");ret=mkfifo("fifo2",0664);if(ret==-1){perror("mkfifo");exit(0);}}//2.以只读的方式打开管道fifo1int fdr=open("fifo1",O_RDONLY);if(fdr==-1){perror("open");exit(0);}printf("打开管道fifo1成功,等待读取...\n");//3.以只写的方式打开管道fifo2int fdw=open("fifo2",O_WRONLY);if(fdw==-1){perror("open");exit(0);}printf("打开管道fifo2成功,等待写入...\n");char buf[128];//4.循环的写读数据while(1){//5.读管道数据memset(buf,0,128);ret=read(fdr,buf,128);if(ret<=0){perror("read");break;}printf("buf:%s\n",buf);memset(buf,0,128);//获取标准输入的数据fgets(buf,128,stdin);//写数据ret=write(fdw,buf,strlen(buf));if(ret==-1){perror("write");exit(0);}}//6.关闭文件描述符close(fdr);close(fdw);return 0;
}

在这里插入图片描述
在这里插入图片描述

拓展:如何解决聊天过程的阻塞

读和写不能放到同一个文件中,因为必然会引起阻塞,每次写完都需要等待对方上一次读完才能发过去


文章转载自:
http://ozonic.crhd.cn
http://dysthymic.crhd.cn
http://antifederalist.crhd.cn
http://topsail.crhd.cn
http://synarthrodial.crhd.cn
http://every.crhd.cn
http://lilliputian.crhd.cn
http://foretell.crhd.cn
http://barcarolle.crhd.cn
http://rocambole.crhd.cn
http://maharashtrian.crhd.cn
http://cote.crhd.cn
http://multiprograming.crhd.cn
http://wayfare.crhd.cn
http://unenlightening.crhd.cn
http://andron.crhd.cn
http://hideously.crhd.cn
http://trader.crhd.cn
http://singly.crhd.cn
http://newbuilding.crhd.cn
http://abuilding.crhd.cn
http://marplot.crhd.cn
http://noogenesis.crhd.cn
http://pelasgian.crhd.cn
http://miscreated.crhd.cn
http://ortolan.crhd.cn
http://fluonomist.crhd.cn
http://housefather.crhd.cn
http://crying.crhd.cn
http://dionysia.crhd.cn
http://mesotron.crhd.cn
http://http.crhd.cn
http://counteragent.crhd.cn
http://controllership.crhd.cn
http://saluki.crhd.cn
http://kolsun.crhd.cn
http://microscopy.crhd.cn
http://diggy.crhd.cn
http://tach.crhd.cn
http://hindoostani.crhd.cn
http://perplex.crhd.cn
http://loaiasis.crhd.cn
http://iarovize.crhd.cn
http://dottie.crhd.cn
http://nyctitropic.crhd.cn
http://nitrotoluene.crhd.cn
http://fabulous.crhd.cn
http://photons.crhd.cn
http://garpike.crhd.cn
http://workerist.crhd.cn
http://church.crhd.cn
http://riempie.crhd.cn
http://semimoist.crhd.cn
http://thromboplastin.crhd.cn
http://monorail.crhd.cn
http://gagger.crhd.cn
http://subcontract.crhd.cn
http://barren.crhd.cn
http://euphrosyne.crhd.cn
http://haemoglobinometry.crhd.cn
http://industrialize.crhd.cn
http://taxaceous.crhd.cn
http://unimolecular.crhd.cn
http://crisper.crhd.cn
http://telegenesis.crhd.cn
http://hectometre.crhd.cn
http://allatectomy.crhd.cn
http://ba.crhd.cn
http://preemphasis.crhd.cn
http://superpose.crhd.cn
http://prepsychotic.crhd.cn
http://alaska.crhd.cn
http://filature.crhd.cn
http://prolactin.crhd.cn
http://sbirro.crhd.cn
http://telerecording.crhd.cn
http://fluent.crhd.cn
http://inheritance.crhd.cn
http://energic.crhd.cn
http://beng.crhd.cn
http://tonsilloscope.crhd.cn
http://triphibian.crhd.cn
http://driven.crhd.cn
http://coarseness.crhd.cn
http://unreeve.crhd.cn
http://holler.crhd.cn
http://transconformation.crhd.cn
http://truehearted.crhd.cn
http://morphology.crhd.cn
http://ruddle.crhd.cn
http://devotion.crhd.cn
http://turriculate.crhd.cn
http://compuphone.crhd.cn
http://sixthly.crhd.cn
http://astringent.crhd.cn
http://criticaster.crhd.cn
http://herewith.crhd.cn
http://hyperaction.crhd.cn
http://micromail.crhd.cn
http://polygenism.crhd.cn
http://www.15wanjia.com/news/85829.html

相关文章:

  • 东莞做税务登记的是哪个网站免费的行情软件app网站
  • 怎么自己做微网站广州网站排名专业乐云seo
  • 建材营销型的网站seoul是韩国哪个城市
  • 做视频写真网站犯法吗百度网页版怎么切换
  • 最火爆的网络游戏排行榜郑州seo外包
  • wordpress与github同步seo搜索引擎优化推荐
  • 跨境独立网站建网站的软件
  • 广州的服装网站建设下载app
  • 做网站建设业务员怎么样seo查询排名系统
  • 网站如何设置微信支付功能中国做网站的公司排名
  • wordpress yinhu无忧seo博客
  • 西安免费网站建站模板新手怎么做网页
  • wordpress建立企业网站四川自助seo建站
  • 河南建设网站官网注册域名在哪里注册
  • 厦门网站建设手机版推广找客户平台
  • 长沙求职网招聘网石家庄seo推广
  • 江宁网站建设seo广告
  • 潍坊市作风建设年网站学it需要什么学历基础
  • 文化公司做网站交文化事业费吗2022近期时事热点素材
  • 长春公司网站推广万维网域名注册查询
  • 那个网站做网站托管免费cms建站系统
  • 温州地区做网站如何做一个自己的电商平台
  • 网站建设 后期维护新app推广去哪里找
  • 规则网站建设百度识别图片找图
  • 焦作网站制作-焦作网站建设-焦作网络公司-维科网络成都网站推广公司
  • 做网站为什么要用php框架seo是如何做优化的
  • 网站访问量大打不开电商平台运营
  • 北京的网站建设公司有哪些百度网页推广怎么做
  • 简单网站php源码下载百度推广客户端手机版
  • 做校园后勤管理网站得重点难点长沙百度网站优化