summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2014-09-26 15:46:28 +0100
committerPádraig Brady <P@draigBrady.com>2014-09-30 16:08:43 +0100
commit27d2c7383f18d0f59b0d096f156ed6cb1677642b (patch)
tree4751ae63c97f082140065ba434b07afe3807512f /doc
parent4d8c4dfc2170bde7a25bbf5db6dd2d6e54b43fac (diff)
downloadcoreutils-27d2c7383f18d0f59b0d096f156ed6cb1677642b.tar.xz
dd: use more robust SIGUSR1 handling
* src/dd.c (ifd_reopen): A new wrapper to ensure we don't exit upon receiving a SIGUSR1 in a blocking open() on a fifo for example. (iftruncate): Likewise for ftruncate(). (iread): Process signals also after a short read. (install_signal_handlers): Install SIGINFO/SIGUSR1 handler even if set to SIG_IGN, as this is what the parent can easily set from a shell script that can send SIGUSR1 without the possiblity of inadvertently killing the dd process. * doc/coreutils.texi (dd invocation): Improve the example to show robust usage wrt signal races and short reads. * tests/dd/stats.sh: A new test for various signal races. * tests/local.mk: Reference the new test. * NEWS: Mention the fix.
Diffstat (limited to 'doc')
-rw-r--r--doc/coreutils.texi37
1 files changed, 25 insertions, 12 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 1519fcb3e..7d32af582 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -9001,23 +9001,36 @@ occur on disk based devices):
dd conv=noerror,sync iflag=fullblock </dev/sda1 > /mnt/rescue.img
@end example
-Sending an @samp{INFO} signal to a running @command{dd}
-process makes it print I/O statistics to standard error
-and then resume copying. In the example below,
-@command{dd} is run in the background to copy 10 million blocks.
+Sending an @samp{INFO} signal (or @samp{USR1} signal where that is unavailable)
+to a running @command{dd} process makes it print I/O statistics to
+standard error and then resume copying. In the example below,
+@command{dd} is run in the background to copy 5GB of data.
The @command{kill} command makes it output intermediate I/O statistics,
and when @command{dd} completes normally or is killed by the
@code{SIGINT} signal, it outputs the final statistics.
@example
-$ dd if=/dev/zero of=/dev/null count=10MB & pid=$!
-$ kill -s INFO $pid; wait $pid
-3385223+0 records in
-3385223+0 records out
-1733234176 bytes (1.7 GB) copied, 6.42173 seconds, 270 MB/s
-10000000+0 records in
-10000000+0 records out
-5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s
+# Ignore the signal so we never inadvertently terminate the dd child.
+# Note this is not needed when SIGINFO is available.
+trap '' USR1
+
+# Run dd with the fullblock iflag to avoid short reads
+# which can be triggered by reception of signals.
+dd iflag=fullblock if=/dev/zero of=/dev/null count=5000000 bs=1000 & pid=$!
+
+# Output stats every half second
+until ! kill -s USR1 $pid 2>/dev/null; do sleep .5; done
+@end example
+
+The above script will output in the following format
+
+@example
+859+0 records in
+859+0 records out
+4295000000 bytes (4.3 GB) copied, 0.539934 s, 8.0 GB/s
+1000+0 records in
+1000+0 records out
+5000000000 bytes (5.0 GB) copied, 0.630785 s, 7.9 GB/s
@end example
@vindex POSIXLY_CORRECT