LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I keep an executable from terminates after the initiating shell terminates (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-keep-an-executable-from-terminates-after-the-initiating-shell-terminates-521004/)

mr.v. 01-19-2007 06:12 PM

How do I keep an executable from terminates after the initiating shell terminates
 
If I start a program...let's say Firefox, from a terminal window, (even if I place it in the background by executing with an &) and the terminal/shell that called it closes, firefox also closes.

For instance, I want to login to my machine via ssh and start a program running. Then disconnect. The problem is that when the ssh terminates, the shell it gave me also terminates and it takes the program with it. Is there a way to avoid this situation and allow the process to continue despite the loss of the calling shell?

Thanks!

gilead 01-19-2007 06:22 PM

Have a look at the screen and nohup commands - I prefer screen, but it really depends on what type of task you're running. They're more practical for letting long running tasks finish while you're away and capturing the output. I'm not sure why you'd need to run Firefox that way though.

unSpawn 01-19-2007 06:23 PM

AFAIK Firefox requires X, so I'd say VNC. If you are remote you can also use VNC over an SSH tunnel.

bobdevis 01-19-2007 06:39 PM

Use screen.

To start screen, simply type:
>screen

You can start the screen session with a name, so you wont be confused if you use multiple, like this:
>screen -S somename

Now that you are in a screen, start some program, like firefox
>firefox

Now detatch the screen session from the console by pressing 'cntrl+a' and then 'd'.

You can now safely close the console window. The screen session and the program you started with it will run on.

---

To regain acess to the screen session, open up a new console and reattach the screen session:
>screen -r

Or if you used names:
>screen -r somename

you can attach a screen session at multiple consoles. To attach it at a second place, type:
>screen -x somename

----

To see what screen sessions are running, type
>screen -list

---

To end a screen session, simply type
>exit
while you are in the screen session.

raskin 01-19-2007 06:40 PM

As unSpawn said, Firefox will terminate on losing connection to X server - you graphical screen, so you will need something to do with it (probably VNC, but I've had no experience with that). But if you need to do the same thing with a command-line program, you can also use - in modern bash and zsh versions, at least - putting command in background (& at the end of command or Ctrl-Z while it controls the terminal with running 'bg' afterwise to resume it in the background) and running 'disown'.

Surely, screen solution or nohup solution work for console programs.

unSpawn 01-19-2007 06:53 PM

Firefox will terminate on losing connection to X server
Hmm. Got me thinking there. You're probably right he meant terminal in the xterm/Kterm/'whatever the DE provides' sense of the word so backgrounding, as you suggested, should be enough really...

raskin 01-19-2007 07:05 PM

Well, if he really ssh's and closes it with Firefox running, he will probably get it connected to - and later disconnected from - it X server on client machine. Well, I guess exotic (ratpoison?) managers with detach feature are not the case, so window manager and Firefox will both die.

Sepero 01-19-2007 08:11 PM

If you use a terminal often, 'screen' is a life saver.

jlliagre 01-20-2007 02:47 AM

For non interactive programs or non text applications, like firefox, there is a simpler way.
Code:

nohup program </dev/null &
Then you can close the terminal where the program has been launched without killing it.


All times are GMT -5. The time now is 06:15 AM.