catch console output from background process

1.7k Views Asked by At

I have a program running on armbian single board computer. The program starts with -b option during the startup of the system. I created this simple shell script

#!/bin/bash
#Myprog server start
sudo -b /home/myprog/myprog

This program is C written and it sometimes outputs some information with printf functions. But since it is started with -b option there's is noting in the console. Now when I log in to the armbian via ssh with Putty I want to occasionally read the output of this program. Is it even possible?

1

There are 1 best solutions below

0
On

Not exactly what you’re asking, but generally speaking it’s better practice to redirect output to a log file than to try to interactively look at the console output for a background app.

Something like:

sudo -b /home/prog/myprog >> /home/prog/log.txt 2>&1

Should do it.

Then view output with

 tail -f /home/prog/log.txt

If it’s really important to you to run interactively without logs, I would suggest running it from within “screen” without backgrounding it.

  screen
  sudo /home/prog/myprog

Then ctrl-d to detach and let it run in background. screen -r to reattach.