avatar
A problem about child process.# Unix - 噫吁兮,危乎高哉
l*t
1
if( (pid = fork()) == 0 )}
.....
i = execvp(xxx,xxxxx[]);
if( i == -1 ){
printf("error!");
//kill(pid,9) ???
}
}
ps
1201 proc1
1203 proc1
.....
when execvp fail, the child process 1203 is
still runing,if I use kill when fail,the
process 1201 will be killed too.
How can I kill 1203 only when exec fail?
thanks!
avatar
l*l
2
When you kill(pid,9), the parent and child use same file_descript in pages,
that is from your fork source. So you can't kill the child simply, you can
fork for an other time and the child of child can be stoped.

【在 l***t 的大作中提到】
: if( (pid = fork()) == 0 )}
: .....
: i = execvp(xxx,xxxxx[]);
: if( i == -1 ){
: printf("error!");
: //kill(pid,9) ???
: }
: }
: ps
: 1201 proc1

avatar
w*n
3

why not use exit()?
if (fork()==0){
execvp(...);
exit();
}
There is no need to test the return value of exec.

【在 l***t 的大作中提到】
: if( (pid = fork()) == 0 )}
: .....
: i = execvp(xxx,xxxxx[]);
: if( i == -1 ){
: printf("error!");
: //kill(pid,9) ???
: }
: }
: ps
: 1201 proc1

avatar
j*y
4

you are calling kill(0, 9);
check the man page of kill, process 0 has special meaning.

【在 l***t 的大作中提到】
: if( (pid = fork()) == 0 )}
: .....
: i = execvp(xxx,xxxxx[]);
: if( i == -1 ){
: printf("error!");
: //kill(pid,9) ???
: }
: }
: ps
: 1201 proc1

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。