当前位置: 技术问答>linux和unix
关于linux c调用子进程
来源: 互联网 发布时间:2017-03-27
本文导语: #include #include #include void main() { int n,j=0,q,p; pid_t pid; n = getpid(); printf("i'm father%dn",n); for(j=0;j0) { pid= wait(NULL); // p=getpid(); // printf("i'm father%dn",p); }*/ } } i'm children 7129 i'...
#include
#include
#include
void main()
{
int n,j=0,q,p;
pid_t pid;
n = getpid();
printf("i'm father%dn",n);
for(j=0;j0)
{
pid= wait(NULL);
// p=getpid();
// printf("i'm father%dn",p);
}*/
}
}
i'm children 7129
i'm children 7127
i'm children 7124
i'm children 7126
i'm children 7130
i'm children 7131
i'm children 7134
i'm children 7135
i'm children 7136
i'm children 7133
i'm children 7132
i'm children 7137
为什么注释掉子进程的exit(0)之后会输出这么多行。而且父进程却没有输出,我想,也许是,每个子进程都跑去循环了。。。麻烦各位给点自己的看法
#include
#include
void main()
{
int n,j=0,q,p;
pid_t pid;
n = getpid();
printf("i'm father%dn",n);
for(j=0;j0)
{
pid= wait(NULL);
// p=getpid();
// printf("i'm father%dn",p);
}*/
}
}
i'm children 7129
i'm children 7127
i'm children 7124
i'm children 7126
i'm children 7130
i'm children 7131
i'm children 7134
i'm children 7135
i'm children 7136
i'm children 7133
i'm children 7132
i'm children 7137
为什么注释掉子进程的exit(0)之后会输出这么多行。而且父进程却没有输出,我想,也许是,每个子进程都跑去循环了。。。麻烦各位给点自己的看法
|
输出的问题请看我的验证,输出是把第六行的printf注掉了
root@ubuntu:~# ./mytest
i'm children 11888
i'm children 11889
i'm children 11890
i'm children 11891
i'm father11890
i'm father11889
i'm children 11892
i'm father11889
i'm father11888
i'm children 11893
i'm children 11894
i'm father11893
i'm father11888
i'm children 11895
i'm father11888
i'm father11887
i'm children 11896
i'm children 11897
i'm children 11898
i'm father11897
i'm father11896
i'm children 11899
i'm father11896
i'm father11887
i'm children 11900
i'm children 11901
i'm father11900
i'm father11887
i'm children 11902
i'm father11887
root@ubuntu:~# ./mytest
i'm children 11888
i'm children 11889
i'm children 11890
i'm children 11891
i'm father11890
i'm father11889
i'm children 11892
i'm father11889
i'm father11888
i'm children 11893
i'm children 11894
i'm father11893
i'm father11888
i'm children 11895
i'm father11888
i'm father11887
i'm children 11896
i'm children 11897
i'm children 11898
i'm father11897
i'm father11896
i'm children 11899
i'm father11896
i'm father11887
i'm children 11900
i'm children 11901
i'm father11900
i'm father11887
i'm children 11902
i'm father11887