zoukankan      html  css  js  c++  java
  • 0821

    竖直方向分屏

    :vsplit 2.c

    :vs 2.c

    切换窗口

    ctrl ww

    ----------------- 下午

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <unistd.h>
    #define LEN 1024
    #define R 0
    #define W 1

    void trans(char *s)
    {
        char ch;
        while(ch = *s)
            *s++ = toupper(ch);
        *s = 0;
    }
    int main()
    {
        
        int pipe_a2b[2];
        int pipe_b2a[2];
        if(pipe(pipe_a2b) < 0){ // 创建 A 管道
            perror("pipe");
            exit(1);
        }
        if(pipe(pipe_b2a) < 0){
            perror("pipe");
            exit(1);
        }
        
        pid_t proc_a = fork();
        if(proc_a == 0){  // 创建 子进程 A; 先写数据
            close(pipe_a2b[R]);
            close(pipe_b2a[W]);
            char bufa[LEN] = "abc";
            while(1){
                gets(bufa);
                printf("proc_a send %s\n", bufa);
                write(pipe_a2b[W], bufa, LEN);
                read(pipe_b2a[R], bufa, LEN);
                printf("--------------proc_a accept:%s\n",bufa);
            }
            exit(0);
        }
        pid_t proc_b = fork();
        if(proc_b == 0){ // 创建子进程 B; 开始读数据
            close(pipe_a2b[W]);
            close(pipe_b2a[R]);
            char bufb[LEN];
            while(1){
                read(pipe_a2b[R], bufb, LEN);
                printf("--------------proc_b accept:%s\n", bufb);
                trans(bufb);
                printf("proc_b send:%s\n", bufb);
                write(pipe_b2a[W], bufb, LEN);
            }
            exit(0);
        }

        wait();
        wait();
        return 0;
    }

    /*
        1. 创建A进程, 管道x在A端写,y在A端读
            A 接收 提示符的输入,
            写入x;
            读y,并输出到提示符  
        2. 创建B进程, 管道x在A另一端读,y在B另一端写
            B 读x,转换为大写
              写y;
    */

  • 相关阅读:
    oracle转义用单引号
    【转】plsql 永久注册码适用个版本
    winform datagridview某一列设为自动宽度
    Allow windows service to "Interact with desktop"
    Format a Hard Drive in Csharp C#格式化总结
    Lib New
    大嫂的HTML
    ASP.NET 分页控件
    linux搭建常用命令(运行jar,查看进程)
    如何用navicat连接linux服务器上的mysql以及重启服务
  • 原文地址:https://www.cnblogs.com/mathzzz/p/2648967.html
Copyright © 2011-2022 走看看