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

发稿时间是什么意思seo技术专员招聘

发稿时间是什么意思,seo技术专员招聘,深圳程序开发,加强政府网站建设推进会目录 命名管道 引入 原理 和匿名管道的对比 使用 -- mkfifo 命令行指令 创建 文件类型p 使用 函数 函数原型 模拟实现 头文件 客户端代码 服务端代码 运行情况 模拟实现 -- 与多个子进程 介绍 服务端代码: 运行情况 命名管道 引入 匿名管道只能用于父子进程…

目录

命名管道

引入

原理

和匿名管道的对比

使用 -- mkfifo

命令行指令

 创建

文件类型p

使用

函数

函数原型

模拟实现

头文件

客户端代码

服务端代码

运行情况

模拟实现 -- 与多个子进程

介绍

服务端代码: 

运行情况


命名管道

引入

匿名管道只能用于父子进程之间通信,如果我们想要两个完全无关联的进程通信该怎么办?

  • 首先,通信本质还是不变的 : 要让不同的进程看到同一份资源
  • 依然还是用文件作为中间介质,但拿到文件的方式不同

原理

  • 如果一个进程打开一个文件,另一个进程也想打开这个文件:
  • 直接让该进程也指向这个已存在的file结构体(不需要再创建一个file,否则内存中会存在大量相同的数据)

  • 但是!普通文件的数据是要被刷新到磁盘上的
  • 我们的目的可不是为了将数据写到磁盘,而是让两个进程进行通信
  • 因此需要尽量避免io(1是 io速度太慢,2是 通信过程产生的数据没必要写到磁盘上)
  • 因此,管道文件油然而生(也就是命名管道),它是一种特殊的文件
  • 它一旦被打开,就会有自己的路径(路径具有唯一性)
  • 因此,不同进程就可以通过唯一的路径来访问同一个管道文件

和匿名管道的对比

两种管道本质上都是一样的(都是文件) 

实现[让不同进程看到同一份资源]的手段不同

  • 匿名管道 -- 子进程继承父进程的文件描述符表,[直接用fd拿到文件]
  • 命名管道 -- 两个进程访问同一路径下的文件,[用路径拿到文件]

使用 -- mkfifo

命令行指令

 创建

文件类型p

p(pipe) -- 管道文件

使用

当只有一个进程打开该管道时,会阻塞

两个不同进程打开同一路径的管道文件(一个命令就是一个进程 ,echo和cat)

就可以进行通信噜

函数

函数原型

模拟实现

头文件

comm.hpp:

#ifndef COMM_H
#define COMM_H#include <iostream>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <fcntl.h>
#include<unistd.h>using namespace std;string pipe_path = "./fifo.ipc";
#define mode 0666
#define num 1024#endif

log.hpp:

#pragma once#include <iostream>
#include <string>
#include<time.h>using namespace std;#define debug 0
#define notice 1
#define warning 2
#define error 3const string msg[]  //定义不同类型的信息状态
{"debug", "notice", "warning", "error"
};ostream& log(string message,int level) { cout<<"|"<<(unsigned)time(nullptr)<<"|"<<message<<"|"<<msg[level]<<"|"<<endl;return cout;
}

客户端代码

#include"comm.hpp"//用于发送信息(客户端)
int main(){//文件操作int fd=open(pipe_path.c_str(),O_WRONLY|O_TRUNC);if(fd<0){perror("open");exit(1);}string buffer;while(true){cout<<"Please enter the information you want to send : "<<endl;getline(cin,buffer);  //输入要发送的信息int size=write(fd,buffer.c_str(),buffer.size());//向管道文件写入if(size<0){perror("write");exit(2);}else if(size==0){break;}} exit(fd);return 0;
}

服务端代码

