0

I currently have a background process on my unix server that's running hours longer than it should be.

I can't remember the command to allow me to see the output of a background process. I'll remember to bookmark this answer!

Ian
  • 251
  • 2
  • 10

4 Answers4

3

What also might be useful if you're uncertain whether it's doing anything at all, is use 'strace'.

If your app is the 'dhcpd' service, run ps ax | grep [d]hcpd

$ ps axufw | grep [d]hcpd
dhcpd    21645  0.0  0.1  19156  4956 ?        Ss   Oct02   0:00 /usr/sbin/dhcpd -f -q -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/ltsp/dhcpd.conf

Your PID is 21645, so you'd run sudo strace -p 21645. Or drop the 'sudo' if you're root already.

It will get the system calls from your application in real time and tell you precisely what your program is doing.

Note: Wrap a letter of the grep command in a bracket to strain out the grep command itself.

Magellan
  • 4,451
  • 3
  • 30
  • 53
2

As a follow up to Mariano Montañez Ureta.

If you can see the task in the jobs window, all you should be able to see something like this:

$ jobs
[1]+  Running                 tail -f .ssh/known_hosts &

If you then use the fg command coupled with the job number you can bring that to the foreground, i.e. fg %1 would bring my tail command to the foreground. You can also use the fg command with a PID.

prateek61
  • 373
  • 2
  • 7
  • hmm..does ubuntu not have the 'jobs' command? I get a command not found. – Ian Oct 05 '12 at 19:54
  • I just tested on an Ubuntu box, and it did have `jobs`. I tested on Ubuntu 12.04. – prateek61 Oct 05 '12 at 21:49
  • @Ian: `jobs` is a Bash built-in. If you don't have it, you're doing other weird things with your system. The jobs command has been around almsost forever. – Magellan Oct 06 '12 at 15:37
  • Bizarre...it's a Mythbuntu 11.04 install. Absolutely does not find 'jobs'...perhaps my computer's unemployed. :-) – Ian Oct 06 '12 at 22:26
  • In any case, you can still forground a task using `fg `. Alternatively you can use strace as suggested by Adrian. – prateek61 Oct 07 '12 at 11:48
1

use fg wich means foreground :)

0
tail -f whatever-file-the-process-is-writing-to.txt
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • the process is not writing to any file. I need to see what's it would be outputting to screen if it was a foreground process. I've done it before, just blanking. – Ian Oct 05 '12 at 00:38
  • If it isn't sending any output anywhere, how do you expect to see it? – Michael Hampton Oct 05 '12 at 00:42
  • I'm pretty sure I did it a year ago...the command enabled you to see what it would be outputting to the terminal it was in the foreground. – Ian Oct 05 '12 at 00:51