LinuxQuestions.org
Visit Jeremy's Blog.
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 05-18-2006, 08:14 AM   #1
rust8y
Member
 
Registered: May 2006
Posts: 100

Rep: Reputation: 15
Run in the background even after logging off


If I execute this command
gzip -f -r * &

would it continue to gzip the files after I disconnect from the vnc linux session?
 
Old 05-18-2006, 08:31 AM   #2
manishsingh4u
Member
 
Registered: Oct 2005
Location: Bhopal, India
Distribution: RHEL 6
Posts: 422

Rep: Reputation: 30
Quote:
Originally Posted by rust8y
would it continue to gzip the files after I disconnect from the vnc linux session?
yes, it will run in background until it finishes its complete execution.
 
Old 05-18-2006, 08:32 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
Why do you use vnc?
Use a X server instead, it is better on all grounds (perf, multiuser collision, CPU usage, memory usage, bandwidth, scalability, monitoring etc...)

Anyway,
if you let the terminal open, the gzip will continue even after you close the vnc session, because there is no link between the vnc session and the gzip command. However, if you close the terminal, which is the parent process, the gzip will terminate.
Use nohup if you want it to continue after the parent terminates.

Last edited by Agrouf; 05-18-2006 at 08:33 AM.
 
Old 05-18-2006, 08:42 AM   #4
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
That's good to know!
Can you bring it back to the foreground after logging in again at a later time?
 
Old 05-18-2006, 08:52 AM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
Quote:
Originally Posted by geeman2.0
That's good to know!
Can you bring it back to the foreground after logging in again at a later time?
There is no such thing as foreground and background.
If you want the output of gzip after you close the terminal, you can't because the standard output of gzip is the terminal. What you can do is redirect the output to somewhere else and check that where you redirected it.
gzip -f -r * 2>&1 >somewhere &

Last edited by Agrouf; 05-18-2006 at 08:59 AM.
 
Old 05-18-2006, 09:07 AM   #6
manishsingh4u
Member
 
Registered: Oct 2005
Location: Bhopal, India
Distribution: RHEL 6
Posts: 422

Rep: Reputation: 30
Quote:
Originally Posted by geeman2.0
Can you bring it back to the foreground after logging in again at a later time?
Yes, you can bring the jobs running in the background to foreground by using this command
Code:
fg
for example
Code:
root@Manish:~# shutdown -h 20:00 &
[1] 7445
root@Manish:~# jobs -l
[1]+  7445 Running                 shutdown -h 20:00 &
root@Manish:~# fg 1
shutdown -h 20:00
See, how shutdown command comes back to the foreground again.
 
Old 05-18-2006, 09:45 AM   #7
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
thanks manishsingh4u for the fg command that I didn't know.
apologies to geeman2.0 for telling you couldn't bring a command to the foreground.
 
Old 05-18-2006, 09:49 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
You can also use the nohup command.

When you log back on, a new shell is created which only knows about the child (job) processes that it has created. You can't re-connect to a child that was launched by another shell, even if that child is still running.

If you want to capture and peruse its output, use the '>', '2>' directives to pipe the stdout/stderr output to a permanent disk file.
 
Old 05-18-2006, 10:02 AM   #9
manishsingh4u
Member
 
Registered: Oct 2005
Location: Bhopal, India
Distribution: RHEL 6
Posts: 422

Rep: Reputation: 30
Quote:
Originally Posted by Agrouf
thanks manishsingh4u for the fg command that I didn't know.
It's your kindness. If you remember, u have helped me many times here.
 
Old 05-18-2006, 11:18 AM   #10
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Rep: Reputation: 45
Quote:
Can you bring it back to the foreground after logging in again at a later time?
I use screen for this. Before running the program in the console, type 'screen' which puts the output to a virtual terminal. To detach the screen and get back to regular console, type 'ctrl+a + ctrl+d'. If you want to reattach the screen to view the output; 'screen -r'. I run a bittorrent client on the console and use this to check the status of it remotely w/ ssh.

regards,
...drkstr
 
Old 05-18-2006, 06:44 PM   #11
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Heh, beat me to the punch. GNU screen is dead sexy, nothing more to be said. If only it'd clean my house....
 
Old 05-18-2006, 06:55 PM   #12
drkstr
Senior Member
 
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191

Rep: Reputation: 45
Quote:
Heh, beat me to the punch. GNU screen is dead sexy, nothing more to be said. If only it'd clean my house....
yours doesn't? You must not have the latest version then.

...drkstr
 
Old 05-19-2006, 06:33 AM   #13
manishsingh4u
Member
 
Registered: Oct 2005
Location: Bhopal, India
Distribution: RHEL 6
Posts: 422

Rep: Reputation: 30
Quote:
Originally Posted by drkstr
I use screen for this. Before running the program in the console, type 'screen' which puts the output to a virtual terminal. To detach the screen and get back to regular console, type 'ctrl+a + ctrl+d'. If you want to reattach the screen to view the output; 'screen -r'. I run a bittorrent client on the console and use this to check the status of it remotely w/ ssh
That's nice. Thanks for the info.
 
Old 05-19-2006, 06:38 AM   #14
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Quote:
Originally Posted by drkstr
I use screen for this. Before running the program in the console, type 'screen' which puts the output to a virtual terminal. To detach the screen and get back to regular console, type 'ctrl+a + ctrl+d'. If you want to reattach the screen to view the output; 'screen -r'. I run a bittorrent client on the console and use this to check the status of it remotely w/ ssh.

regards,
...drkstr
meh, cheers mate,

Wanted something like this for the exact same purpose a little while ago.
 
  


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
Logging From Background shadypalm88 Programming 6 01-20-2015 02:14 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM
Run programs in background... Cybers19 Linux - Newbie 1 06-02-2004 03:54 AM
trouble with background process and logging out successfully isaia Linux - Newbie 3 04-05-2004 12:03 AM
How do I change the background images when logging onto the Xserver? LinuxQuest01 Linux - General 4 06-18-2002 09:22 AM

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

All times are GMT -5. The time now is 08:41 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