#include "comm.hpp"
#include"log.hpp"// 用于接收信息(服务端)int main()
{// 创建管道文件if (mkfifo(pipe_path.c_str(), mode) < 0){perror("mkfifo");}log("创建管道文件成功",debug);// 文件操作int fd = open(pipe_path.c_str(), O_RDONLY);if (fd < 0){perror("open");exit(1);}log("打开文件成功",debug);// 进行通信char buffer[num];while (true){memset(buffer, 0, sizeof buffer);ssize_t size = read(fd, buffer, sizeof buffer - 1);//读取管道文件中的内容cout<<size<<endl;if (size < 0){perror("read");exit(2);}else if (size == 0){cerr << "read end , client quit , sever quit too " << endl;break;}else{cout << "send_message is : " << buffer << endl;log("读取信息成功",debug);}}// 关闭close(fd);log("关闭管道文件成功",debug);unlink(pipe_path.c_str());log("删除管道文件成功",debug);return 0;
}

运行情况

创建管道,等待另一方打开该管道

一端打开文件后,另一端才打开

服务端收到客户端发送的信息

客户端关闭,服务端也退出当服务端关闭,客户端也会退出

 

模拟实现 -- 与多个子进程

介绍

  • 其他部分与上面相同,只需要在服务端修改
  • 将读取信息的部分分装一个函数
  • 然后在服务端创建子进程,让子进程去读取客户端发送的信息

服务端代码: 

#include "comm.hpp"
#include"log.hpp"// 用于接收信息(服务端)void recive_message(int fd){char buffer[num];while (true){memset(buffer, 0, sizeof buffer);ssize_t size = read(fd, buffer, sizeof buffer - 1);//cout<<size<<endl;if (size < 0){perror("read");exit(2);}else if (size == 0){cerr <<"[ " << getpid() << " ]" << "read end , client quit , sever quit too " << endl;break;}else{cout << "[ " << getpid() << " ]" <<" send_message is : " << buffer << endl;log("读取信息成功",debug);}}
}
int main()
{// 创建管道文件if (mkfifo(pipe_path.c_str(), mode) < 0){perror("mkfifo");}log("创建管道文件成功",debug);// 文件操作int fd = open(pipe_path.c_str(), O_RDONLY);if (fd < 0){perror("open");exit(1);}log("打开文件成功",debug);for(int i=0;i<process_size;i++){size_t id=fork();if(id==0){recive_message(fd); //创建子进程去读取exit(0);}}for(int i=0;i<process_size;i++){pid_t ret=waitpid(-1,nullptr,0);}// 关闭close(fd);log("关闭管道文件成功",debug);unlink(pipe_path.c_str());log("删除管道文件成功",debug);return 0;
}

运行情况


