我试图用fork和execlp程序,其中父地址空间替换为“ls”命令。叉和Execlp
#include<stdio.h>
main()
{
int pid,j=10,fd;
pid=fork();
if(pid==0)
{
printf("\nI am the child\n");
execlp("/bin/ls","ls",NULL);
printf("\nStill I am the child\n");
}
else if (pid > 0)
{
printf("\n I am the parent\n");
wait();
}
}
当我执行程序的孩子
printf("\nStill I am the child\n");
的最后一行不打印。为什么?
几个好点,但在新的过程中,pid肯定是不同的。另外,如果exec成功,exec只会替换进程,否则它将在exec调用之后继续 – techdude