调用exec()后进程在何处终止
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main()
{
int a = 1;
int pid;
char buff[] = "before fork";
if(write(1, buff, sizeof(buff) - 1) != (sizeof(buff) - 1))
{
perror("write error");
exit(0);
}/* fork之前的代码不会在子进程中执行 */
if( (pid = fork()) == -1 )
{
perror("fork error");
exit(1);
}
else if(pid == 0)
{
if( execlp( "./write1", "write1", (char *)0 ) == -1 )
{
perror("execlp error");
exit(1);
}/* exec函数执行的程序替换了所在进程的进程空间,执行完后进程就终止了了,所以下面两行代码不会执行 */
/*********************进程在此处终止*****************************/
a++; /* 不会执行 */
printf("%d", a); /* 不会执行 */
}
if( execlp( "./write1", "write1", (char *)0 ) == -1 )
{
perror("execlp error");
exit(1);
}
/*********************进程