I'm testing on Debian a routing algorithm wrote in C. In algorithm source file i set a flag to 1 to enable the printing of routing decisions on stdout. Problem is: the process that runs this file is a background process. How can i see stdout?
Asked
Active
Viewed 1.6k times
3 Answers
5
You can use the below line to check what your process is doing.
$ strace -p $!
$!
gives the process ID of the last background process. Remember to run the above line in same console as the background process.

3cheesewheel
- 9,133
- 9
- 39
- 59

neo
- 969
- 1
- 11
- 23
-
1What if the original console is disconnected and I have to login on from another console ? – Lewis Chan Dec 20 '18 at 01:59
4
Assuming you have the process you want to listen to already up and running, and you don't want to stop and rerun it with a redirection as Laszlo suggests: you can use strace
to listen to it - How should strace be used?
Basically it can track all system call activities, but that includes printing
Add -p <pid>
to attach it to your desired process. Add -e write
to filter most of the stuff and get only the output writes
For e.g.:
> grep somestring . -R >& /dev/null &
[2] 8093
> strace -p 8093 -e write
...here goes the output...
1
You redirect the output of your program into a file, and then you can watch the output in that file.

Laszlo Valko
- 2,683
- 25
- 29