【问题标题】:How to stop the rsync process by system("ssh host rsync...")?如何通过系统(“ssh host rsync ...”)停止rsync进程?
【发布时间】:2011-04-16 09:26:28
【问题描述】:

我是这样写的 Perl 脚本。(/tmp/file 是 fuge)

system("ssh host1 'rsync -av /tmp/file host2:/tmp/'");

然后,我运行这个脚本,然后按 Ctrl+C 杀死。

脚本已停止,但 host1 上的 rsync 进程仍在运行。

如何通过Ctrl+C停止rsync进程?

【问题讨论】:

    标签: perl ssh rsync


    【解决方案1】:

    试试

    system("ssh -t host1 'rsync -av /tmp/file host2:/tmp/'");
    

    【讨论】:

      【解决方案2】:

      如果你检测到 CTRL-C 中断,我猜你应该捕获 rsync 进程 id (PID) 并杀死这个 PID。使用 bash 脚本,您可以使用 pid=$! 捕获最后一个 pid。您可以在此信号 SIGINT 上使用 bash trap 函数检测 CTRL-C 中断 (SIGINT=2),例如:trap 'clean_exit' SIGINT 启动 干净的退出功能。然后你可以在 clean exit 函数中做任何你需要的事情,比如杀死之前捕获的 PID。

      【讨论】:

        猜你喜欢
        • 2013-05-15
        • 1970-01-01
        • 2013-06-28
        • 2019-12-30
        • 1970-01-01
        • 2012-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多