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?

12
  • 1
    Check out the answer in this Q&A .. 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, 2016 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, 2016 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, 2016 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, 2016 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, 2016 at 17:34

2 Answers 2

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.
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 !

2
  • 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, 2016 at 16:43
  • @Unkwntech In that case you can use screen 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 to redirect the stderr of your command and read from that when you want after that you send the -usr1 signal.
    – Hastur
    Feb 26, 2016 at 17:01

You must log in to answer this question.

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