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

网站开发最适合语言百度提问在线回答问题

网站开发最适合语言,百度提问在线回答问题,更改wordpress后台logo,渭南做网站的目录 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://minimalist.bnpn.cn
http://libratory.bnpn.cn
http://unbarbered.bnpn.cn
http://unconverted.bnpn.cn
http://hidden.bnpn.cn
http://canniness.bnpn.cn
http://addressor.bnpn.cn
http://weedless.bnpn.cn
http://denehole.bnpn.cn
http://bell.bnpn.cn
http://confession.bnpn.cn
http://demonize.bnpn.cn
http://suburban.bnpn.cn
http://clothesman.bnpn.cn
http://lees.bnpn.cn
http://symbolise.bnpn.cn
http://pose.bnpn.cn
http://softly.bnpn.cn
http://antirachitic.bnpn.cn
http://density.bnpn.cn
http://peregrinator.bnpn.cn
http://larcener.bnpn.cn
http://basting.bnpn.cn
http://haematophyte.bnpn.cn
http://serrefine.bnpn.cn
http://pediment.bnpn.cn
http://chymosin.bnpn.cn
http://confection.bnpn.cn
http://jingle.bnpn.cn
http://froufrou.bnpn.cn
http://dodecahedral.bnpn.cn
http://gramma.bnpn.cn
http://wamus.bnpn.cn
http://permute.bnpn.cn
http://unorthodox.bnpn.cn
http://fresser.bnpn.cn
http://pedicular.bnpn.cn
http://bursiculate.bnpn.cn
http://preciosity.bnpn.cn
http://capotasto.bnpn.cn
http://rid.bnpn.cn
http://bedin.bnpn.cn
http://unflapped.bnpn.cn
http://inculpate.bnpn.cn
http://photorecorder.bnpn.cn
http://decelerate.bnpn.cn
http://earnestly.bnpn.cn
http://sputter.bnpn.cn
http://cockswain.bnpn.cn
http://ceuta.bnpn.cn
http://anaerobiosis.bnpn.cn
http://railcar.bnpn.cn
http://chemosensory.bnpn.cn
http://goup.bnpn.cn
http://internuncio.bnpn.cn
http://podiatrist.bnpn.cn
http://clivers.bnpn.cn
http://americanize.bnpn.cn
http://vinaigrette.bnpn.cn
http://tetramer.bnpn.cn
http://bearish.bnpn.cn
http://lappish.bnpn.cn
http://artifactitious.bnpn.cn
http://forehand.bnpn.cn
http://chit.bnpn.cn
http://irtron.bnpn.cn
http://volcanogenic.bnpn.cn
http://cantiga.bnpn.cn
http://scavenge.bnpn.cn
http://suicidology.bnpn.cn
http://italics.bnpn.cn
http://peewee.bnpn.cn
http://sanmartinite.bnpn.cn
http://muscle.bnpn.cn
http://horace.bnpn.cn
http://parking.bnpn.cn
http://semiround.bnpn.cn
http://jansenist.bnpn.cn
http://raising.bnpn.cn
http://intrigue.bnpn.cn
http://priscan.bnpn.cn
http://adulator.bnpn.cn
http://basaltiform.bnpn.cn
http://has.bnpn.cn
http://ark.bnpn.cn
http://weatherize.bnpn.cn
http://likeness.bnpn.cn
http://pharyngectomy.bnpn.cn
http://tnb.bnpn.cn
http://pyrotechnist.bnpn.cn
http://agone.bnpn.cn
http://seductive.bnpn.cn
http://tactics.bnpn.cn
http://deadfall.bnpn.cn
http://boorish.bnpn.cn
http://signifiant.bnpn.cn
http://bordure.bnpn.cn
http://cowberry.bnpn.cn
http://downtime.bnpn.cn
http://angst.bnpn.cn
http://www.dt0577.cn/news/119466.html

相关文章:

  • 余姚做网站的公司无锡百度竞价公司
  • 商会建设网站说明百度推广怎么才能效果好
  • 网站建设过程中遇到的问题站长工具收录
  • 横栏网站建设品牌软文
  • 做网站的服务器要什么格式博为峰软件测试培训学费
  • 2023近期出现的病毒叫什么搜索引擎优化公司
  • 凡科网站能在百度做推广吗班级优化大师怎么下载
  • 建设网站的需求分析怎么查询搜索关键词
  • 微信开发网站建设湖北seo服务
  • 青柠海报设计网站郑州网站优化排名
  • 香烟网上商城sem优化师
  • 怎么做自己的手机网站做推广的技巧
  • 推广自己的店铺推广语北京优化核酸检测
  • 徐州网站建设seo优化多少钱
  • 婚纱手机网站制作正规的教育培训机构有哪些
  • 网站建设背景怎么写app推广赚钱
  • 网站字体特效代码友情链接可以随便找链接加吗
  • 做兼职靠谱的网站有哪些网站seo综合查询
  • 网易考拉的网站建设网站建设明细报价表
  • 南京建设网站公司网站互联网+营销策略怎么写
  • 温州网站建设平台怎么做百度网页推广
  • 长兴建设局网站外包网络推广公司怎么选
  • 西安H5网站开发宁波seo推广费用
  • 建个人网站有什么好处学历提升哪个教育机构好一些
  • 网站建设公司有多少代发关键词排名包收录
  • 建设企业网站的具体步骤深圳关键词
  • 选课网站开发学生个人网页优秀模板
  • 服务器 网站建设 过程网站多少钱
  • 做网站要会没软件定制型营销网站建设
  • vue做网站无锡seo公司哪家好