2

if i do dd if=/dev/zero of=/dev/null it show the results on terminal. but i want to run this command for a specific period of time and show the results. for example, i tried

timeout 10s dd if=/dev/zero of=/dev/nul but i get no stdout / stderr on terminal.

i tried using some timeout options like "--preserve-status", "--foreground" and "-v --verbose" but i still get no output on the terminal.

is there a way i can get the results to show on terminal or even to a file?

3 Answers 3

5

Use the --foreground option for timeout in combination with INT signal to dd.

timeout --foreground -s INT 0.1 dd if=/dev/zero of=/dev/null

Documentation for timeout say:

--foreground
  when not running timeout directly from a shell prompt,
  allow COMMAND to read from the TTY and get TTY signals;
  in this mode, children of COMMAND will not be timed out

From what I can see trough traces etc. it looks like this works better for dd. Without --foreground the process get the INT signal but then a CONT to both dd and timeout which rapidly result in the process exiting. In very rare cases dd does get the time to process the INT signal, but that is not the norm.

With --foreground the CONT is never sent and dd get time to print the stats before exiting.

The cleanup function linked above is called on first iteration call to sigsuspend.

dds process_signals() is extremely rarely called after interrupt_signal has been set when CONT is in process for timeout (i.e. --foreground not set).

1
  • thanks a lot, that worked!, i had forgotten to use the foreground in conjunction with the signal. and thanks for the extra explanation!
    – Boris L
    Commented Jun 21, 2021 at 15:26
0

If you want to display dd's output on stderr (like interrupting a dd process with Ctrl+C), use the SIGINT signal instead of the default SIGTERM:

timeout -s INT 10s dd if=/dev/zero of=/dev/null

To redirect stderr to file logfile, use

timeout -s INT 10s dd if=/dev/zero of=/dev/null 2> logfile
2
  • that actually makes sense, on theory it should work, but i tried with INT and TSTP signals still no output is emitted, even redirecting the stderr and stdout to the logfile, no output or error is shown at all.
    – Boris L
    Commented Jun 20, 2021 at 22:19
  • one thing that i noticed is, redirecting the stderr (2>) to a file it works if I specify the verbose flag and do a Ctrl+C before the timeout interval time runs out. but if I let the timeout interval time finish on its own, nothing is written to the file, not even if I specify the INT signal flag to timeout
    – Boris L
    Commented Jun 20, 2021 at 22:38
0

Try this:

timeout -s INT --foreground 10s dd if=/dev/zero of=/dev/null

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .