0

When dd is done it prints a three line summary about the number of read and written segments, the total size and average writing speed. While it does its work, dd is awfully quiet.

Not too long ago (mea culpa) I discovered that I can make dd print the three line summary while it is still doing work by emitting SIGUSR1. Ever since I do

dd <magic incantation> &
watch kill -USR1 $!

The problem is, that with this the three lines of dd's summary are not left aligned. Each following line starts at the column the previous line ended. So I'm guessing dd prints a newline character, but not a carriage return and whatever watch uses to print output expects carriage returns.

I tried putting | sed -e '<expression>' behind the kill command different sorts of quoting but the output I get presented does not change at all.

How can I pretty print the dd output in this scenario?

Bananguin
  • 7,984

2 Answers2

3

You don't need kill -USR1 to know where dd is at. You can use lsof to display the position of its input file descriptor. Getting parseable output is a bit abstruse, but it works. Note that the 0 is the input file descriptor; if you pass a if=… argument to dd rather letting it read from standard input, then depending on your implementation of dd, it might read from a different descriptor.

lsof -a -o -p $! -d 0 -F o | sed -n 's/^o[0-9]*t//p'

On Linux, you can get this information directly from /proc.

</proc/$!/fdinfo/0 awk '$1 == "pos:" {print $2}'

You might as well use cat instead of dd: it's often faster and it's less error-prone.

0

I have the same problem in Ubuntu 20.04 terminal. But launching from RXVT make the display behave correctly :

sudo su - # From the default Ubuntu terminal
dd if=... &
rxvt
watch -n 0.5 kill -USR1 <process number of the dd>

(but well, I don't know why.)