just do a test for HTML
2011-05-07 22:43
351 查看
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 }
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 }
相关文章推荐
- Java设计模式-单例 just for test
- Just For Test
- Just for test-1 rpart
- Just For Test!
- Just do nothing, smile in the dream and waiting for the sun raising.
- Just do nothing, smile in the dream and waiting for the sun raising.
- Using SIPp to do performance test for opensips
- just for test
- Just For Test
- just for test
- wustoj-1375:Just a test for your DouBi value(这真的是只有逗逼的人才能做出来【允悲】【允悲】)
- 窥探 kernel,just for fun --- do_fork
- just for test
- Just for test!
- Just for test.
- [33期] Do,Just for my favorite
- just for test~ 嵌个JS看看?~
- just a test for my bolg first file
- How to do code coverage test for windows service
- Just for test