I am struggling to get a process to run in the background on a Ubuntu Linux machine. I run: -
/home/brad > /usr/bin/nohup sudo /home/brad/spideroak/jsystem/runner/runAgent < /dev/null &
[1] 5611
/home/brad > /usr/bin/nohup: appending output to `nohup.out'
[1] + Stopped (SIGTTOU) /usr/bin/nohup sudo /home/brad/spideroak/jsystem/runner/runAgent < /dev/null &
/home/brad > exit
/home/brad > You have stopped jobs
The job kicks off ok but when I press enter I get the SIGTTOU message. Trying to exit warns me about the stopped jobs and if I continue to log out the job dies.
This is running under Korn shell on Ubuntu.
Can anyone tell me why I can't log out of the terminal without the job dying?
The system is stopping your process with a SIGTTOU signal because while it's in the background it's trying to write to the terminal. If you want to avoid that, you should redirect stdout and stderr before backgrounding, or trap the signal and react appropriately (whatever that means for your task).
With regard to not being able to exit the shell without killing the job, have a look at the "disown" builtin in your shell's man page.
Thanks for the reply. Actually I have tried quite a variety of variations on this command: -
/usr/bin/nohup sudo /home/brad/spideroak/jsystem/runner/runAgent >/dev/null 2>&1 &
/usr/bin/nohup sudo /home/brad/spideroak/jsystem/runner/runAgent > ~/runAgent.out 2>~/runAgent.err &
To mention but a few
I thought that nohup automatically redirected stderr and out to nohup.out anyway.
This really shouldn't be so hard :wall:
I'm wondering if there is some sort of job control mechanism interfering with this.
---------- Post updated at 04:01 PM ---------- Previous update was at 03:49 PM ----------
I should add that I can run a simple script to echo the date in the background using nohup and then exit without any problem. It still runs ok.
The runAgent script calls another wich eventually kicks of a Java process. Don't know if that is sigificant...
Duh. I forgot about that. You're correct of course. Still, SIGTTOU is the result of something trying to write to the terminal. Perhaps sudo is prompting for a password? Even if you (or nohup) have redirected stdin/stdout/stderr, sudo can still write to its controlling terminal.
Just because you're running a job in the background does not mean that an interactive shell will not kill it if the job is stopped and you insist on exiting the shell. You need to disown it if you want to exit the shell without killing the job. Of course, in this situation, that won't be of much help.
Yeh, still haven't got to the bottom of it, think I'll sleep on it and see if I can come up with some inspiration...
I have seen some sudo failures in nohup.out where it is prompting for a password. Not sure why as it doesn't from the command line. Seems to write to it when I am trying to exit. Hmmm. Perhaps sudo is buffering......
The chain of events is I call a script I have set up in sudo file to run as root with no password.
That in turn calls another file that has several echos to stdout, (should be redirected?)
That file finally launches a java app. JSystem agent.
I'm not a heavy sudo user, but wouldn't using sudo -b command <input >output 2>err be the right thing to use?
It will prompt for the password and then execute the command asynchronously (i.e. in the background if you think that way) and, in the wee bit of testing I did here, it seems to ignore hangup signals, so you can exit without taking the process down.