Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor STDERR of all processes running on my linux machine

I would like to monitor the STDERR channel of all the processes running on my Linux. Monitoring should preferably be done at real-time (i.e. while the process is running), but post-processing will also do. It should be done without requiring root permissions, and without breaking any security features.

I have done a good bit of searching, and found some utilities such as reptyr and screenify, and a few explanations on how to do this with gdb (for example here). However, all of these seem to be doing both too much and too little. Too much in the sense that they take full control of the process's stream handles (i.e. closing original one and opening a new one). Too little in the sense that they have serious limitations, such as the fact that require disabling security features, such as ptrace_scope.

Any advice would be highly appreciated!

like image 548
avidane Avatar asked Oct 31 '22 23:10

avidane


1 Answers

Maybe this question would get more answers on SU. The only thing I could think of would be to monitor the files and devices already opened as STDERR. Of course, this would not work if STDERR is redirected to /dev/null.

You can get all the file descriptors for STDERR with:

ls -l /dev/proc/[0-9]*/fd/2

If you own the process, accessing its STDERR file descriptor or output file should be possible in the language of your choice without being root.

like image 157
Eric Fournie Avatar answered Nov 15 '22 05:11

Eric Fournie