just do a test for HTML

 1/*******************************************************************************
 2  * Author          :Honker.y
 3  * Email           :Honker.ying@gmail.com
 4  * Last modified   :2011-05-05 18:59
 5  * Filename        :read_tset.c
 6  * version         :
 7  * Description     :子进程读取父进程传递的信息
 8  * Revision        :
 9 * Compiler         :gcc (Debian 4.4 .5 - 8)
10  * Install         :
11  * Use             :
12  *******************************************************************************/
13
14 #include    <stdio.h>
15 #include    <stdlib.h>
16 #include    <unistd.h>
17 #include    <sys/types.h>
18 #include    <errno.h>
19 #include    <string.h>
20 int
21 main (int argc, char *argv[])
22 {
23   int pipe_fd[2];
24   pid_t pid;
25   char r_buf[100];
26   char w_buf[4];
27   char *p_wbuf;
28   int r_num;
29
30   memset (r_buf, 0, sizeof (r_buf));
31   memset (w_buf, 0, sizeof (r_buf));
32   p_wbuf = w_buf;
33   if (pipe (pipe_fd) < 0)
34     {
35       printf ("pipe create error/n");
36       return -1;
37     }
38
39   if ((pid = fork ()) == 0)
40     {
41       printf ("/n");
42       close (pipe_fd[1]);
43       sleep (3);        /* 确保父进程关闭写端 */
44       r_num = read (pipe_fd[0], r_buf, 100);
45       printf ("read num is %d   the data read from the pipe is %d/n", r_num,
46           atoi (r_buf));
47
48       close (pipe_fd[0]);
49       exit (0);
50     }
51   else if (pid > 0)
52     {
53       close (pipe_fd[0]);   /* read */
54       strcpy (w_buf, "111");
55       if (write (pipe_fd[1], w_buf, 4) != -1)
56     printf ("parent write over/n");
57       close (pipe_fd[1]);   /* write */
58       printf ("parent close fd[1] over/n");
59       sleep (10);
60     }
61   exit (0);
62 }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值