2

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
  • 109
  • 1
  • 2
  • 7

3 Answers3

4

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
  • 8,503
  • 7
  • 36
  • 58
neo
  • 937
  • 1
  • 10
  • 22
3

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
  • 18,457
  • 5
  • 52
  • 82
1

You redirect the output of your program into a file, and then you can watch the output in that file.

Laszlo Valko
  • 2,543
  • 20
  • 28