LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-05-2010, 04:46 PM   #1
fdelval
Member
 
Registered: Feb 2010
Posts: 107

Rep: Reputation: 15
everytime i launch a program, i cant use the console anymore...


hello,

My problem is, that everytime i launch a program, like a virtualbox image, the console launch it, but i cant use it anymore.
I use ssh with putty remotely, and the problem is that if i close putty console, the program closes too...

Can i do something to run the program independently of the console? or keep running after i close?

if its possible, how i can i keep track of it when i open console again?
 
Old 12-05-2010, 06:59 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
To be able to use a console again after starting a command you can do two possible things:
1. You can append an ampersand (&) to the command which starts it in the background
2. You can start the command and then hit ^z (ctrl+z) to pause it and then run bg to background it

As for running a program and having it continue after you close the console you can prepend your command with SIGHUP which lets the command ignore a SIGHUP when you log out.

Regards,

Alunduil
 
Old 12-05-2010, 07:06 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
alunduil,

I wonder if you meant to write "nohup" rather than "SIGHUP" ? `nohup` is the command to make applications ignore HUP signals, is it not?

Also, for the OP: If you want to launch an app and totally disown (fully detach) the app from your terminal, bash has the `disown` keyword. A full usage of all the mentioned things might be like:
Code:
$ nohup some_application & disown
Now, the application has been totally detached from the tty it was started from.
 
Old 12-05-2010, 07:16 PM   #4
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
I did thanks for catching that. Don't know what I was thinking.

Regards,

Alunduil
 
Old 12-06-2010, 06:53 AM   #5
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
If you need a console session to be maintained between logins, you can also use the screen program, which creates a virtual console that you can disconnect and connect to at will. Sort of like VNC for the console.
 
Old 12-06-2010, 07:29 AM   #6
fdelval
Member
 
Registered: Feb 2010
Posts: 107

Original Poster
Rep: Reputation: 15
Hello
thank you all

i have a mess betweek &, nohup, disown.

& = background, but when i close terminal, background running and foreground running app's are killed
nohup = ?
disown = detaches app's from console, i can close it


meanwhile, im installing screen.
Looks like i can create as many consoles as i want, and switch between them.
But i cant find a point; can i close the ssh shell where i launched screen?
If the answer is "yes", if a login again, i guess simply by doing "#screen" again, i would be able to regain control of the running apps, right?


thank you for the help, i will wait until clarification to start doing tests.
 
Old 12-06-2010, 08:09 AM   #7
reed9
Member
 
Registered: Jan 2009
Location: Boston, MA
Distribution: Arch Linux
Posts: 653

Rep: Reputation: 142Reputation: 142
Default keybinding to detach a screen session is CTRL-a + d. You can close your ssh session and the detached screen session will continue running. To re-attach do screen -r. If you have multiple screen sessions going that will list available sessions and you would do screen -r <session#>.
 
Old 12-06-2010, 09:13 AM   #8
fdelval
Member
 
Registered: Feb 2010
Posts: 107

Original Poster
Rep: Reputation: 15
wow screen is great!

but i dont want to close the thread without understanding the nohup, &, disown commands.
 
Old 12-06-2010, 09:26 AM   #9
reed9
Member
 
Registered: Jan 2009
Location: Boston, MA
Distribution: Arch Linux
Posts: 653

Rep: Reputation: 142Reputation: 142
nohup = ignore the hangup signal. When you close your terminal session, it sends the hangup signal to running processes to close them. This prevents that.

& = runs the process in the background, free up your console to do other things.

disown = disowns the process from its parent process. nohup makes the process ignore the hangup signal from the get go, disowning a process, AFAIK, prevents the signal from being sent.

http://playingwithsid.blogspot.com/2...-commands.html
 
Old 12-06-2010, 10:19 AM   #10
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
The nohup is simply a script that grabs the SIGHUP handler before starting the command you want to run. The & is a bash language construct that backgrounds the process when it is executed by forking the process before executing it. I'm not familiar with the disown command but will do a little research and report back with anything I find.

Regards,

Alunduil
 
Old 12-06-2010, 11:34 AM   #11
fdelval
Member
 
Registered: Feb 2010
Posts: 107

Original Poster
Rep: Reputation: 15
understood.

Guys, screen is a great trick, looks like there is a trick for every need in linux, and lot of times, we dont know them.

Have you got a web with more useful tricks like that?

other than that, problem solved. thanks.
 
Old 12-06-2010, 11:59 AM   #12
fdelval
Member
 
Registered: Feb 2010
Posts: 107

Original Poster
Rep: Reputation: 15
oh, and by the way,
i have another problem like this in windows CMD console.
I know this is linux world, so i will just whisper lol, but, is there any similar command for windows?
 
  


Reply



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
How can I start a program from tty1 console to be executed in tty2 console? jtag Linux - Software 6 09-10-2010 07:13 PM
How do I launch a prog from console.... SlackN00b Slackware 4 11-03-2005 10:33 AM
My configure menu won't launch anymore nolimitz Linux - Software 2 08-29-2005 09:25 AM
Running a console command everytime login... jdaniel Linux - General 1 11-04-2003 03:11 PM
DNS getting queried everytime I open a program Zil Linux - Networking 5 03-14-2002 02:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:34 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
Open Source Consulting | Domain Registration