nohup problem

Hi All

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?

Thanks

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.

Regards,
Alister

Hi Alister

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.

Regards,
Alister

run it via an at job.

echo "sudo /home/brad/spideroak/jsystem/runner/runAgent >~/runAgent.out 2>~/runAgent.err" | at now

Hi Alister

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... :slight_smile:

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.

My sudo entry is currently: -

brad ALL = (root) NOPASSWD: /usr/bin/nohup /home/brad/spideroak/jsystem/runner/runAgent > ~/runAgent.out 2> ~/runAgent.err < /dev/null &

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.

Hi frank

Tried it and got this: -

/home/brad > cat runAgent.err
sudo: no tty present and no askpass program specified

make the sudo rule less complex.

put "/usr/bin/nohup /home/brad/spideroak/jsystem/runner/runAgent > /home/brad/runAgent.out 2> /home/brad/runAgent.err < /dev/null &"

into a script
and make the sudo rule look like this

brad ALL = (root) NOPASSWD: /usr/local/bin/foo.ksh

also for security reasons I suggest putting the binaries into a root owned location and also would not write root output to your home directory.

Hi

Well I tried -b and -n but both still killed the job when I exited: -

/home/brad/spideroak/jsystem/runner > sudo -n /usr/bin/nohup /home/brad/spideroak/jsystem/runner/runAgent </dev/null >~/runAgent.out 2>~/runAgent.err &
[1]     2425
/home/brad/spideroak/jsystem/runner > (PRESSED ENTER KEY HERE)
[1] +  Done(1)                 sudo -n /usr/bin/nohup /home/brad/spideroak/jsystem/runner/runAgent </dev/null >~/runAgent.out 2>~/runAgent.err &
/home/brad/spideroak/jsystem/runner > (CONTROL D HERE)
/home/brad/spideroak/jsystem/runner > You have stopped jobs
/home/brad/spideroak/jsystem/runner > exit

I set the sudo entry as: -

brad ALL = (root) NOPASSWD: /usr/bin/nohup /home/brad/spideroak/jsystem/runner/runAgent </dev/null >~/runAgent.out 2>~/runAgent.err &

---------- Post updated at 09:04 PM ---------- Previous update was at 08:52 PM ----------

Thanks Frank

That did the job.

Will tidy it up tomorrow and implement your security suggestions.

:b: