0

I have a long dd process running on a Debian system from the local console.

I know that I can send USER1 or CTRL+T on the local console, but my only means for the time being is to monitor it via ssh. Google has been unfortunately unhelpful here.

Is there a simple way to monitor it's progress remotely without stopping the current task?

Hastur
  • 18,764
  • 9
  • 52
  • 95
Unkwntech
  • 575
  • 2
  • 4
  • 10
  • 1
    Check out the answer in [this Q&A](http://askubuntu.com/questions/215505/how-do-you-monitor-the-progress-of-dd) .. `kill -USR1` doesn't have to be run from a local terminal, it just has to be runnable with the right permissions (i.e. you might need to `sudo kill`) .. did that not work, or can you not open a 2nd SSH instance to monitor? – txtechhelp Feb 26 '16 at 16:03
  • Note: It is reported _You have to use `kill -INFO $(pgrep ^dd$)` on BSD systems (like OSX)._ because _This way interupts dd work under OSX._ from two comment from that post for BSD users... – Hastur Feb 26 '16 at 16:11
  • What about to send the command via `ssh`? Something like `ssh 'kill -USR1 $(pgrep ^dd)' ` ? Of course only when you know that `kill -usr1` will not stop the execution of your command. – Hastur Feb 26 '16 at 16:19
  • 1
    When you send USR1 it causes DD to print the current progress to the console it was started on, not the one it was sent from. – Unkwntech Feb 26 '16 at 16:53
  • Can you confirm if you have just launched the command and if you have just left the place where is open the console? – Hastur Feb 26 '16 at 17:34
  • From those links [1](http://www.serenux.com/2011/02/howto-monitor-the-progress-of-dd/), [2](http://askubuntu.com/a/215521/196535) they say __open another terminal__ and run the command `kill -USR1...`. Please [edit] you post adding the version of DD. Unfortunately it is not so. – Hastur Feb 26 '16 at 17:42
  • @Hastur, yes DD is running and when you open the second console to send DD the USR1 signal, it reports it's information back on the console it is running on, not the new console. – Unkwntech Feb 26 '16 at 17:50
  • ... and so did you tried? – Hastur Feb 29 '16 at 05:04
  • @Hastur, yes and it works as described. – Unkwntech Feb 29 '16 at 15:50
  • @Unkwntech I don't understand: does it works the updated answer with `strace`? Because on my computer it works fine, but I had no time to try on Debian too... – Hastur Feb 29 '16 at 16:13
  • @Hastur,as I said it isn't an answer to the question because it doesn't print to the correct console. – Unkwntech Feb 29 '16 at 18:27
  • Look well: You have output in the original one (of course, but you didn/t ask to suppress it) but even in the shell (via `ssh`) from which you use `strace`. – Hastur Feb 29 '16 at 19:22

2 Answers2

1

With pv

pv can watch another process. The relevant part of man 1 pv:

-d PID[:FD], --watchfd PID[:FD]

Instead of transferring data, watch file descriptor FD of process PID, and show its progress. The pv process will exit when FD either changes to a different file, changes read/write mode, or is closed; other data transfer modifiers - and remote control - may not be used with this option.

If only a PID is specified, then that process will be watched, and all regular files and block devices it opens will be shown with a progress bar. The pv process will exit when process PID exits.

There are restrictions though:

  • This only works for regular files and block devices. If your dd is in the middle of a pipeline, pv -d won't watch its stdin or stdout. Progress bar makes no sense in this case, still you may want to see throughput. But even if you explicitly specify PID:0 or PID:1, this won't work.
  • Normally, as a regular user you cannot watch another user's processess.

The advantage is this approach is totally non-intrusive. It shouldn't affect the running dd in any way.


With reptyr

Another approach is with reptyr; see this answer of mine.

Start screen or tmux and use reptyr to attach the running dd to the new terminal. If this succeeds then you will be able to see dd's reaction to signals in the new terminal. Detach from screen/tmux and reattach if needed.

Notes:

  • dd's reaction to signals will no longer appear in the old terminal.
  • reptyr will redirect relevant file descriptors and change the controlling terminal of dd; so this is intrusive in a way. My advice is to try this with a "scratch monkey dd" first.
  • In some cases (e.g. dd in a pipeline) reptyr is unable to attach. Then reptyr -T may work, but it will affect other processes, not only dd. Please see man 1 reptyr for details.
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
0

Now that the long dd command is running, it is too late to redirect its output. Maybe you are far from the console and you cannot use screen or to create a FIFO for its stderr...

... but you can still use two ssh session and strace !

On the first ssh session you can write

sudo strace -ewrite -p `pgrep ^dd`  2>&1 | grep -v "write(1,"

On the second instead (read the warning note below for the signal to use -SIGUSR1 or SIGINFO)

kill -USR1 $(pgrep ^dd)

And read a not so nice output from the first similar to the one below

Process 26176 attached
--- SIGUSR1 {si_signo=SIGUSR1, si_code=SI_USER, si_pid=29517, si_uid=0} ---
write(2, "329094980+0 records in\n329094979"..., 47) = 47
write(2, "168496629248 bytes (168 GB) copi"..., 34) = 34
write(2, ", 109.221 s, 1.5 GB/s\n", 22) = 22

Note: Unfortunately (even if differently reported) the command kill -USR1 $(pgrep ^dd) will force the running dd processes to write to their original stderr. For this it was needed to modify the original answer (you can see in the version history).
Warning: As reported on this other answer the signal to send with kill instead of -USR1 may depend from the Linux distro. Under OpenBSD -SIGINFO under Ubuntu SIGUSR1. Check it carefully in advance a wrong one can terminate the process !

Hastur
  • 18,764
  • 9
  • 52
  • 95
  • Unfortunately this isn't a solution, as when DD receives the USR1 signal it reports it's progress on the console where it was run. – Unkwntech Feb 26 '16 at 16:43
  • @Unkwntech In that case you can use [`screen`](http://ss64.com/bash/screen.html) and take it back with ssh. Else since from man I read that `-usr1` _"makes it print I/O statistics to standard error "_, you can use a [Named Pipe](http://www.tldp.org/LDP/lpg/node15.html) to redirect the stderr of your command and read from that when you want after that you send the `-usr1` signal. – Hastur Feb 26 '16 at 17:01