zoukankan      html  css  js  c++  java
  • 多进程小例子--fork+pipe

     1 #include<stdio.h>
      2 #include<unistd.h>
      3
      4 #define m 6
      5 int main()
      6 {
      7         int pipefd[2];
      8         int pid;
      9         int m1;
     10
     11         if(pipe(pipefd)<0)
     12         {
     13                 printf("unable to create pipe! ");
     14                 return 1;
     15         }
     16         pid=fork();
     17         if(pid>0)    //parent
     18         {
     19                 m1=m;
     20                 close(pipefd[0]);  //close read end
     21                 write(pipefd[1],&m1,sizeof(int)); //read m1
     22                 wait(NULL);  // wait for child complete
     23                 close(pipefd[1]);
     24         }
     25         else if(pid==0)
     26         {
     27                 close(pipefd[1]);
     28                 read(pipefd[0],&m1,sizeof(int));  //read m1
     29                 while(m1>0)
     30                 {
     31                         printf("hello world! ");
     32                         m1--;
     33                 }
     34                 close(pipefd[0]);
     35         }
     36         else
     37         {
     38                 printf("unable to firk! ");
     39                 return 1;
     40         }
     41         return 0;
     42 }

  • 相关阅读:
    防止软件被暴力破解
    简单分析QQ群验证
    Hash(哈希)算法科普
    C语言自学的方法
    如何防范算法求逆
    .Net程序逆向入门教程
    分享几篇VMP研究和分析的文章
    逆向工程
    PHP之MVC项目实战(三)
    PHP之MVC项目实战(二)
  • 原文地址:https://www.cnblogs.com/zhangyabin---acm/p/3175627.html
Copyright © 2011-2022 走看看