关于fork()
关于管道的例程:
#include <stdio.h>
int main()
{
int childB,childC;
int pipefds[2];
char * args1[]={"/bin/wc",NULL};
char * args2[]={"/usr/bin/ls","-1",NULL};
pipe(pipefds);
if(!(childB=fork()))
{
close(pipefds[1]);
close(0);
dup2(pipefds[0],0);
close(pipefds[0]);
execve("/usb/bin/wc",args1,NULL);
//<--------这里是否要return?
}
close(pipefds[0]);
if(!(childC=fork()))
{
close(1);
dup2(pipefds[1],1);
close(pipefds[1]);
execve("/bin/ls",args2,NULL);
//<--------这里是否要return?
}
close(pipefds[1]);
wait4(childB,NULL,0,NULL);
return 0;
}
以上代码为一个进程创建一个管道供两个新进程使用。但是其出处原来是没有retur语句的。这样的话会不会造成processB又创建了属于processB的子进程processC呢?究竟要不要在这里使用return呢?