由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - fork() and execve() in Unix
相关主题
各位大哥帮忙,EXECVE()的使用[转载] 活见鬼了---搞不定的程序
A problem about child process.大侠帮忙看看这段程序,想不通
FreeBSD: Can't kill child process![转载] waitpid 一问
how to fork a subroutine in unix?how to record the process end time in a child process and obtain it in the parent process?
"fork" program question.Re: how to close port/socket from parent process?help!!!!!!!!!
help!!! pipe programhow to run background process after logout
error in my function "write_log"Help please! 怎么keep当前还在运行的child process
[转载] UNIX下的strtok[转载] how to get process state in C/C++
相关话题的讨论汇总
话题: process话题: child话题: null话题: parent话题: execve
进入Unix版参与讨论
1 (共1页)
h******m
发帖数: 10
1
I got 2 cod of parent.c and child.c here:
parent.c:
#include
#define NULL 0
int main(void)
{
if(fork()==0){execve("child",NULL,NULL);exit(0);}
printf("Process[%d]:Parent in execution\n",getpid());
sleep(2);
if(wait(NULL)>0)printf("Process[%d]:Parent detects terminatin
child",getpid());
printf("Process[%d]:Parent terminating\n",getpid());
}
child.c:
int main()
{
printf("Process[%d]:child in execution\n",getid());
sleep(1);
printf("Process[%d]:child terminating\n",getid());
}
and
o***z
发帖数: 133
2
the control wasn't switched from parent to child until this was done
n******t
发帖数: 4406
3

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is no way to make sure child exec first after fork call
unless you synchronize it.

【在 h******m 的大作中提到】
: I got 2 cod of parent.c and child.c here:
: parent.c:
: #include
: #define NULL 0
: int main(void)
: {
: if(fork()==0){execve("child",NULL,NULL);exit(0);}
: printf("Process[%d]:Parent in execution\n",getpid());
: sleep(2);
: if(wait(NULL)>0)printf("Process[%d]:Parent detects terminatin

h******m
发帖数: 10
4

parent,so
So the lines after
if(fork()==0){execve("child",NULL,NULL);exit(0);}
were executed before child,right? But why it was said that the child took
over?And why
if(wait(NULL)>0)printf("Process[%d]:Parent detects terminatin
was executed after the termination of the child?
Thanks for attention.

【在 n******t 的大作中提到】
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: It is no way to make sure child exec first after fork call
: unless you synchronize it.

N*********r
发帖数: 40
5
if( fork() == 0 ) { /* A */ }
else { /* B */ }
A is the child process and B is the parent process. As netghost has said,
there is no way to make sure A get executed first or B get executed first.
now in A, you called execve. so another executable 'child' takes over the
child process. but it doesn't affect the parent process, nor the timing
relationship between parent and child.

【在 h******m 的大作中提到】
:
: parent,so
: So the lines after
: if(fork()==0){execve("child",NULL,NULL);exit(0);}
: were executed before child,right? But why it was said that the child took
: over?And why
: if(wait(NULL)>0)printf("Process[%d]:Parent detects terminatin
: was executed after the termination of the child?
: Thanks for attention.

1 (共1页)
进入Unix版参与讨论
相关主题
[转载] how to get process state in C/C++"fork" program question.
emacs问题求教----有关C程序格式help!!! pipe program
interview questionerror in my function "write_log"
awk question[转载] UNIX下的strtok
各位大哥帮忙,EXECVE()的使用[转载] 活见鬼了---搞不定的程序
A problem about child process.大侠帮忙看看这段程序,想不通
FreeBSD: Can't kill child process![转载] waitpid 一问
how to fork a subroutine in unix?how to record the process end time in a child process and obtain it in the parent process?
相关话题的讨论汇总
话题: process话题: child话题: null话题: parent话题: execve