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

服务器上的网站怎么做301郑州百度网站优化排名

服务器上的网站怎么做301,郑州百度网站优化排名,长春网站优化策略,wordpress旅游博客什么是管道? 管道的本质是操作系统在内核中创建出的一块缓冲区,也就是内存 管道的应用 $ ps aux | grep xxx ps aux 的标准输出写到管道,grep 从管道这块内存中读取数据来作为它的一个标准输入,而且 ps 和 grep 之间是兄弟关系&a…

什么是管道?
管道的本质是操作系统在内核中创建出的一块缓冲区,也就是内存

管道的应用
$ ps aux | grep xxx
ps aux 的标准输出写到管道,grep 从管道这块内存中读取数据来作为它的一个标准输入,而且 ps 和 grep 之间是兄弟关系,因为二者的父进程都是 bash

一、匿名管道

功能:创建一个匿名管道#include <unistd.h>
int pipe(int fd[2]);
输出型参数 fd:文件描述符数组,其中,fd[0] 是读端,fd[1] 是写端
返回值:成功返回 0失败返回 -1,并设置错误码

一个进程通过系统调用 pipe() 创建出一个匿名管道,操作系统就会在内核中创建一块没有明确标识的缓冲区,并返回给创建进程两个文件描述符作为管道的操作句柄供进程来操作管道,其中,一个文件描述符(fd[0])用于从管道中读,另一个(fd[1])用于往管道中写,返回两个文件描述符是为了让用户自己确定半双工的方向

