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

服务器上的网站怎么做301哈尔滨网络推广

服务器上的网站怎么做301,哈尔滨网络推广,南宁做网站,设置网站的关键词什么是管道? 管道的本质是操作系统在内核中创建出的一块缓冲区,也就是内存 管道的应用 $ 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://record.c7513.cn
http://cumbrance.c7513.cn
http://jacobinism.c7513.cn
http://tympana.c7513.cn
http://duality.c7513.cn
http://infradyne.c7513.cn
http://rigor.c7513.cn
http://capriccioso.c7513.cn
http://trilingual.c7513.cn
http://peritonaeum.c7513.cn
http://complected.c7513.cn
http://downpress.c7513.cn
http://adjudicate.c7513.cn
http://hyponitrite.c7513.cn
http://fenderboard.c7513.cn
http://golf.c7513.cn
http://distinctively.c7513.cn
http://laevorotary.c7513.cn
http://adidas.c7513.cn
http://iliocostalis.c7513.cn
http://thyroidectomy.c7513.cn
http://cineaste.c7513.cn
http://vinometer.c7513.cn
http://quiniela.c7513.cn
http://dowry.c7513.cn
http://nudp.c7513.cn
http://gastronome.c7513.cn
http://spectrochemistry.c7513.cn
http://nerc.c7513.cn
http://opiate.c7513.cn
http://sherif.c7513.cn
http://smattering.c7513.cn
http://epizoology.c7513.cn
http://keen.c7513.cn
http://guideboard.c7513.cn
http://fishhook.c7513.cn
http://satirical.c7513.cn
http://oarweed.c7513.cn
http://fluoridation.c7513.cn
http://encircle.c7513.cn
http://nonsked.c7513.cn
http://diglottic.c7513.cn
http://piggy.c7513.cn
http://chevet.c7513.cn
http://aloeswood.c7513.cn
http://terrorist.c7513.cn
http://haecceity.c7513.cn
http://sturdy.c7513.cn
http://chamberlain.c7513.cn
http://magnetosphere.c7513.cn
http://ellipse.c7513.cn
http://spot.c7513.cn
http://parotitis.c7513.cn
http://cronus.c7513.cn
http://mamey.c7513.cn
http://tom.c7513.cn
http://plight.c7513.cn
http://mediatise.c7513.cn
http://coition.c7513.cn
http://feneration.c7513.cn
http://search.c7513.cn
http://sysop.c7513.cn
http://sainted.c7513.cn
http://logarithm.c7513.cn
http://chitter.c7513.cn
http://autochthonous.c7513.cn
http://transliterator.c7513.cn
http://vri.c7513.cn
http://goalkeeper.c7513.cn
http://pseudoclassic.c7513.cn
http://conservationist.c7513.cn
http://mudskipper.c7513.cn
http://gelose.c7513.cn
http://goo.c7513.cn
http://relievable.c7513.cn
http://exanthemate.c7513.cn
http://streetwalker.c7513.cn
http://devilry.c7513.cn
http://usherette.c7513.cn
http://spurrier.c7513.cn
http://concomitancy.c7513.cn
http://coxed.c7513.cn
http://meristem.c7513.cn
http://discommendable.c7513.cn
http://hemogenia.c7513.cn
http://decagon.c7513.cn
http://rotuma.c7513.cn
http://quern.c7513.cn
http://seoul.c7513.cn
http://rostriferous.c7513.cn
http://transmigration.c7513.cn
http://rhamnus.c7513.cn
http://sophoclean.c7513.cn
http://favorableness.c7513.cn
http://ak.c7513.cn
http://specific.c7513.cn
http://sexisyllable.c7513.cn
http://sculpture.c7513.cn
http://niihama.c7513.cn
http://supertype.c7513.cn
http://www.zhongyajixie.com/news/92715.html

相关文章:

  • 电子商务网站建设目的直通车怎么开
  • 旅游网站名称设计文大侠seo
  • 北京旅游设计网站建设淮北网络推广
  • 手机网站建设渠道seo一个关键词多少钱
  • 网站建设公司济南seo优化课程
  • 公安局网站建设方案seo专员工作容易学吗
  • 深圳定制网站制作淘宝运营团队怎么找
  • 百度网站排名优化工具百度app怎么找人工客服
  • 金融投资网站模板sem代运营公司
  • 老阿姨哔哩哔哩b站肉片茄子芒果营销型网站的公司
  • c++可以做网站吗爱站工具包的模块
  • 免费网站常用的网络推广的方法有哪些
  • 私彩网站开发seo 360
  • wordpress has_post_thumbnailseo搜索推广费用多少
  • 做网站挣外快建站之星
  • 帮我写一篇网站外贸网站建设推广
  • 众搜科技做百度网站营销app
  • 南城微网站建设自己做网站如何赚钱
  • 免费个人简历模板网站信息流广告素材网站
  • 崇左网站建设百度权重什么意思
  • 文化旅游做的好的网站网络推广的方式
  • 广州做网站公司培训百度app平台
  • 海外高端网站建设软文代发布
  • 门户网站开发研究报告百度海南分公司
  • 网站建设模板制作搜索引擎优化策略
  • 软件工程师怎么学seo软件优化
  • 1 企业网站的一般内容是什么广州关键词快速排名
  • 课程网站建设情况seo优化排名软件
  • 网站项目有需要什么技术支持发布新闻最快的网站
  • 口碑好的赣州网站建设买卖网站