我正在尝试使用fork和execlp编写一个程序,其中父进程的地址空间被"ls"命令替换。
#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");
is not printed. Why?