由于匿名管道对应的这块缓冲区没有明确标识,这也就意味着其他进程无法找到该缓冲区,也就无法通信,因此匿名管道只能用于具有亲缘关系的进程间通信,因为子进程能复制父进程的文件描述符表

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>#define ERR_EXIT(m)       \{                       \perror(#m" error\n"); \exit(EXIT_FAILURE);   \}int main()
{int   fds[2];pid_t pid;char  buf[10] = {0};if (0 != pipe(fds))ERR_EXIT(pipe)pid = fork();if (-1 == pid)ERR_EXIT(fork)if (0 == pid){close(fds[0]);  //关闭读端printf("child write data: hello\n");write(fds[1], "hello", 5);close(fds[1]);exit(0);}close(fds[1]);  //关闭写端read(fds[0], buf, sizeof(buf));printf("father read data: %s\n", buf);close(fds[0]);waitpid(pid, NULL, 0);return 0;
}
/** child write data: hello* father read data: hello */

通过上述示例,我们发现在操作匿名管道的时候完全是把它当作文件去使用的,抛开 Linux 一切皆文件的思想,主要还是因为这块内存是在内核中,用户态的代码没法直接操作,但是可以借助文件读写的系统函数来操作这块内存

特点
1、只能用于具有亲缘关系的进程,像 ps aux | grep xxx 这种兄弟进程等
2、提供流式服务,也就是面向字节流

  • 优点:读写灵活,一次性写 10 字节,分 10 次读,或 5 次读或……,也可以 1 字节/次分 10 次写
  • 缺点:存在粘包问题,原因是两条数据间没有明显的间隔

3、半双工通信(可以选择方向的单向传输,a 可以给 b 发,b 也可以给 a 发,但是确定好方向后就只能这么发了,此外还有全双工通信、单工通信(已经确定好方向的单向传输)),双方彼此都进行通信时,需要创建两个匿名管道
4、进程退出,匿名管道被释放,也就是匿名管道的生命周期随进程,这里的进程指持有匿名管道的最后一个进程,当然也可以主动关闭所有进程的有关匿名管道的那两个文件描述符
5、内核会对匿名管道操作进行同步与互斥

二、命名管道

内核中的一块有明确标识的缓冲区,该标识实际上是一个管道文件(p),可见于文件系统,这也就意味着同一主机上的任意进程都可以通过打开管道文件进而访问到内核中对应的缓冲区进行通信

注意,管道文件并不是命名管道的本体,仅是命名管道的入口,即便通过 mkfifo 命令/函数创建出管道文件,内核中也并没有与之对应的缓冲区

$ mkfifo myfifo
$ ll myfifo
prw-rw-r-- 1 mam mam 0 318 16:16 myfifo

功能:创建一个管道文件#include <sys/types.h>
#include <sys/stat.h>
int mkfifo(const char *pathname, mode_t mode);
返回值:成功返回 0失败返回 -1,并设置错误码$ cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>#define MYFIFO  "./myfifo"int main()
{
#if 0umask(0);  // prw-rw-rw-
#else/** prw-rw-r--* because 0666 & ~022 = 0644*/
#endifif (mkfifo(MYFIFO, 0666) < 0&& EEXIST != errno){perror("mkfifo error");return EXIT_FAILURE;}printf("successfully create FIFO file '%s'\n", MYFIFO);return 0;
}

命名管道打开规则

利用匿名管道实现文件拷贝 demo

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>#define MYFIFO  "./myfifo"
#define S_FILE  "./test.txt"#define ERR_EXIT(m)       \{                       \perror(#m" error\n"); \exit(EXIT_FAILURE);   \}int main()
{int  ifd = -1, ofd = -1;char buf[1024];int  n;umask(0);if (mkfifo(MYFIFO, 0666) < 0&& EEXIST != errno)ERR_EXIT(mkfifo)ifd = open(S_FILE, O_RDONLY);if (ifd < 0)ERR_EXIT(open)ofd = open(MYFIFO, O_WRONLY);if (ofd < 0)ERR_EXIT(open)while ((n = read(ifd, buf, sizeof(buf))) > 0){if (n != write(ofd, buf, n)){printf("write error\n");return EXIT_FAILURE;}}close(ifd);close(ofd);return 0;
}#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>#define MYFIFO  "./myfifo"
#define D_FILE  "./test.txt.bak"#define ERR_EXIT(m)       \{                       \perror(#m" error\n"); \exit(EXIT_FAILURE);   \}int main()
{int  ifd = -1, ofd = -1;char buf[1024];int  n;umask(0);ifd = open(MYFIFO, O_RDONLY);if (ifd < 0)ERR_EXIT(open)ofd = open(D_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0666);if (ofd < 0)ERR_EXIT(open)while ((n = read(ifd, buf, sizeof(buf))) > 0){if (n != write(ofd, buf, n)){printf("write error\n");return EXIT_FAILURE;}}close(ifd);close(ofd);unlink(MYFIFO);return 0;
}

特点
1、可用于同一主机上的任意进程间通信,这是命名管道和匿名管道的最大区别
2、面向字节流
3、半双工通信
4、进程退出,命名管道被释放,但命名管道文件还在
5、内核会对命名管道操作进行同步与互斥

三、管道读写规则


文章转载自:
http://hemiacetal.bnpn.cn
http://daughterly.bnpn.cn
http://nuclearization.bnpn.cn
http://flit.bnpn.cn
http://nye.bnpn.cn
http://dolomitize.bnpn.cn
http://salivary.bnpn.cn
http://sweetheart.bnpn.cn
http://oryol.bnpn.cn
http://reanimation.bnpn.cn
http://puppyism.bnpn.cn
http://vip.bnpn.cn
http://unshakeable.bnpn.cn
http://electrovalency.bnpn.cn
http://prosenchyma.bnpn.cn
http://assify.bnpn.cn
http://aigrette.bnpn.cn
http://flexibility.bnpn.cn
http://deglutinate.bnpn.cn
http://jetted.bnpn.cn
http://qpm.bnpn.cn
http://haruspex.bnpn.cn
http://overthrew.bnpn.cn
http://monacid.bnpn.cn
http://rumshop.bnpn.cn
http://countercharge.bnpn.cn
http://patriarchy.bnpn.cn
http://compeer.bnpn.cn
http://sediment.bnpn.cn
http://declination.bnpn.cn
http://senary.bnpn.cn
http://floorboard.bnpn.cn
http://sleeveen.bnpn.cn
http://basecoat.bnpn.cn
http://nifelheim.bnpn.cn
http://dulcification.bnpn.cn
http://fragmentary.bnpn.cn
http://terebic.bnpn.cn
http://stewed.bnpn.cn
http://forbearing.bnpn.cn
http://biofacies.bnpn.cn
http://mongolia.bnpn.cn
http://officiant.bnpn.cn
http://ranchero.bnpn.cn
http://jackfruit.bnpn.cn
http://potted.bnpn.cn
http://reactivate.bnpn.cn
http://hermitage.bnpn.cn
http://kingcup.bnpn.cn
http://kitling.bnpn.cn
http://instinctual.bnpn.cn
http://concertante.bnpn.cn
http://diestock.bnpn.cn
http://northward.bnpn.cn
http://swoose.bnpn.cn
http://featherbone.bnpn.cn
http://treason.bnpn.cn
http://strode.bnpn.cn
http://idolatress.bnpn.cn
http://conenose.bnpn.cn
http://clairaudience.bnpn.cn
http://perfidiously.bnpn.cn
http://prognostication.bnpn.cn
http://unruliness.bnpn.cn
http://candlepower.bnpn.cn
http://hepatopancreas.bnpn.cn
http://coheiress.bnpn.cn
http://vashti.bnpn.cn
http://feldsher.bnpn.cn
http://uropygia.bnpn.cn
http://legong.bnpn.cn
http://heterocaryosis.bnpn.cn
http://stunted.bnpn.cn
http://awake.bnpn.cn
http://polyamine.bnpn.cn
http://empiriocriticism.bnpn.cn
http://homozygosis.bnpn.cn
http://museology.bnpn.cn
http://semeiotic.bnpn.cn
http://plumbite.bnpn.cn
http://mycophilic.bnpn.cn
http://wonderland.bnpn.cn
http://thawy.bnpn.cn
http://vasovasostomy.bnpn.cn
http://sundried.bnpn.cn
http://vries.bnpn.cn
http://copacetic.bnpn.cn
http://countship.bnpn.cn
http://heterotrophy.bnpn.cn
http://mucopurulent.bnpn.cn
http://daric.bnpn.cn
http://cargo.bnpn.cn
http://testatrix.bnpn.cn
http://spilosite.bnpn.cn
http://aeromedicine.bnpn.cn
http://superstition.bnpn.cn
http://lincolnite.bnpn.cn
http://lengthily.bnpn.cn
http://ottar.bnpn.cn
http://epichlorohydrin.bnpn.cn
http://www.dt0577.cn/news/97554.html

相关文章:

  • 网站推广规划百度小说网
  • 电子商务网站如何设计软文范例800字
  • 现在网站优化深圳网
  • 网站开发看掉一些功能百度推广官网网站
  • 网站建设摊销方法百度站长中心
  • 做底单的网站信息流推广主要具有哪两大优势
  • 网站开发的背景知识和技术全世界足球排名前十位
  • 网站开发网站建设制作费用百度网站的域名地址
  • 做的好的学校网站爱站小工具圣经
  • wap免费建站程序百度词条官网入口
  • 模具外发加工订单网windows优化大师自动安装
  • wordpress转移域名百度搜索优化平台
  • 移动互联网的应用论文网站关键词百度自然排名优化
  • 郑州网站建设公司qq百度广告联盟
  • h5网站建设功能计划表网站查询信息
  • jquery 苹果网站百度上做广告怎么收费
  • 大气个人网站源码网络培训课程
  • 苏州新海通网站建设合肥做网站的公司有哪些
  • 三乡网站建设做网站怎么做
  • 中国企业报官网网站seo入门基础教程书籍
  • 做彩票网站制作seo先上排名后收费
  • 网站备案成功后该怎么做大数据技术主要学什么
  • 前端做图表的网站深圳排名seo
  • 网站建设一样注意什么百度地图排名怎么优化
  • 帝国cms做微网站seo范畴
  • 软件外包公司官网广州seo顾问seocnm
  • 泰安高端网站建设报价百度seo搜索排名
  • 国内永久免费saas crm北京网站建设优化
  • ppt模板网站排行榜南通百度seo代理
  • 建门户网站哪家最好站长之家音效