[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Trying to understand man page for dd



On Mon 29 May 2017 at 09:13:21 (-0500), Richard Owlett wrote:
> On 05/29/2017 08:36 AM, David Wright wrote:
> >On Mon 29 May 2017 at 06:59:23 (-0500), Richard Owlett wrote:
> >
> >>I think the is a subtle bug in the man page.
> >>I introduces the two lines of code saying:
> >>  > Sending a USR1 signal to a running 'dd' process makes it print
> >>  > I/O statistics to standard error and then resume copying.
> >>I believe that to accurately describe the code at
> >>
> >>https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html#dd-invocation
> >>*NOT* the code on the man page.
> >
> >The two lines you quote don't "introduce" anything. They describe
> >the action of dd when you send a USR1 signal to it, a primary
> >purpose of the man page.
> >
> >>I realize now that was the discrepancy that prompted my question.
> >>I had gone to the man page to double check syntax. Spotted the code
> >>a thought "a way to display progress information when copying".
> >>
> >>I can "sort of" understand syntactically correct code. The less said
> >>of my programming skills the better ;/ How I "read" the code just
> >>didn't jibe with the description.
> >>
> >>Am I correct that there is a problem with the man page?
> >
> >Not that I can see. A terse illustration of program output might
> >be seen as an infrequent but welcome addition to a man page.
> >However, others might prefer not to lengthen the man page (which
> >is a one chunk affair) with tutorials, or even examples,
> >preferring to leave that for info nodes or other more extensive
> >documentation.
> >
> >Cheers,
> >David.
> >
> >
> 
> Not quite. It says "...and then resume copying."
> The script copies bytes until the second line is encountered.
> It outputs data and *STOPS DEAD*
> richard@stretch-2nd:~$ dd if=/dev/zero of=/dev/null& pid=$!
> [1] 3600
> richard@stretch-2nd:~$ kill -USR1 $pid; sleep 1; kill $pid
> 53590611+0 records in
> 53590610+0 records out
> 27438392320 bytes (27 GB, 26 GiB) copied, 21.6988 s, 1.3 GB/s
> richard@stretch-2nd:~$

With respect, dd does not stop after printing out the statistics.
It carries on running exactly as the man page specifies.
You can demonstrate this for yourself by a small modification
of the final command: send the signal INT instead of TERM:

$ dd if=/dev/zero of=/dev/null& pid=$!
[1] 12121
$ kill -USR1 $pid; sleep 1; kill -INT $pid
8113119+0 records in
8113118+0 records out
4153916416 bytes (4.2 GB) copied, 10.6885 s, 389 MB/s
$ 8895227+0 records in
8895226+0 records out
4554355712 bytes (4.6 GB) copied, 11.714 s, 389 MB/s
                                                        ← I pressed <RETURN>
[1]+  Interrupt               dd if=/dev/zero of=/dev/null
$ 

So 0.4GB was copied during the one-second sleep because dd resumed
copying.

Alternatively, because there's no cost associated with typing
extra lines on your terminal, type the following, slowly:

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid
$ kill -USR1 $pid
$ kill -USR1 $pid # until you are convinced
$ kill -USR1 $pid
$ kill $pid

Once again, you've tried to overinterpret this:

  Sending a USR1 signal to a running 'dd' process makes it print
  I/O statistics to standard error and then resume copying.

as a description of this:

              $ dd if=/dev/zero of=/dev/null& pid=$!
              $ kill -USR1 $pid; sleep 1; kill $pid

It isn't. It's a description of the behaviour of dd.

Cheers,
David.


Reply to: