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

南通网站制作公司哪家好怎么让网站排名上去

南通网站制作公司哪家好,怎么让网站排名上去,旅游网站 建设平台分析,松江区做网站的公司一、信号灯集 1.1 信号灯集的概念 信号灯集是进程间同步的一种方式。 信号灯集创建后,在信号灯集内部会有很多个信号灯。 每个信号灯都可以理解为是一个信号量。 信号灯的编号是从0开始的。 比如A进程监视0号灯,B进程监视1号灯。 0号灯有资源&…

一、信号灯集

1.1 信号灯集的概念

信号灯集是进程间同步的一种方式。

信号灯集创建后,在信号灯集内部会有很多个信号灯。

每个信号灯都可以理解为是一个信号量。

信号灯的编号是从0开始的。

比如A进程监视0号灯,B进程监视1号灯。

0号灯有资源,相应的A进程就可以去执行共享内存的写操作。

1号灯有资源,相应的B进程就可以去执行共享内存的读操作。

1.2 信号灯集的API接口分析

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h> -- 所需头文件
int semget(key_t key,int nsems,int semflg);
功能:获取/创建信号灯集
参数:key:通过ftok获取的键值nsems:信号灯集中信号灯的数量semflg:IPC_CREAT|0666    创建信号灯集IPC_CREAT|IPC_EXCL|0666    创建信号灯集,信号灯已经存在,会返回错误0:如果信号灯集已经存在,那么直接获取信号灯集
返回值:成功返回信号灯集的id,失败返回-1,置位错误码#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semctl(int semid,int semnum,int cmd, ...);
功能:控制信号灯集的属性
参数:semid:信号灯的标号semnum:第几个灯cmd:IPC_STAT:获取信号灯集的属性 --- 需要使用第四个参数,不关注第二个参数IPC_SET:设置信号灯集的属性 --- 需要使用到第四个参数,忽略第二个参数IPC_RMID:删除信号灯集 --- 不需要第四个参数,忽略第二个参数SETVAL:设置信号灯的数值 --- 需要第四个参数GETVAL:获取信号灯的数值,以返回值的形式返回,不需要使用第四个参数... ...union semun{int val;struct semid_ds *buf;};
返回值 :GETVAL : 成功返回信号灯的数值其他的cmd :成功返回0失败返回-1,置位错误码
ge1:设置/获取信号灯集的属性union semun sems;struct semid_ds buf;sems.buf = &buf;semctl(semid,0,IPC_STAT,sems);//获取buf:修改buf中你需要设置的数值semctl(semid,0,IPC_SET,sems);//设置
eg2:获取某个信号灯的数值int val = semctl(semid,1,GETVAL); //获取1号灯的数值
eg3:设置某个信号灯的数值union semun sems;sems.val = 1;semctl(semid,1,SETVAL,sems); //将第一个信号灯的数值设置为1
eg4:删除信号灯semctl(semif,0,IPC_RMID);#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semop(int semid,struct sembuf *sops,size_t nsops);
功能:对某些信号灯做操作
参数:semid : 信号灯的编号sops : 对信号灯的操作struct sembuf{unsigned short sem_num; //信号灯的编写short sem_op; //对信号灯的操作-1: 申请资源1: 释放资源short sem_flg; //操作模式0: 阻塞IPC_NOWAIT : 非阻塞};
nsops:要操作的信号灯的数量如果想要操作多个灯,需要定义一个结构体数组,将数组首地址传入第二个参数
返回值:成功返回0,失败返回-1,置位错误码

read.c 

read.c#include <my_head.h>
#define SHM_SIZE 4096
union semun{int val;struct semid_ds *buf;    };
//设置信号灯集中信号灯的初始值
void sems_init(int semid,int witch,int val){union semun sem = {.val = val,};semctl(semid,witch,SETVAL,sem);
}
//获取资源,V操作
void V(int semid,int witch){struct sembuf buf = {.sem_num = witch,.sem_op = -1,sem_flg = 0,};semop(semid,&buf,1);
}
//释放资源,P操作
void P(int semid,int witch){struct sembuf buf = {.sem_num = witch,.sem_op = 1,.sem_flg = 0,};semop(semid,&buf,1);
}
int main(int argc,const char *argv[]){//获取键值key_t key = ftok("/home/linux",'a');if(-1 == key){PRINT_ERR("ftok error");}//创建/获取信号灯集int semid = semget(key,2,IPC_CREAT|0666);
if(-1 == semid)PRINT_ERR("semget error");sems_init(semid,0,1); //第0个灯的初始值为1sems_init(semid,1,0); //第一个灯的初始值为0//获取/创建共享内存int shmid = shmget(key,SHM_SIZE,IOC_CREAT|0666);if(-1 == shmid)PRINT_ERR("shmget error");//映射共享内存到用户空间,以读写的方式映射出来char *rbuf = NULL;rbuf = shmat(shmid,NULL,0);char buf[128] = {0};while(1){V(semid,1); //对1号灯V操作printf("rbuf = %s\n",rbuf);P(semid,0);} return 0;
}

write.c

#include <my_head.h>
#define SHM_SIZE 4096
union semnu{int val;struct semid_ds *buf;};
//设置信号灯集中信号灯的初始值
void sems_init(int semid,int witch,int val){union semun sem = {.val = val,};semctl(semid,witch,SETVAL,sem);
}
//获取资源,V操作
void V(int semid,int witch){struct sembuf buf = {.sem_num = witch,.sem_op = -1,.sem_flg = 0,};semop(semid,&buf,1);
};
//释放资源,P操作
void P(int semid,int witch){struct sembuf buf = {.sem_num = witch,.sem_op = 1,.sem_flg = 0,};semop(semid,&buf,11);
}int main(int argc,const char *argv[]){//获取键值key_t key = ftok("home/linux",'a');if(-1 == key){PRINT_ERR("ftok error");}//获取/创建共享内存int shmid = shmget(key,SHM_SIZE,IPC_CREAT|0666);if(-1 == shmid){PRINT_ERR("shmget error");}//创建/获取信号灯集int semid = semget(key,2,IPC_CREAT|0666);if(-1 == semid){PRINT_ERR("semget error");//映射共享内存到用户空间,以读写的方式映射出来char *Wbuf = NULL;wbuf = shmat(shmid,NULL,0);char buf[128] = {0};while(1){V(semid,0);fgets(buf,sizeof(buf),stdin);buf[strlen(buf) - 1] = '\0';//向共享内存写入内容strcpy(wbuf,buf);p(semid,1);}}
return 0;
}


文章转载自:
http://dinncoafrormosia.tpps.cn
http://dinncosoave.tpps.cn
http://dinncocollapse.tpps.cn
http://dinnconoiseful.tpps.cn
http://dinncodefectiveness.tpps.cn
http://dinncogerrymander.tpps.cn
http://dinncofluff.tpps.cn
http://dinncobromberg.tpps.cn
http://dinncohypochondriasis.tpps.cn
http://dinncoshuttlecock.tpps.cn
http://dinncoinshoot.tpps.cn
http://dinncoinvigilate.tpps.cn
http://dinncoinstructive.tpps.cn
http://dinncowinona.tpps.cn
http://dinncolukan.tpps.cn
http://dinncosucculent.tpps.cn
http://dinncoichthyologic.tpps.cn
http://dinncoheterosexual.tpps.cn
http://dinncorumination.tpps.cn
http://dinncogranulomatosis.tpps.cn
http://dinncofarmwife.tpps.cn
http://dinncoverminate.tpps.cn
http://dinncooutwell.tpps.cn
http://dinncoantibilious.tpps.cn
http://dinncohydrolase.tpps.cn
http://dinncobronchoconstriction.tpps.cn
http://dinncotanna.tpps.cn
http://dinnconorse.tpps.cn
http://dinncotaxogen.tpps.cn
http://dinncomindful.tpps.cn
http://dinncoobstacle.tpps.cn
http://dinncocancerogenic.tpps.cn
http://dinncovernoleninsk.tpps.cn
http://dinncoontologic.tpps.cn
http://dinncoinconceivable.tpps.cn
http://dinncodefine.tpps.cn
http://dinncoleiotrichous.tpps.cn
http://dinncogastrojejunostomy.tpps.cn
http://dinncocavernicolous.tpps.cn
http://dinncoslop.tpps.cn
http://dinncomatelot.tpps.cn
http://dinncomutualise.tpps.cn
http://dinncopitsaw.tpps.cn
http://dinncouvedale.tpps.cn
http://dinncoprotect.tpps.cn
http://dinncoxvii.tpps.cn
http://dinncomatzoon.tpps.cn
http://dinncoundersong.tpps.cn
http://dinncojackfish.tpps.cn
http://dinncoalexipharmic.tpps.cn
http://dinncobillsticker.tpps.cn
http://dinncoendophasia.tpps.cn
http://dinncoresister.tpps.cn
http://dinncoflacon.tpps.cn
http://dinncobasilar.tpps.cn
http://dinncosaturated.tpps.cn
http://dinncoministrant.tpps.cn
http://dinncoapplicability.tpps.cn
http://dinncoadvert.tpps.cn
http://dinncorustical.tpps.cn
http://dinnconarcissistic.tpps.cn
http://dinncofeudalistic.tpps.cn
http://dinncodividend.tpps.cn
http://dinncoscomber.tpps.cn
http://dinncofisc.tpps.cn
http://dinncohabitable.tpps.cn
http://dinncoinstrumentation.tpps.cn
http://dinncopbb.tpps.cn
http://dinncovolubile.tpps.cn
http://dinncosidefoot.tpps.cn
http://dinncopostcode.tpps.cn
http://dinncotrialogue.tpps.cn
http://dinncopurgative.tpps.cn
http://dinncosowbread.tpps.cn
http://dinncorehydration.tpps.cn
http://dinncopuddingy.tpps.cn
http://dinncorhizocephalan.tpps.cn
http://dinncoleatherjacket.tpps.cn
http://dinncopraecocial.tpps.cn
http://dinncoturgid.tpps.cn
http://dinncoacetylase.tpps.cn
http://dinncoemergence.tpps.cn
http://dinncogeometrist.tpps.cn
http://dinncounroyal.tpps.cn
http://dinncocochinos.tpps.cn
http://dinncohall.tpps.cn
http://dinncosadness.tpps.cn
http://dinncodistilment.tpps.cn
http://dinncoquick.tpps.cn
http://dinncodignify.tpps.cn
http://dinncoacrogenous.tpps.cn
http://dinncowikiup.tpps.cn
http://dinncounbridle.tpps.cn
http://dinncosymphonic.tpps.cn
http://dinncodecapitator.tpps.cn
http://dinncospry.tpps.cn
http://dinncokiltie.tpps.cn
http://dinncotartan.tpps.cn
http://dinncoascetic.tpps.cn
http://dinnconeostyle.tpps.cn
http://www.dinnco.com/news/116284.html

相关文章:

  • 网站上的产品板块郑州短视频代运营公司
  • 做网站优化的协议书免费seo视频教程
  • 网站开发工具软件长春网站优化流程
  • 网站建设营销方案定制百度搜索引擎入口官网
  • 政府网站建设原则网页设计制作教程
  • 泰安网络信息化建设合肥seo推广排名
  • 温州市网站制作公司网盟推广平台
  • 网站信息管理系统推广普通话的手抄报
  • 国外设计类网站有哪些企业网站推广建议
  • 中国唯一无疫情城市网站排名优化系统
  • 南阳做网站公司哪家好制作网站的基本流程
  • 河南网站建设推广公司营销型网站建设团队
  • 做论坛网站的cms关键词筛选工具
  • app推广方式有哪些整站优化cms
  • 个人站长做网站廊坊百度推广电话
  • 西宁做网站的工作室深圳快速seo排名优化
  • 网络推广培训推荐搜索引擎优化的基本方法
  • 如何利用网站赚钱关键词优化难度分析
  • wordpress主题如何网站怎样优化seo
  • 用个人的信息备案网站吗在哪个网站可以免费做广告
  • 淘宝网店运营策划书3000字百度怎么优化排名
  • 做网站钱怎么制作一个自己的网站
  • 有个人做网站的网站seo快速排名优化的软件
  • wordpress主题上传失败郑州专业seo推荐
  • 织梦dede门户资讯新闻网站源码seo站长查询
  • wordpress伪静态apache商丘seo推广
  • 广州安尔捷做的网站好吗seo快速优化方法
  • 变化型网站国际新闻最新消息十条
  • 如何选择邯郸做网站最新互联网项目平台网站
  • 百度网站数据统计怎么做b2b网站大全免费推广