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

健康管理公司网站建设优化关键词排名外包

健康管理公司网站建设,优化关键词排名外包,武汉网站推广怎么做,非凡网站开发培训目录 1 -> 命名管道 1.1 -> 创建一个命名管道 1.2 -> 匿名管道与命名管道的区别 1.3 -> 命名管道的打开规则 1.4 -> 例子 1 -> 命名管道 管道应用的一个限制就是只能在具有共同祖先(具有亲缘关系)的进程间通信。如果我们想在不相关的进程之间交换数据&…

目录

1 -> 命名管道

1.1 -> 创建一个命名管道

1.2 -> 匿名管道与命名管道的区别

1.3 -> 命名管道的打开规则

1.4 -> 例子


1 -> 命名管道

  • 管道应用的一个限制就是只能在具有共同祖先(具有亲缘关系)的进程间通信。
  • 如果我们想在不相关的进程之间交换数据,可以使用FIFO文件来做这项工作,它经常被称为命名管道。
  • 命名管道是一种特殊类型的文件。

1.1 -> 创建一个命名管道

命名管道可以从命令行上创建,命令行方法是使用下面这个命令:

$ mkfifo filename

命名管道也可以从程序里创建,相关函数有:

int mkfifo(const char *filename,mode_t mode);

创建命名管道:

int main(int argc, char *argv[])
{
        mkfifo("p2", 0644);
        return 0;
}

1.2 -> 匿名管道与命名管道的区别

  • 匿名管道由pipe函数创建并打开。
  • 命名管道由mkfifo函数创建,打开用open。
  • FIFO(命名管道)与pipe(匿名管道)之间唯一的区别在它们创建与打开的方式不同,一但这些工作完成之后,它们具有相同的语义。

1.3 -> 命名管道的打开规则

  • 如果当前打开操作是为读而打开FIFO时:
    • O_NONBLOCK disable:阻塞直到有相应进程为写而打开该FIFO。
    • O_NONBLOCK enable:立刻返回成功。
  • 如果当前打开操作是为写而打开FIFO时。
    • O_NONBLOCK disable:阻塞直到有相应进程为读而打开该FIFO。
    • O_NONBLOCK enable:立刻返回失败,错误码为ENXIO。

1.4 -> 例子

1. 用命名管道实现文件拷贝:

读取文件,写入命名管道: 

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>#define ERR_EXIT(m) \do \{ \perror(m); \exit(EXIT_FAILURE); \} while(0)int main(int argc, char* argv[]) 
{mkfifo("tp", 0644); int infd; infd = open("abc", O_RDONLY); if (infd == -1)ERR_EXIT("open");int outfd;outfd = open("tp", O_WRONLY);if (outfd == -1) ERR_EXIT("open");char buf[1024];int n;while ((n = read(infd, buf, 1024)) > 0){write(outfd, buf, n);}close(infd);close(outfd);return 0;
}

读取管道,写入目标文件:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>#define ERR_EXIT(m) \do \{ \perror(m); \exit(EXIT_FAILURE); \} while(0)int main(int argc, char* argv[]) 
{int outfd; outfd = open("abc.bak", O_WRONLY | O_CREAT | O_TRUNC, 0644); if (outfd == -1) ERR_EXIT("open");int infd;infd = open("tp", O_RDONLY);if (outfd == -1)ERR_EXIT("open");char buf[1024];int n;while ((n = read(infd, buf, 1024)) > 0){write(outfd, buf, n);}close(infd);close(outfd);unlink("tp");return 0;
}

2. 用命名管道实现server&client通信

# ll
total 12
-rw-r--r--. 1 root root 46 Sep 18 22:37 clientPipe.c
-rw-r--r--. 1 root root 164 Sep 18 22:37 Makefile
-rw-r--r--. 1 root root 46 Sep 18 22:38 serverPipe.c
# cat Makefile
.PHONY:all
all:clientPipe serverPipe
clientPipe:clientPipe.cgcc -o $@ $^
serverPipe:serverPipe.cgcc -o $@ $^
.PHONY:clean
clean:rm -f clientPipe serverPipe

severPipe.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>#define ERR_EXIT(m) \
do{\perror(m);\exit(EXIT_FAILURE);\
}while(0)int main()
{umask(0);if (mkfifo("mypipe", 0644) < 0) {ERR_EXIT("mkfifo");}int rfd = open("mypipe", O_RDONLY);if (rfd < 0) {ERR_EXIT("open");}char buf[1024];while (1) {buf[0] = 0;printf("Please wait...\n");ssize_t s = read(rfd, buf, sizeof(buf) - 1);if (s > 0) {buf[s - 1] = 0;printf("client say# %s\n", buf);}else if (s == 0) {printf("client quit, exit now!\n");exit(EXIT_SUCCESS);}else {ERR_EXIT("read");}}close(rfd);return 0;
}

clientPipe.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>#define ERR_EXIT(m) \
do{\perror(m);\exit(EXIT_FAILURE);\
}while(0)int main()
{int wfd = open("mypipe", O_WRONLY);if (wfd < 0) {ERR_EXIT("open");}char buf[1024];while (1) {buf[0] = 0;printf("Please Enter# ");fflush(stdout);ssize_t s = read(0, buf, sizeof(buf) - 1);if (s > 0) {buf[s] = 0;write(wfd, buf, strlen(buf));}else if (s <= 0) {ERR_EXIT("read");}}close(wfd);return 0;
}

感谢各位大佬支持!!!

互三啦!!!

http://www.shuangfujiaoyu.com/news/23202.html

相关文章:

  • 湖北做网站南宁seo推广外包
  • 无锡营销型网站建设360搜索推广官网
  • 沈阳公司网站制作游戏推广员怎么做
  • 黄页网页的推广网站网站推广优化怎样
  • 伪静态规则变动对网站的影响百度关键词规划师入口
  • 企业名称注册查询官网入口南昌seo计费管理
  • 做论坛网站的应用山西seo优化
  • 响应式网站无法做联盟广告个人网站免费域名和服务器
  • wordpress标题北京谷歌seo公司
  • 专注江苏网站建设企业产品推广运营公司
  • wordpress备份整站windows优化大师下载
  • 杭州建设网站制作网络新闻发布平台
  • 杭州建站公司软件外包公司
  • oa系统办公一键优化软件
  • 网站建设 asp 武汉2345网址导航
  • 如何在网上接做网站的小项目百度关键词竞价价格
  • 国外设计网站app媒体公关公司
  • 政府网站源码破解网络优化需要哪些知识
  • 南京网站定制开发公司如何做seo优化
  • 老网站怎么做循环链接搜索引擎优化是什么意思啊
  • 网站做二级域名seo搜索引擎优化工资
  • 一个博彩网站建设下来要花多少钱网站友情链接
  • wordpress站点目录海外推广营销系统
  • 做义工的网站长春百度seo公司
  • 长宁区网站制作人民网舆情数据中心官网
  • 一个网站做3个关键词够优秀的营销案例
  • 99到家网站怎么做杭州关键词优化测试
  • 网站怎么建设dw百度左侧排名
  • 重庆网站开发哪家专业沈阳关键词优化费用
  • h5动态页面玉溪seo