Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here is the situation. I left my pc at home doing an rsync from a 2TB hard drive to another 2TB hard drive (it's going to take a while since they are both USB 2.0). I am now at work and I have ssh-ed into my home pc. If I do ps aux | grep rsync I can see the following:

1000  7214 18.8  0.1  30636  1368 pts/0 S+   00:52 134:00 rsync -vr /media/master /media/slave

However I want to see exactly what rsync is doing. When I was at home, the standard output was shown in my terminal and the verbose mode of rsync showed which files were currently being copied. Is there any way to read stdout for another pts?

$ ps -t pts/0
7214 pts/0    02:14:42 rsync

I did a little bit of googling and it seems that /proc/pid/fd may hold the answer but I'm not sure about this...

P.S. I have sudo privileges of course.

share|improve this question
    
Even if it's possible, once it's been shown on the terminal it's no longer in the pty. –  Random832 Jun 10 '11 at 3:32
2  
yeah i guess it depends if some kind of stream needs to be re-directed or if it can just be passively 'read' by my terminal. i should have just done screen rsync ... at home but i didnt expect it to take so long when i started. –  mulllhausen Jun 10 '11 at 3:38
    
If you just want to see what rsync is doing, you can just attach a strace to the process: strace -p 7214 –  Random832 Jun 10 '11 at 3:43
    
i tried strace but it gives a MASSIVE output (probably due to the high speed of the rsync process) like this: read(0, "\n\204C\320\234\33\36\376\36\244H\242\3\1\231\353F[G[SN\244M\0232(\213\247GKh".‌​.., 4092) = 4092 select(1, [0], [], NULL, {60, 0}) = 1 (in [0], left {59, 999998}) –  mulllhausen Jun 10 '11 at 3:46
    
I found it! strace has options you can use, will post answer shortly. –  Random832 Jun 10 '11 at 3:53
add comment

4 Answers 4

Run gdb -p 7214, and do:

p dup2(open("/dev/pts/your-pts-number", 1), 1)
detach
quit

This isn't exactly obvious, but it redirects the stdout from the process you attached to to the path given in the first line (in this case, your desired pts).

share|improve this answer
    
ah looks promising. do i literally type the to-output-to or is this replaced by the number of my current pts? –  mulllhausen Jun 10 '11 at 4:19
    
It's replaced by the number of the pts you want. –  John Flatness Jun 10 '11 at 5:26
    
well i tried it but it doesn't work for me. when i quit i do not see the output from rsync. –  mulllhausen Jun 10 '11 at 6:11
add comment

The strace tool allows you to get a copy of the output going to a particular file descriptor (in this case, stdout and stderr).

strace -e write=1,2 -e trace=write -p 7214

This will appear in hex dump format.

share|improve this answer
    
this would be a really elegant solution if it could produce a human readable output, but the output is unreadable - its all in hex? all lines start with something like write(3, "jh\260)\340\221j\16S\203B\202... which im assuming is due to the writing of data from one drive to the other –  mulllhausen Jun 10 '11 at 5:57
    
Perfect! Very usefull for debugs! And the right column show also ASCII, so its not just HEX. Thanks. –  Dr Beco Oct 12 '13 at 18:50
add comment

You can detach the rsync process from its terminal and move it to the current one. See How can I disown it a running process and associate it to a new screen shell?. The fundamental approach is similar to the gdb command in John Flatness's answer, but tools such as neercs and retty are more robust.

Make sure to import the process into a screen or tmux session, so you don't have to detach it yet again (unless you use neercs, which provides this functionality already).

Another approach is to check what the process is doing right now by looking at what files it has open. lsof will show you that.

lsof -p7214
share|improve this answer
add comment

I haven't tried this, but looks interesing...

http://blog.nelhage.com/2011/01/reptyr-attach-a-running-process-to-a-new-terminal/

Always using GNU Screen to handle the terminal would be a nice solution to this problem!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.