Linux: can I read the output of another process without using any IPC (pipes, etc.)?

Is it possible in linux to somehow read the result (from stdout and stderr) of another process without knowing it? So, let's say I have a process A running in the background, and process B wants to read its output - is this possible? I can not use the channels or the program on the screen. I tried reading from / proc / xxx / fd or from / pts / x consoles, etc., but so far nothing has worked.

+6
linux process tty
source share
3 answers

In the kernel, I think you could write a driver that intercepts read and write to get what you want.

In user space, you can compile a modified glibc that outputs the output of stdout and stderr to some file along with the process and thread id. But itโ€™s risky if you break something. (assuming that the applications you want to track are not statically connected or do not create direct system calls to the kernel)

+1
source share

I read the question that you are not going to write kernel code, and that the idea is not to change the executable that you are following.

Given these limitations, the answer is simple. No, you can not. A process calls a record (1 or record (2), and they can be sent anywhere, and there is no โ€œwired connectionโ€ built into the system to help you see traffic on the way.

+1
source share

Just using the dup2 function:

int b_fd; /* This is the B process File descriptor*/ int a_fd /* This is the A process File descriptor*/ int main (int argc, char*argv[]){ /** I suppose that you can init the file descriptor for A*/ dup2( b_fd, a_fd); /**Now everything that A will output will be written in B file descriptor*/ } 
-one
source share

All Articles