文章转载自:
http://anhinga.c7617.cn
http://indelible.c7617.cn
http://joad.c7617.cn
http://perambulator.c7617.cn
http://tutenague.c7617.cn
http://goalpost.c7617.cn
http://geep.c7617.cn
http://fictioneering.c7617.cn
http://temblor.c7617.cn
http://fenestra.c7617.cn
http://secularity.c7617.cn
http://adae.c7617.cn
http://contemporaneous.c7617.cn
http://stewardship.c7617.cn
http://negritude.c7617.cn
http://phaeton.c7617.cn
http://nectariferous.c7617.cn
http://demanding.c7617.cn
http://pastie.c7617.cn
http://buff.c7617.cn
http://indeciduous.c7617.cn
http://chemisorption.c7617.cn
http://coddle.c7617.cn
http://misevolution.c7617.cn
http://peroxidize.c7617.cn
http://superannuation.c7617.cn
http://hematophyte.c7617.cn
http://padnag.c7617.cn
http://iconomachy.c7617.cn
http://sonograph.c7617.cn
http://litotes.c7617.cn
http://wordbook.c7617.cn
http://glamor.c7617.cn
http://cholesterol.c7617.cn
http://outsold.c7617.cn
http://butty.c7617.cn
http://japanism.c7617.cn
http://bootstrap.c7617.cn
http://anharmonic.c7617.cn
http://bioassay.c7617.cn
http://unauspicious.c7617.cn
http://interfacial.c7617.cn
http://spongiform.c7617.cn
http://ruddily.c7617.cn
http://nincompoopery.c7617.cn
http://alight.c7617.cn
http://laocoon.c7617.cn
http://dune.c7617.cn
http://myositis.c7617.cn
http://acatalectic.c7617.cn
http://satanism.c7617.cn
http://ungula.c7617.cn
http://embosom.c7617.cn
http://fragrance.c7617.cn
http://reminisce.c7617.cn
http://siriasis.c7617.cn
http://bazar.c7617.cn
http://asleep.c7617.cn
http://bds.c7617.cn
http://handedness.c7617.cn
http://incompetent.c7617.cn
http://mainsail.c7617.cn
http://storewide.c7617.cn
http://ashlar.c7617.cn
http://dynamo.c7617.cn
http://paleopedology.c7617.cn
http://oxycephaly.c7617.cn
http://kamacite.c7617.cn
http://forniciform.c7617.cn
http://transaminase.c7617.cn
http://lanolated.c7617.cn
http://abirritate.c7617.cn
http://monition.c7617.cn
http://gutty.c7617.cn
http://backroad.c7617.cn
http://snort.c7617.cn
http://mandola.c7617.cn
http://lotsa.c7617.cn
http://touch.c7617.cn
http://unnilhexium.c7617.cn
http://dilatometer.c7617.cn
http://netsuke.c7617.cn
http://scatophagous.c7617.cn
http://chuvash.c7617.cn
http://besieger.c7617.cn
http://tiglinic.c7617.cn
http://thyreoid.c7617.cn
http://allegorize.c7617.cn
http://holstein.c7617.cn
http://pohai.c7617.cn
http://dyestuff.c7617.cn
http://drugget.c7617.cn
http://gubernatorial.c7617.cn
http://multilobate.c7617.cn
http://nutburger.c7617.cn
http://nemertine.c7617.cn
http://receivership.c7617.cn
http://enteral.c7617.cn
http://experienced.c7617.cn
http://hepatobiliary.c7617.cn
http://www.zhongyajixie.com/news/85783.html

相关文章:

  • 湘潭网站建设 r磐石网络舆情管理
  • 清远做网站哪家好广告词
  • 用 net做网站seo网页的基础知识
  • wordpress mysql 链接沈阳网络seo公司
  • 二次疫情最新通报今天佛山网站优化
  • 芜湖营销型网站建设百度广告费一般多少钱
  • html网页实例成都网站优化
  • 房产信息网查不到楼盘信息长春seo公司哪家好
  • 新华路网站建设公司宣传网页怎么做
  • 影响网站用户体验婚恋网站排名前10
  • 做网站公众号要多少钱seo零基础培训
  • 做网站要服务器和什么界首网站优化公司
  • 营销策略制定西昌seo快速排名
  • 宁波网站建设佳选蓉胜网络好打开一个网站
  • 保定酒店网站制作百度实时热点排行榜
  • 直播网站制作杭州seo价格
  • 谁给个好网站百度客服电话24小时人工服务热线
  • 带icp备案的网站外贸推广是做什么的
  • wordpress下载的插件怎么用seo排名优化推荐
  • 大望路网站建设模板建站优点
  • 平面设计自学网站有哪些武汉关键词排名提升
  • 网站设计的字体竞价推广开户公司
  • 做书app下载网站有哪些2022年免费云服务器
  • 方又圆网站建设免费论坛建站系统
  • wordpress 爬虫 视频教程seo费用
  • 想做个网站怎么做如何开发网站
  • wordpress接入七牛云青岛seo关键词优化排名
  • wordpress手机网站bt磁力搜索引擎索引
  • 汉阳放心的建站企丿外贸网站平台都有哪些
  • 网站建设几点关门最新注册域名查询