Using strace With this command, we use its -p option for the process ID. We also use the -s9999 option to indefinitely expand the string size output. The default string size is 32 characters. Finally, we use the -e write option to allow ASCII and hexadecimal characters.
You can use the ps command to find out which processes are running and display information about those processes. The ps command has several flags that enable you to specify which processes to list and what information to display about each process.
You can use the below line to check what your process is doing. $ strace -p $! $! gives the process ID of the last background process.
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.
There are a few options here. One is to redirect the output of the command to a file, and then use 'tail' to view new lines that are added to that file in real time.
Another option is to launch your program inside of 'screen', which is a sort-of text-based Terminal application. Screen sessions can be attached and detached, but are nominally meant only to be used by the same user, so if you want to share them between users, it's a big pain in the ass.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With