LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Run in the background even after logging off (https://www.linuxquestions.org/questions/linux-newbie-8/run-in-the-background-even-after-logging-off-446043/)

rust8y 05-18-2006 08:14 AM

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?

manishsingh4u 05-18-2006 08:31 AM

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.

Agrouf 05-18-2006 08:32 AM

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.

geeman2.0 05-18-2006 08:42 AM

That's good to know!
Can you bring it back to the foreground after logging in again at a later time?

Agrouf 05-18-2006 08:52 AM

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 &

manishsingh4u 05-18-2006 09:07 AM

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.

Agrouf 05-18-2006 09:45 AM

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.

sundialsvcs 05-18-2006 09:49 AM

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.

manishsingh4u 05-18-2006 10:02 AM

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.

drkstr 05-18-2006 11:18 AM

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

cs-cam 05-18-2006 06:44 PM

Heh, beat me to the punch. GNU screen is dead sexy, nothing more to be said. If only it'd clean my house....

drkstr 05-18-2006 06:55 PM

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

manishsingh4u 05-19-2006 06:33 AM

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.

ethics 05-19-2006 06:38 AM

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.


All times are GMT -5. The time now is 03:24 PM.