【问题标题】:Linux/BSD: How can I call a program/script ignoring/bypassing the timeout command?Linux/BSD:如何调用忽略/绕过超时命令的程序/脚本?
【发布时间】:2020-04-13 13:48:28
【问题描述】:

这是我的脚本

$ cat LongRun.sh
#!/usr/bin/env bash
echo "This line will obbey the timeout command and stop"

# This line below needs to run until it finishes:
dd if=/dev/zero of=zerofile.txt bs=1M count=400

echo "More lines that can be stopped"

运行时:

$ ./LongRun.sh
This line will obbey the timeout command and stop
400+0 records in
400+0 records out
419430400 bytes (419 MB, 400 MiB) copied, 31.3204 s, 13.4 MB/s
More lines that can be stopped

结果是:

$ ls -la zerofile.txt
-rw-r--r-- 1 luis luis 419430400 Dec 21 10:47 zerofile.txt

但是,当运行它通过 timeout

$ timeout 2s ./LongRun.sh
This line will obbey the timeout command and stop
$ ls -la zerofile.txt
-rw-r--r-- 1 luis luis 108195840 Dec 21 10:48 zerofile.txt

我想要完整的结果文件,所以 dd 行应该不要停止并创建一个完整的 400MiB 文件:

如何在 Linux/FreeBSD 上做到这一点?

测试(没有成功)到现在:

  • nohup dd if=/dev/zero of=zerofile.txt bs=1M count=400 &
  • nohup $(dd if=/dev/zero of=zerofile.txt bs=1M count=400) &
  • nohup $(dd if=/dev/zero of=zerofile.txt bs=1M count=400 &) &
  • dd if=/dev/zero of=zerofile.txt bs=1M count=400 ; disown
  • setsid dd if=/dev/zero of=zerofile.txt bs=1M count=400

(我的错误:setsid 方法似乎工作正常。对不起大家。 看我的回答)

【问题讨论】:

  • 你可以试试setsid setsid dd ...看看有没有帮助?
  • setsid setsid dd ...setsid setsid dd ... 都在工作。我的错。谢谢你,@rodrigo

标签: multithreading timeout


【解决方案1】:

回答自己:

他们都工作

setsid setsid dd ...
setsid dd ...

我错误地执行了测试。 我已经编辑了原始问题以反映。 对不起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 2011-06-27
    • 2010-10-21
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多