How would I 'attach' a console/terminal-view to an applications output so I can see what it may be saying?
How would I detach from an applications output without killing the application?
Normally if you fire up a talkative application using the command line you get to see all kinds of wonderful output. However, let’s say I have a particularly chatty programming running, like KINO, and I want to view its output at any given moment without restarting it through the command line. I cannot; at least I don't know how.
This question is related to
linux
logging
command-line-interface
How would I 'attach' a console/terminal-view to an applications output so I can see what it may be saying?
About this question, I know it is possible to catch the output, even when you didn't launch sceen command before launching the processus.
While I never tried it, I've found an interesting article which explains how to do using GDB (and without restarting your process).
redirecting-output-from-a-running-process
Basically:
By the way, if you are running a linux OS on i386 box, comments are talking about a better tool to redirect output to a new console : 'retty' . If so, consider its use.
You can use reptyr
:
sudo apt install reptyr
reptyr pid
For me, this worked:
Login as the owner of the process (even root
is denied permission)
~$ su - process_owner
Tail the file descriptor as mentioned in many other answers.
~$ tail -f /proc/<process-id>/fd/1 # (0: stdin, 1: stdout, 2: stderr)
I think I have a simpler solution here. Just look for a directory whose name corresponds to the PID you are looking for, under the pseudo-filesystem accessible under the /proc
path. So if you have a program running, whose ID is 1199, cd
into it:
$ cd /proc/1199
Then look for the fd
directory underneath
$ cd fd
This fd
directory hold the file-descriptors objects that your program is using (0: stdin, 1: stdout, 2: stderr) and just tail -f
the one you need - in this case, stdout):
$ tail -f 1
I was looking for this exact same thing and found that you can do:
strace -ewrite -p $PID
It's not exactly what you needed, but it's quite close.
I tried the redirecting output, but that didn't work for me. Maybe because the process was writing to a socket, I don't know.
I wanted to remotely watch a yum upgrade process that had been run locally, so while there were probably more efficient ways to do this, here's what I did:
watch cat /dev/vcsa1
Obviously you'd want to use vcsa2, vcsa3, etc., depending on which terminal was being used.
So long as my terminal window was of the same width as the terminal that the command was being run on, I could see a snapshot of their current output every two seconds. The other commands recommended elsewhere did not work particularly well for my situation, but that one did the trick.
Source: Stackoverflow.com