c - fork()-parent 忽略 except 脚本的 execv()

标签 c linux ubuntu-12.04

以下代码调用 except 脚本,该脚本通过 ftp 将文件复制到服务器。

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() 将在执行后终止,因此我为此函数生成了一个子进程。如果我没有 sleep(7),为什么 ftptest.exp 从父级中断......

最佳答案

所谓“中断”,我猜你的意思是 parent 不会等待 child 完成操作后再做下一步的事情?

parent和child会在fork之后并行运行。如果您希望父级“挂起”直到子级完成,那么您需要等待

参见 man wait 并在互联网上搜索 fork 示例。

关于c - fork()-parent 忽略 except 脚本的 execv(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12348997/

相关文章:

c - 使用 CreateProcessAsUser 将用户恢复到 session 1 后,用户的路径不再可访问

c - 为什么asm代码在C中的函数比c代码函数花费更多的时间?

linux - 是否有用于访问 Docker 19.03 中的 docker buildx 的 HTTP api?

c++ - std::atomic_thread_fence 具有 undefined reference

timezone - ubuntu : change timezone to UTC does not affect the time of syslog?

c - 没有规则可以创建 `main.c' 所需的目标 `main.o' 。停止

c - 多进程文件操作

linux - bash:xargs 传递变量

linux - 使用 grep 计算出现次数

svn - 可以通过右键菜单忽略 RabbitVCS 中的文件吗?