fork() and execve() in Unix# Unix - 噫吁兮,危乎高哉
h*m
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
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