Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
hmm..does ubuntu not have the 'jobs' command? I get a command not found. –  Ian Oct 5 '12 at 19:54
    
I just tested on an Ubuntu box, and it did have jobs. I tested on Ubuntu 12.04. –  prateek61 Oct 5 '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 6 '12 at 15:37
    
Bizarre...it's a Mythbuntu 11.04 install. Absolutely does not find 'jobs'...perhaps my computer's unemployed. :-) –  Ian Oct 6 '12 at 22:26
    
In any case, you can still forground a task using fg <pid>. Alternatively you can use strace as suggested by Adrian. –  prateek61 Oct 7 '12 at 11:48

use fg wich means foreground :)

share|improve this answer
tail -f whatever-file-the-process-is-writing-to.txt
share|improve this answer
    
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 5 '12 at 0:38
    
If it isn't sending any output anywhere, how do you expect to see it? –  Michael Hampton Oct 5 '12 at 0: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 5 '12 at 0:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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