LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2007, 07:12 PM   #1
mr.v.
Member
 
Registered: Jun 2006
Distribution: Slackware 11
Posts: 56

Rep: Reputation: 15
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!

Last edited by mr.v.; 01-19-2007 at 07:18 PM.
 
Old 01-19-2007, 07:22 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
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.

Last edited by gilead; 01-19-2007 at 07:23 PM.
 
Old 01-19-2007, 07:23 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
AFAIK Firefox requires X, so I'd say VNC. If you are remote you can also use VNC over an SSH tunnel.
 
Old 01-19-2007, 07:39 PM   #4
bobdevis
Member
 
Registered: Nov 2006
Distribution: Ubuntu 64bit
Posts: 49

Rep: Reputation: 15
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.

Last edited by bobdevis; 01-19-2007 at 07:51 PM.
 
Old 01-19-2007, 07:40 PM   #5
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
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.

Last edited by raskin; 01-19-2007 at 07:50 PM.
 
Old 01-19-2007, 07:53 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
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...
 
Old 01-19-2007, 08:05 PM   #7
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
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.
 
Old 01-19-2007, 09:11 PM   #8
Sepero
Member
 
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 32
If you use a terminal often, 'screen' is a life saver.
 
Old 01-20-2007, 03:47 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,652

Rep: Reputation: 393Reputation: 393Reputation: 393Reputation: 393
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script terminates as zombie, ie, <defunct> Kropotkin Linux - Newbie 3 02-20-2007 01:15 AM
valgrind terminates unexpectedly appas Linux - General 0 02-18-2005 03:30 AM
why program terminates? manojg Linux - General 6 06-07-2004 05:08 PM
Fetchmail terminates with signal 15 teeka Linux - Networking 0 05-19-2004 12:12 PM
Netscape 6 Terminates!! islandkid Linux - General 5 05-04-2002 03:14 PM


All times are GMT -5. The time now is 08:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration