0
以下代码调用一个except脚本,该脚本通过ftp将文件复制到服务器。fork() - parent忽略除脚本外的execv()
int status;
int child_pnr;
if((child_pnr = fork())==0)
{
printf("Childnr %i\n",child_pnr);
execv("/home/..../ftptest.exp",NULL);
}
else if (child_pnr > 0)
{
printf("Parent... childnr %i generated\n",child_pnr);
sleep(7);
}
else
perror("fork() error");
由于execv()将在执行后终止,我为此函数产生了一个子进程。如果我没有睡眠(7),为什么从父母中断了ftptest.exp ...
只是为了澄清:execv(或任何'exec'函数族)在执行后不会终止。实际上''execv''在被调用的程序中用进程替换了子进程,'execv'永远不会返回(除非执行程序时出错)。 –