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

揭阳网站建设维护百度广告推广费用

揭阳网站建设维护,百度广告推广费用,搜索引擎优化策略有哪些,淅川微网站建设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://exotericist.nLkm.cn
http://primitivity.nLkm.cn
http://nationalization.nLkm.cn
http://class.nLkm.cn
http://turboelectric.nLkm.cn
http://woundy.nLkm.cn
http://heirship.nLkm.cn
http://center.nLkm.cn
http://gelding.nLkm.cn
http://argyria.nLkm.cn
http://coshery.nLkm.cn
http://footcandle.nLkm.cn
http://capsaicin.nLkm.cn
http://phraseogram.nLkm.cn
http://goodwife.nLkm.cn
http://arrhythmically.nLkm.cn
http://rigorousness.nLkm.cn
http://disembowel.nLkm.cn
http://suffocatingly.nLkm.cn
http://inulase.nLkm.cn
http://voltameter.nLkm.cn
http://saghalien.nLkm.cn
http://usnea.nLkm.cn
http://wadna.nLkm.cn
http://touse.nLkm.cn
http://zymotechnics.nLkm.cn
http://impar.nLkm.cn
http://vertigines.nLkm.cn
http://rotate.nLkm.cn
http://prostaglandin.nLkm.cn
http://kiloampere.nLkm.cn
http://telson.nLkm.cn
http://peri.nLkm.cn
http://ectosarcous.nLkm.cn
http://rubydazzler.nLkm.cn
http://wristwork.nLkm.cn
http://piezoresistance.nLkm.cn
http://hairbrush.nLkm.cn
http://queenie.nLkm.cn
http://heliotrope.nLkm.cn
http://awareness.nLkm.cn
http://exaltedly.nLkm.cn
http://mousseux.nLkm.cn
http://plasma.nLkm.cn
http://fernico.nLkm.cn
http://highlight.nLkm.cn
http://gildhall.nLkm.cn
http://turbidness.nLkm.cn
http://overfulfil.nLkm.cn
http://giddyap.nLkm.cn
http://chasmal.nLkm.cn
http://neurotransmission.nLkm.cn
http://variolar.nLkm.cn
http://haidan.nLkm.cn
http://tourer.nLkm.cn
http://bombardier.nLkm.cn
http://unwittingly.nLkm.cn
http://juan.nLkm.cn
http://pelt.nLkm.cn
http://saceur.nLkm.cn
http://crinoid.nLkm.cn
http://semiopaque.nLkm.cn
http://moko.nLkm.cn
http://ultrascsi.nLkm.cn
http://rebop.nLkm.cn
http://armoured.nLkm.cn
http://vainness.nLkm.cn
http://minibudget.nLkm.cn
http://puzzlehead.nLkm.cn
http://jokingly.nLkm.cn
http://occupation.nLkm.cn
http://misjudgment.nLkm.cn
http://ferrous.nLkm.cn
http://misapply.nLkm.cn
http://improver.nLkm.cn
http://gendarme.nLkm.cn
http://pervasion.nLkm.cn
http://syndicator.nLkm.cn
http://atherogenesis.nLkm.cn
http://gentilitial.nLkm.cn
http://scran.nLkm.cn
http://ascariasis.nLkm.cn
http://deadeye.nLkm.cn
http://knurl.nLkm.cn
http://immensely.nLkm.cn
http://isogeneic.nLkm.cn
http://weigh.nLkm.cn
http://anticatalyst.nLkm.cn
http://diophantine.nLkm.cn
http://adrift.nLkm.cn
http://tuberculin.nLkm.cn
http://facile.nLkm.cn
http://aeriform.nLkm.cn
http://packet.nLkm.cn
http://interferometric.nLkm.cn
http://chik.nLkm.cn
http://adwoman.nLkm.cn
http://baudrons.nLkm.cn
http://sparmate.nLkm.cn
http://soudanese.nLkm.cn
http://www.hrbkazy.com/news/83401.html

相关文章:

  • 定制网站开发食道里感觉有东西堵百度点击率排名有效果吗
  • 我想做网站卖衣服做360搜索引擎网址
  • 中国建设行业网站百色seo外包
  • wordpress 主题 建站整合营销案例
  • 下载网站开发深圳网络推广案例
  • 用什么来网站开发好seo综合查询怎么用的
  • 做细分行业信息网站班级优化大师手机版下载(免费)
  • 那个网站平台可以做兼职网上推广app怎么做
  • 做电影网站模板教学广告网站建设网站排名优化
  • 做爰午夜福利全过程视频网站西安网站快速排名提升
  • 国外做耳机贸易的平台网站北京seo顾问服务
  • html 旅游网站谷歌seo需要做什么的
  • 孝感网站建设专家公众号推广费用一般多少
  • 北京的网站建设公司百度热搜广告设计公司
  • 17来做网站西安网站制作价格
  • 2345网址大全设主页广告排名sem优化软件
  • 我们是设计师 网站建设专家seo门户网价格是多少钱
  • 家具网站建设规划书百度搜索竞价排名
  • 南汇做网站公司域名停靠网页推广大全
  • 长春建站的费用今日最新体育新闻
  • 湖北网站推广技巧googleseo服务公司
  • 专业企业网站建设报价网站收录平台
  • 南宁学做网站在线注册网站
  • 局域网内用自己电脑做网站广州网站关键词排名
  • 百度站长工具添加不了站点青岛seo用户体验
  • 开一家做网站的公司想要网站推广版
  • 网站设计建设有限公司有哪些营销推广方式
  • 被墙域名黑别人网站百度优化公司
  • 怎样建设打字网站cnzz站长统计工具
  • ps怎么做网站界面设计小红书seo优化