D
D
Decker2018-05-10 11:30:41
linux
Decker, 2018-05-10 11:30:41

How to get stdout of already running process?

There was a simple problem and, unfortunately, I can not find a solution. There is a certain process process outputting information to stdout. Let's assume that we connected to the server via ssh and started this process as process &. As a result, while we are in this SSH session, we see everything that this process writes to stdout on the screen, but when we relogin to the server, of course, we don’t see anything anymore, although this process works in the background. About redirecting input / output to a file, screen, etc. - I know.
Interested in a way to read the stdout of an already running process. From /proc/$(pid)/fd/1, as advised on the Internet, for some reason nothing works. Those. tail -f /proc/$(pidof process)/fd/1outputs nothing. readlink -f /proc/$(pidof process)/fd/1shows /dev/pts/19, but options like tail -f /dev/pts/19or cat /dev/pts/19also don't work.
As a result, the question remains open - how to see the stdout of an already running process if it is disconnected from the console? Or maybe there is an opportunity to "attach" it to the console back? Thanks in advance.
ps I would like to implement the task without redirecting the output of the process to a file and without launching it in screen.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
chupasaurus, 2018-05-10
@chupasaurus

reptyrinvented for this.

S
synapse_people, 2018-05-10
@synapse_people

why doesn't it work with fd/1? Should work

J
jcmvbkbc, 2018-05-10
@jcmvbkbc

when relogin to the server, when relogin to the server, of course, we don’t see anything anymore, although this process works in the background, of course, we don’t see anything anymore, although this process works in the background

Something I'm not sure that the process is "running in the background". Because if you start the process as a background process and then close the terminal, the next output to stdout of the process ends with an error (which can be viewed through strace):
Then the normal process ends. An abnormal process, of course, can continue to write to a file after an error, but what happens is difficult to say.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question