Is there a way to view the console outputs of a particular script that is running in the background on a machine?

Maybe using the pid or something similar.

For example, to view the output of this script


while (1) {
  print "OUTPUT\n"

Example Usage

-> ps ax | grep script.pm

<- 1234 ? S 0:05 /var/lib/script.pm

-> monitor 1234 #this is a fake command






  • 2
    Why not just redirect the output of the background script to a file and then monitor the output of the file? – Raman Sailopal Apr 23 '18 at 14:58
  • it's for a mojo server spread across many files in deployment and I'm trying to see at any level where errors are occurring, or just general diagnostic output. @RamanSailopal – Bigbob556677 Apr 23 '18 at 15:00
  • 1
    I agree with @RamanSailopal, you'll want to ship STDOUT and STDERR from your application to a log file, and then up to a log ingestion server that can process and query the logs from all the different application servers. Look into the ELK stack or Graylog. – BoomShadow Apr 23 '18 at 15:05
  • maybe GNU Screen can help. Also, take a look at this question – Ankur S Apr 23 '18 at 15:11

If the process is running in the background, you can move it to the foreground of your current shell with the fg command. The processes output will then start writing to your shell.

If you want to send the process back to the background, you can press CTRL+Z to suspend the process, then the bg command to send it back to the background.

fg PID
bg PID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.