LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Put a process in background and logout (https://www.linuxquestions.org/questions/linux-newbie-8/put-a-process-in-background-and-logout-261399/)

esasse 12-01-2004 01:37 PM

Put a process in background and logout
 
When I start a process and then send it to bg using Ctrl+Z, it is stopped, right? To resume I use the bg command, right?

Imagine I'm in a remote ssh session, I start a process and want to send it to bg so that I can logout and leave the process running. How can I do that? And how can I see the results when I login again?

Thanks!

redgren 12-01-2004 02:04 PM

Not sure if this is exactly what you are looking for, but try the 'screen' command.

After I discovered it, I can't live without it.

esasse 12-01-2004 02:39 PM

The "screen" command is not found in my Fedora Core 3 distro and I could not found any references to it. Can you point me?

redgren 12-01-2004 02:42 PM

check out 'rpmfind.net' a valuable resource for any rpm based distro.

screen, just as background, works as a 'virtual shell', i guess. You run screen, it opens up a new shell and continues running that shell until you explicity kill it. You can jump into or out of that shell at any time.

Jerre Cope 12-01-2004 03:06 PM

Another solution would be to use nohup

Ex.

nohup command &

(don't forget the ampersand)

The command will continue when you log out, standard output will go to nohup.out in the directory where you initiated the command.

dsegel 12-01-2004 03:42 PM

Putting an ampersand -&- behind any command makes it immediately go into the background. However, if the command wants to write to it's controlling terminal then it will simply stop until you bring it to the foreground again. Using 'nohup' will let it continue in the background in the absence of a controlling terminal and will also prevent it from exiting when it gets the 'HUP' signal when you log out.

If the command doesn't need to print anything to the terminal then it may just continue to run in the bakground even after you log out without the nohup command; it all depends on what the program does when it receives a 'HUP' signal. Some programs ignore it, some quit.

esasse 12-02-2004 04:36 AM

Ok, so if I forget to use nohup when I started the process I can't logout and leave it running, right?

dsegel 12-02-2004 09:58 PM

It depends on the process. When you logout, all processes are sent a HUP signal, but it's up to the process to decide what to do with it. Some exit, some continue running. Most daemon-type processes simply reload their configuration settings when they receive a HUP.

Also, if you background a process and leave it running on one terminal, you can't bring it forward on another unless you were using the 'screen' app mentioned earlier.

esasse 12-03-2004 05:37 AM

Ok, thanks!

clain 04-15-2011 05:34 PM

I hope my post is as relevant to this thread as I feel it is..

I'm having much the same problem/situation since I also want to get a process running in the background..

I have an Openvpn-process that I've tried to startup as an backgroundprocess.
I want to be able to start it via remote ssh and then logout again.

I've tried to execute the original command with it's required options and then ended it with an ampersand. Although, this command requires input of login & passwd after execution, but when I end the command with an "&" it simply skips this login/passwd part and then the process doesn't start up properly..
:(

If I simply start it by it's usuall command I can't exit the shell and logout since when I do a Ctrl+C it shuts down the process.. :(

Hopefully someone else's been through this who could help me out..


Best Regards
Andreas

starfyredragon 07-13-2011 01:44 AM

If the issue you're having is just not getting a password prompt when you attempt to run the command, there's this nice little property about sudo... it sticks around. If you have to put in a sudo password for a command, your next several sudo commands don't need a password. So just before you run the command, do something like
sudo ls
and that gets you your sudo, you run the sudo nohup [command] & and you're good to go.

bclabots 03-28-2012 02:53 PM

disown
 
Hi just wanted to add this function to the thread for reference.

#start_whatever_process
[CTRL]+[Z]bg
#disown -h
#exit

Bernard


All times are GMT -5. The time now is 07:50 PM.