【发布时间】: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 ; disownsetsid dd if=/dev/zero of=zerofile.txt bs=1M count=400
(我的错误:
setsid方法似乎工作正常。对不起大家。 看我的回答)
【问题讨论】:
-
你可以试试
setsid setsid dd ...看看有没有帮助? -
setsid setsid dd ...和setsid setsid dd ...都在工作。我的错。谢谢你,@rodrigo