Linux/BSD:如何调用忽略/绕过超时命令的程序/脚本?



这是我的脚本

$ 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 dd ...

我错误地执行了测试。 我已经编辑了原始问题来反映。 不好意思。

最新更新