Attach to process output for viewing

How would I attach a console / terminal view to the output of the application so that I can see what it says?

How would I tear myself away from application output without killing the application?

Usually, if you start a conversation application using the command line, you see all kinds of wonderful results. However, let’s say I’ve started very chatty programming, such as KINO, and I want to view its results at any time without restarting through the command line. I can not; at least I don’t know how.

+101
linux command-line-interface logging
Apr 3 '09 at 21:17
source share
6 answers

There are several options here. One of them is to redirect the output of the command to a file, and then use the tail to view new lines that are added to this file in real time.

Another option is to run your program inside the "screen", which is a kind of text terminal application. Screen sessions can be attached and disconnected, but nominally intended only for use by the same user, so if you want to share them between users, this is a big pain in the ass.

+14
Apr 3 '09 at 21:20
source share

I think I have a simpler solution here. Just find the directory whose name matches the PID you are looking for in the pseudo -f ilesystem accessible under /proc . So if you are running a program with ID 1199, cd into it:

 $ cd /proc/1199 

Then find the fd directory under

 $ cd fd 

This fd directory contains the file descriptor objects your program uses (0: stdin, 1: stdout, 2: stderr), and just tail -f one you need β€” in this case stdout):

 $ tail -f 1 
+256
Jul 22 '13 at 14:51
source share

I searched for exactly the same thing and found what you can do:

 strace -ewrite -p $PID 

This is not quite what you need, but it is very close.

I tried redirecting the output, but that did not work for me. Perhaps because the process was writing to the socket, I do not know.

+50
Dec 07
source share

How would I attach a console / terminal view to the output of the application so that I can see what it says?

About this question, I know that you can catch the output even if you did not run the sceen command before the processor started.

Although I have never tried, I found an interesting article that explains how to do it with GDB (and without restarting your process).

redirection-exit-s-a-run-in process

Basically:

  1. Check the list of open files for your process, thanks to / proc / xxx / fd
  2. Join your process with gdb
  3. While it is paused, close the file you are interested in by calling the close () function (you can use any function of your process in GDB. I suspect you need debug symbols in your process ..)
  4. Open a new file by calling the create () or open () function. (Look at the comments at the end, you'll see that people suggest using dup2 () to make sure the same descriptor is used)
  5. Turn off the process and start.

By the way, if you are running Linux with an OS on i386, the comments speak of the best tool for redirecting output to a new console: 'retty' . If so, consider using it.

+7
Apr 3 '09 at 22:38
source share

I wanted to remotely monitor the yum update process that was running locally, so although there might have been more efficient ways to do this, here is what I did:

 watch cat /dev/vcsa1 

Obviously, you will want to use vcsa2, vcsa3 etc., depending on which terminal is used.

Since the window of my terminal was the same width as the terminal on which the command was executed, I could see a snapshot of their current output every two seconds. Other teams recommended elsewhere didn't work well for my situation, but this team did the trick.

+1
Oct 08 '14 at 2:40
source share

For me it worked:

  1. Log in as the owner of the process (even root denied permission)

     ~$ su - process_owner 
  2. The file descriptor tail, as mentioned in many other answers.

     ~$ tail -f /proc/<process-id>/fd/1 # (0: stdin, 1: stdout, 2: stderr) 
0
Aug 21 '19 at 9:11
source share



All Articles