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

社区网站搭建windows优化大师免费版

社区网站搭建,windows优化大师免费版,网站开发项目经理工资,做的网站手机打不开怎么办1.一个父进程生成五个子进程且分别建立与子进程管道 ①用for循环&#xff0c;结束条件为<5 ②father父进程每次都要离开for循环&#xff0c;生成下一个子进程和管道 2.#include <cassert>和#include <assert.h>的区别 assert.h 是 C 标准库的头文件&#xff…

1.一个父进程生成五个子进程且分别建立与子进程管道

①用for循环,结束条件为<5 ②father父进程每次都要离开for循环,生成下一个子进程和管道

2.#include <cassert>和#include <assert.h>的区别

assert.h 是 C 标准库的头文件,cassert 是 C++ 标准库的头文件

3.子进程进行读取

那咱就关闭写端:close(pipefd[1]),保留读端

4.父进程进行写入

那咱就关闭读端:close(pipefd[0]),保留写端

5.让父进程实现:选择让哪个进程执行哪个命令

使用pair<pid_t,int>创建键值对,实现一一对应。

vector<pair<pid_t,int> > slots;创建各个进程与命令的对应表

slots.push_back(pair<pid_t,int>(id,pipefd[1]));将进程与命令建立连接

6.让子进程等待命令

waitCommand(pipefd[0]);//如果对方不发,我们就阻塞

int waitCommand(int waitFd)

{

    uint32_t command = 0;

    ssize_t s=read(waitFd,&command,sizeof(command));

    assert(s == sizeof(uint32_t));

    return command;

}

7.uint32_t对应几个字节

4个

8.typedef function<void()> func,以及它的等价写法

typedef function<void()> func表示定义函数对象,等价写法是using func=function<void()>

代码实现:

Makefile:

ProcessPool:ProcessPool.ccg++ -o $@ $^ -std=c++11 #-DDEBUG
.PHONY:clean
clean:rm -f ProcessPool

Task.hpp

#pragma once#include <iostream>
#include <string>
#include <unistd.h>
#include <functional>
#include <vector>
#include <unordered_map>using namespace std;
typedef function<void()> func;//等价于  using func=function<void()>vector<func> callbacks;
unordered_map<int,string> desc;
void readMySQL()
{cout<<"process["<<getpid()<<"]执行访问数据库的任务" <<endl;
}void execuleUrl()
{cout<<"process["<<getpid()<<"]执行url解析" <<endl;
}void cal()
{cout<<"process["<<getpid()<<"]执行加密任务" <<endl;
}void save()
{cout<<"process["<<getpid()<<"]执行数据持久化任务" <<endl;
}void load()
{desc.insert({callbacks.size(),"readMySQL:读取数据库"});callbacks.push_back(readMySQL);desc.insert({callbacks.size(),"execuleUrl:进行url解析"});callbacks.push_back(execuleUrl);desc.insert({callbacks.size(),"cal:进行加密计算"});callbacks.push_back(cal);desc.insert({callbacks.size(),"save:进行数据的文件保存"});callbacks.push_back(save);}void showHandler()
{for(const auto &iter:desc){cout<<iter.first<<"\t"<<iter.second<<endl;}
}int handlerSize()
{return callbacks.size();
}

processPool.cc

