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

广州响应式网站word 添加 wordpress

广州响应式网站,word 添加 wordpress,网站登录如何做,适合农村的代加工厂#include <unistd.h> int pipe(int pipefd[2]); 功能&#xff1a;创建一个匿名管道&#xff0c;用于进程间通信 参数&#xff1a; -int pipefd[2]:传出参数 pipefd[0]对应的是管道的读端 pipefd[0]对应的是管道的写端 返回值&#xff1a; 成功返回0&#xff0c;失败返回-…

#include <unistd.h>

    int pipe(int pipefd[2]);

    功能:创建一个匿名管道,用于进程间通信

    参数:

        -int pipefd[2]:传出参数

            pipefd[0]对应的是管道的读端

            pipefd[0]对应的是管道的写端

    返回值:

        成功返回0,失败返回-1

管道默认是阻塞的,如果管道中没有数据,read阻塞,如果管道满了,write阻塞

    注意:匿名管道只能用于具有关系的进程之间的通信(父子进程、兄弟进程)

1.子进程写数据,父进程读数据并输出

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据char buf[1024] = {0};int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());} else if(pid == 0){//子进程//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));}return 0;
}

2.子进程持续写数据,父进程持续接收

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据printf("i am parent process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());}} else if(pid == 0){//子进程printf("i am child process, pid: %d\n", getpid());while(1) {//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));sleep(1);}}return 0;
}

3.父子进程都能读和写数据

//子进程发送数据给父进程,父进程读取到数据输出
#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main() {//在fork之前创建管道int pipefd[2];int ret = pipe(pipefd);if(ret == -1) {perror("pipe");exit(0);}//创建子进程pid_t pid = fork();if(pid > 0) {//父进程//从管道读取端读取数据printf("i am parent process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {//在管道中读取数据int len = read(pipefd[0], buf, sizeof(buf));printf("parent recv : %s, pid: %d\n", buf, getpid());//在管道中写入数据char * str = "hello, i am parent";write(pipefd[1], str, strlen(str));sleep(1);}} else if(pid == 0){//子进程printf("i am child process, pid: %d\n", getpid());char buf[1024] = {0};while(1) {//在管道中写入数据char * str = "hello, i am child";write(pipefd[1], str, strlen(str));sleep(1);//在管道中读取数据int len = read(pipefd[0], buf, sizeof(buf));printf("child recv : %s, pid: %d\n", buf, getpid());}}return 0;
}

4.查看管道缓冲大小

 

#include <unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>int main() {int pipefd[2];int ret = pipe(pipefd);//获取管道大小long size = fpathconf(pipefd[0], _PC_PIPE_BUF);printf("pipe size: %ld\n", size);return 0;
}

http://www.yayakq.cn/news/238502/

相关文章:

  • 一个完整的网站推广方案深圳网站设计 公司
  • 外贸网站建站系统渔泡建筑网
  • 上海网站制作软件怀化北京网站建设
  • 为什么做网站要用谷歌浏览器电商网站建设优缺点
  • 可信赖的网站建设公司南昌外包建站
  • 桂林北站离哪个景区近python制作网页教程
  • 网站ui设计是什么红古微信网站建设
  • 网站建设的宗旨wordpress 随机标签
  • 使用c#语言建设网站优点wordpress必须安装php吗
  • 做网站好还是做app好网站图片验证码出不来
  • 用dw6做网站首页腾讯企业邮箱网页版登录入口
  • 网站帮助中心设计网站开发的投标案例
  • 苗木企业网站源码高职两学一做专题网站
  • 网站开发企业培训报名做推广网站的文章术语
  • 云南省城乡建设培训中心网站永州网站建设优化
  • 长沙做网站seo优化外包网站网络推广方式方法
  • 阳原网站建设辽宁建设工程信息网上开标流程
  • 网站建设步骤完整版中装建设集团有限公司董事长是谁
  • 遵义市播州区建设厅网站在线制作网站页面
  • 网站源码生成合肥经开区建设局网站
  • 建站自学网站建设培训会上的讲话
  • 信阳市住房和城乡建设厅网站广州企业网站模板购买
  • 西安道桥建设有限公司网站国外可以做会员网站的网站
  • 网站项目建设与管理论文ios开发用什么软件
  • 太原网站建设司假山网站建设
  • 有广告的网站输入网站域名
  • 适合做网站背景的图片新品牌进入市场的推广方案
  • 优质的网站建设微信开放平台开发者
  • 贵阳网站开发推荐做推广类门户网站怎么样
  • 网站php网站空间郑州区块链数字钱包网站开发周期