3

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?

david6630
  • 169
  • 1
  • 3
  • 8

3 Answers3

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
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...
Community
  • 1
  • 1
Leeor
  • 19,260
  • 5
  • 56
  • 87
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