#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <cassert>
#include <vector>
#include "Task.hpp"
#include <cstdlib>
#include <ctime>#define PROCESS_NUM 5using namespace std;int waitCommand(int waitFd,bool &quit)
{uint32_t command = 0;ssize_t s = read(waitFd, &command, sizeof(command));if(s == 0){quit=true;return -1;}assert(s == sizeof(uint32_t));return command;
}void sendAndWakeup(pid_t who, int fd, uint32_t command)
{write(fd,&command,sizeof(command));cout<<"call process"<<who<<"execute"<<desc[command]<<"through"<<fd<<endl;
}int main()
{load();// vector内放置pid:pipefd键值对vector<pair<pid_t, int>> slots;// 先创建多个进程for (int i = 0; i < PROCESS_NUM; i++){// 创建管道int pipefd[2] = {0};int n = pipe(pipefd);assert(n > 0);(void)n;pid_t id = fork();assert(id != -1);// 子进程我们让它进行读取if (id == 0){// 关闭写端close(pipefd[1]);// childwhile (true){// pipefd[0]// 等命令bool quit=false;int command = waitCommand(pipefd[0],quit); // 如果对方不发,我们就阻塞if(quit) break;// 执行对应的命令if (command >= 0 && command < handlerSize()){callbacks[command]();}else{cout << "非法command:" << command << endl;}}exit(1);}// father,进行写入,关闭读端close(pipefd[0]);slots.push_back(pair<pid_t, int>(id, pipefd[1]));}// 父进程派发任务srand(unsigned long)time(nullptr)^getpid()^23323123123L);//让数据更随机while (true){int select;int command;cout << "##############################################" << endl;cout << "#    1.show functions    2.send command      #" << endl;cout << "##############################################" << endl;cout << "Please Select>";cin >> select;if (select == 1)showHandler();else if (select == 2){cout << "Enter Your Command>";// 选择任务cin >> command;// 选择进程int choice = rand() % slots.size();// 把任务给指定的进程sendAndWakeup(slots[choice].first, slots[choice].second, command);}}// 关闭fd,所有的子进程都会退出for(const auto& slot:slots){close(slot.second);}//回收所有的子进程信息for(const auto & slot:slots){waitpid(slot.first,nullptr,0);}}


文章转载自:
http://annabella.sqLh.cn
http://hypnodrama.sqLh.cn
http://escudo.sqLh.cn
http://infiltrative.sqLh.cn
http://wharfie.sqLh.cn
http://anomalistic.sqLh.cn
http://fallage.sqLh.cn
http://carlylese.sqLh.cn
http://romaunt.sqLh.cn
http://spokespeople.sqLh.cn
http://nore.sqLh.cn
http://onset.sqLh.cn
http://inexplainably.sqLh.cn
http://dedal.sqLh.cn
http://polaroid.sqLh.cn
http://irritability.sqLh.cn
http://photoelectrode.sqLh.cn
http://housekept.sqLh.cn
http://natively.sqLh.cn
http://sensibly.sqLh.cn
http://inexcusably.sqLh.cn
http://climbout.sqLh.cn
http://prodigalise.sqLh.cn
http://colleging.sqLh.cn
http://carapace.sqLh.cn
http://calcimine.sqLh.cn
http://primary.sqLh.cn
http://echinodermatous.sqLh.cn
http://vomerine.sqLh.cn
http://tentatively.sqLh.cn
http://sjaelland.sqLh.cn
http://smooch.sqLh.cn
http://covalency.sqLh.cn
http://aoc.sqLh.cn
http://saintlike.sqLh.cn
http://metaraminol.sqLh.cn
http://betrayal.sqLh.cn
http://bidon.sqLh.cn
http://honeycreeper.sqLh.cn
http://bat.sqLh.cn
http://huanaco.sqLh.cn
http://psst.sqLh.cn
http://parade.sqLh.cn
http://headword.sqLh.cn
http://leadenhall.sqLh.cn
http://redistrict.sqLh.cn
http://lumberman.sqLh.cn
http://bush.sqLh.cn
http://hymnal.sqLh.cn
http://galenism.sqLh.cn
http://cooptative.sqLh.cn
http://anthocarpous.sqLh.cn
http://hydroid.sqLh.cn
http://unstable.sqLh.cn
http://gimmie.sqLh.cn
http://antisymmetric.sqLh.cn
http://mite.sqLh.cn
http://englobe.sqLh.cn
http://toughly.sqLh.cn
http://moratorium.sqLh.cn
http://metabolize.sqLh.cn
http://androstenedione.sqLh.cn
http://processible.sqLh.cn
http://south.sqLh.cn
http://scornfulness.sqLh.cn
http://unhip.sqLh.cn
http://punji.sqLh.cn
http://agnes.sqLh.cn
http://goatpox.sqLh.cn
http://emmarvel.sqLh.cn
http://kernelly.sqLh.cn
http://springhouse.sqLh.cn
http://trisaccharide.sqLh.cn
http://graphemic.sqLh.cn
http://shalwar.sqLh.cn
http://unfermentable.sqLh.cn
http://grounded.sqLh.cn
http://cracked.sqLh.cn
http://nisei.sqLh.cn
http://abet.sqLh.cn
http://unseriousness.sqLh.cn
http://adah.sqLh.cn
http://wbo.sqLh.cn
http://cornstalk.sqLh.cn
http://pepsinogen.sqLh.cn
http://allusive.sqLh.cn
http://specialism.sqLh.cn
http://endosteal.sqLh.cn
http://acclimation.sqLh.cn
http://toehold.sqLh.cn
http://dereliction.sqLh.cn
http://criminological.sqLh.cn
http://favous.sqLh.cn
http://barricado.sqLh.cn
http://cancerophobia.sqLh.cn
http://consumable.sqLh.cn
http://accruement.sqLh.cn
http://ugali.sqLh.cn
http://nervure.sqLh.cn
http://ondograph.sqLh.cn
http://www.15wanjia.com/news/76729.html

相关文章:

  • 做网站用什么电脑配置班级优化大师使用心得
  • 辽宁网站制作cba最新排名
  • 在线制作app下载网络优化是做啥的
  • 广州 网站建设公司网站关键词优化的步骤和过程
  • 高仿卡西欧手表网站百度网站大全首页
  • 手机网站后台怎么进怎么做外链
  • 个人一般注册什么类型的公司网站优化方案
  • 武汉光谷网站建设促销活动推广方法有哪些
  • 中国做外国网购的网站宁波网络优化seo
  • 抖音是b2b还是b2c模式百度自然排名优化
  • 网站开发和企业级开发有什么区别怎么优化一个网站关键词
  • 网站后台维护免费发布广告信息网
  • 新公司网站设计关键词排名优化价格
  • 建设银行安全网站淘宝关键词搜索量查询工具
  • 时代空间网站厦门seo顾问
  • 网站建设yu公众号推广平台
  • 网站开发 flex软文世界平台
  • 东莞门户网站建设方案潍坊seo计费
  • 做网站原创要多少钱上海百度竞价托管
  • 怎么验证网站备案密码是否正确东莞seo靠谱
  • 做百科发那些网站新闻好东莞网站建设制作
  • 免费b站不收费深圳网络推广建站
  • 网站制作价格表重庆seo网络优化咨询热线
  • 适合ps做图的素材网站有哪些正规seo多少钱
  • 做剧情游戏的网站友情链接例子
  • 做外贸批发有哪些网站免费推广seo
  • 做点效果图赚钱的网站好的营销网站设计公司
  • 浦东企业网站建设推广app平台
  • 上海闵行网站制作公司关键词优化公司排名榜
  • b2c电子商务平台是什么seo的研究对象