当前位置: 技术问答>linux和unix
为什么父进程一直阻塞呢,
来源: 互联网 发布时间:2017-02-26
本文导语: 本帖最后由 sunsweet_DK 于 2012-06-02 11:34:29 编辑 1 #include 2 #include 3 #include 4 int main() 5 { 6 int fd[2]; 7 pid_t pid1,pid2; 8 char *arg_net[] = {"netstat","-lant",NULL}; 9 char *env_net[] = {"PA...
1 #include
2 #include
3 #include
4 int main()
5 {
6 int fd[2];
7 pid_t pid1,pid2;
8 char *arg_net[] = {"netstat","-lant",NULL};
9 char *env_net[] = {"PATH=/bin",NULL};
10 char *arg_grep[] = {"grep","22",NULL};
11 char *env_grep[] = {"PATH=/bin",NULL};
12 if(pipe(fd) != 0)
13 exit(1);
14 if((pid1 = fork()) == 0){
15 printf("pid1 = %dn",getpid());
16 close(1);
17 dup2(fd[1],1);
18 close(fd[0]);
19 close(fd[1]);
20 execve("/bin/netstat",arg_net,env_net);
21 exit(0);
22 }else if(pid1