Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Ubuntu Server 11.10

When a normal (non-root) user starts a process with nohup (nohup java ... &), when the user disconnects from the terminal (ssh) the process stops responding. When the user connects again, the process starts responding again. For example the process is a database (H2) which stops responding queries when the user that started the process disconnects from the terminal, and starts responding again when the user logs in again.

Is there any background process permissions that I'm not aware of that precludes the process from running in background? What could be causing this behaviour?

share|improve this question
    
What do you mean? Once you close the terminal, there is no way to reconnect, which is why you use nohup; so the program keeps running without a terminal. –  psusi Oct 27 '11 at 17:50
1  
I modified the question a bit to try to make it clearer. –  pakman Oct 27 '11 at 17:56

2 Answers 2

nohup should work for you, what was your exact command? Maybe you're missing something. Here's section from wikipedia about it:

Nohupping backgrounded jobs is typically used to avoid terminating them when logging
off from a remote SSH session. A different issue that often arises in this situation
is that ssh is refusing to log off ("hangs"), since it refuses to lose any data
from/to the background job(s).  This problem can also be overcome by redirecting all
three I/O streams:

nohup ./myprogram > foo.out 2> foo.err < /dev/null &

So you could do something like:

ssh -n -f user@remotebox "sh -c 'cd /foo/bar; nohup ./myprogram > foo.out 2> foo.err < /dev/null &'"

Or if that still doesn't work, you can try screen. It will allow you to run your process in the "background", and it will keep running after you logout.

First, ssh over to the remote box, then from there use screen and start your process, and you can give your screen a session name if you want. You won't really notice anything different, but start your process in that session. You can than exit out of the screen session by using the command Ctrl-a d. It will look something like this:

user@remotebox:~$ screen -S foobarsession
user@remotebox:~$ startmyprocess
[detached from 4865.foobarsession]
user@remotebox:~$

You can then exit out of your ssh session, and the process will keep running. To reconnect to the screen session later on, ssh back to the remote box and use screen -r to reconnect. You can use screen -ls to list the sessions.

user@remotebox:~$ screen -ls
There is a screen on:
        4865.foobarsession     (10/05/2012 11:10:57 AM)     (Detached)
1 Socket in /var/run/screen/S-user
user@remotebox:~$ screen -r foobarsession
user@remotebox:~$ screen -ls
        4865.foobarsession     (10/05/2012 11:10:57 AM)     (Attached)
1 Socket in /var/run/screen/S-user
user@remotebox:~$
share|improve this answer
1  
Way to resurrect an old question.. Good second answer ;) Free rep to you. –  SirCharlo Oct 5 '12 at 16:23

Processes started with nohup ... & are designed to run even after the terminal process exits. I don't think there is a core unix mechanism that suspends such processes. Although the scheduler might change its priority (because it might be considered as not-so-important process).

I'm pretty sure, that the process continues to run, but something like a pipe is blocking it and prevents from responding.

share|improve this answer

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.