The following code calls an except script which copies an file via ftp to a server.
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");
As execv() will terminate after execution I spawned a childprocess for this function. Why is the ftptest.exp interupted from parent if I don’t have the sleep(7)….
By “interrupted”, I presume you mean that the parent does not wait for the child to complete the operation before doing whatever it does next?
The parent and the child will run in parallel after the fork. If you want the parent to “hang” until the child is done then you need to
waitfor it.See
man waitand search for fork examples on the internet.