Ruby_Baby
(Ruby Baby)
3 February 2004 01:02
1
Shouldn’t a Ruby script keep running if someone uses the “&” at the end of the command?
I have a script that takes hours to run, processing many files, on a remote server.
If I start it like this…
./processFiles.rb
… it will work, but I have to keep an SSH terminal window open for hours.
If I start it like this…
./processFiles.rb &
… and then I close my SSH session to let it run
… it stops immediately after I log out.
Is that expected behavior?
How would I get it to keep running (like my regular /bin/sh shell scripts) after I log out?
I could give example code if someone wants to see it.
Shouldn’t a Ruby script keep running if someone uses the “&” at the end of
the command?
“&” denotes that you are sending a process to the background for execution.
It will only continue to run in the background for that current tty session.
Once you log out of your SSH session it is terminated. To do what you want
you need to run it as a service/daemon or add it to the crontab file.
Is that expected behavior?
Yes
How would I get it to keep running (like my regular /bin/sh shell scripts)
after I log out?
Run it as a service/daemon and/or add it to the crontab file.
HTH,
Zach
···
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com ).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
nohup ./processFiles.rb&
exit
or
ruby -e ‘fork do exec(“./processFiles.rb&”) end’
will make the trick …
ronnie.
Ruby Baby wrote:
···
Shouldn’t a Ruby script keep running if someone uses the “&” at the end of the command?
I have a script that takes hours to run, processing many files, on a remote server.
If I start it like this…
./processFiles.rb
… it will work, but I have to keep an SSH terminal window open for hours.
If I start it like this…
./processFiles.rb &
… and then I close my SSH session to let it run
… it stops immediately after I log out.
Is that expected behavior?
How would I get it to keep running (like my regular /bin/sh shell scripts) after I log out?
I could give example code if someone wants to see it.
Gennady1
(Gennady)
3 February 2004 01:11
4
Ruby Baby wrote:
Shouldn’t a Ruby script keep running if someone uses the “&” at the end of the command?
I have a script that takes hours to run, processing many files, on a remote server.
If I start it like this…
./processFiles.rb
… it will work, but I have to keep an SSH terminal window open for hours.
If I start it like this…
./processFiles.rb &
… and then I close my SSH session to let it run
… it stops immediately after I log out.
try:
trap ‘’ 1
./processFiles.rb >processFiles.log 2>&1 &
or with ‘nohup’, which will do the same for you (redirecting to
nohup.out, though):
nohup ./processFiles.rb &
···
Is that expected behavior?
How would I get it to keep running (like my regular /bin/sh shell scripts) after I log out?
I could give example code if someone wants to see it.
Shouldn’t a Ruby script keep running if someone uses the “&” at the end of
the command?
I have a script that takes hours to run, processing many files, on a remote
server.
If I start it like this…
./processFiles.rb
… it will work, but I have to keep an SSH terminal window open for hours.
If I start it like this…
./processFiles.rb &
… and then I close my SSH session to let it run
… it stops immediately after I log out.
Is that expected behavior?
I’m not sure, but I think no.
How would I get it to keep running (like my regular /bin/sh shell scripts)
after I log out?
Try using the command ‘nohup’.
I could give example code if someone wants to see it.
Good luck!
···
El Martes, 03 de Febrero de 2004 01:02, Ruby Baby escribió:
If I start it like this…
./processFiles.rb
… it will work, but I have to keep an SSH terminal window open for
hours.
If I start it like this…
./processFiles.rb &
… and then I close my SSH session to let it run
… it stops immediately after I log out.
Is that expected behavior?
Yes.
How would I get it to keep running (like my regular /bin/sh shell
scripts) after I log out?
nohup ./processFiles.rb &
-austin
···
On Tue, 3 Feb 2004 10:02:09 +0900, Ruby Baby wrote:
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.05
* 11.33.53
nohup ./processFiles.rb&
exit
I didn’t know this, very cool! Thanks,
Zach
···
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com ).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
— Austin Ziegler austin@halostatue.ca wrote:
How would I get it to keep running (like my regular /bin/sh shell
scripts) after I log out?
nohup ./processFiles.rb &
or:
disown $(jobs -p) && logout
or:
disown %1 && logout
Both’ll work under Bash
– Thomas Adam
···
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net
“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk
nohup is a very handy command… Another very useful utility for this is
called screen. Once you start screen, you’ve basically got a set of
terminals within a terminal & you can even “detach” from screen, log
out, and come back later & reattach to your session. Kind of like
interactive nohup for your entire session. just type ‘screen -R’ to
start it (the -R will reattach if possible, or just create a new one).
Some basic screen commands (each begins with a CTRL+a):
ctrl+a c : new session
ctrl+a 0 … 9 : switch between sessions
ctrl+a ctrl+a : bounce between two sessions
ctrl+a w : list open sessions
ctrl+a d : detach from screen; sessions continue to run, even if you log
out.
when you log back in, start screen with -R to reattach to your session.
man screen for even more cool stuff.
http://www.gnu.org/software/screen/screen.html
Amaze your friends today!
-Ryan
···
On Mon, 2004-02-02 at 20:12, Zach Dennis wrote:
nohup ./processFiles.rb&
exit
How would I get it to keep running (like my regular /bin/sh shell
scripts) after I log out?
nohup ./processFiles.rb &
or:
disown $(jobs -p) && logout
or:
disown %1 && logout
or, using zsh:
./processFiles.rb &!
everybody else was doing it, I felt left out
Hi,
At Fri, 6 Feb 2004 01:41:42 +0900,
Thomas Adam wrote in [ruby-talk:91620]:
disown $(jobs -p) && logout
Just
disown -a
···
–
Nobu Nakada
— Ryan Dlugosz ryan@dlugosz.net wrote:
···
On Mon, 2004-02-02 at 20:12, Zach Dennis wrote:
nohup ./processFiles.rb&
exit
./somefile.rb &
disown %1 && logout
Will achieve the same thing.
– Thomas Adam
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net
“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
BT Yahoo! Broadband - Free modem offer, sign up online today and save £80 http://btyahoo.yahoo.co.uk
I guess I can add that it is a normal behavior. It is not specific to
Ruby in anyway but to UNIX. When the ssh session ends, the controlling
tty of your process disappear and your process gets a SIGHUP, for which
the default behavior is to terminate the process.
Guillaume.
···
Le 3 févr. 04, à 00:11, Thomas Adam a écrit :
— Ryan Dlugosz ryan@dlugosz.net wrote:
On Mon, 2004-02-02 at 20:12, Zach Dennis wrote:
nohup ./processFiles.rb&
exit
./somefile.rb &
disown %1 && logout
Will achieve the same thing.
– Thomas Adam
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net
“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
BT Yahoo! Broadband - Free modem offer, sign up online today and save
£80 http://btyahoo.yahoo.co.uk
Quoteing thomas_adam16@yahoo.com , on Tue, Feb 03, 2004 at 02:11:08PM +0900:
— Ryan Dlugosz ryan@dlugosz.net wrote:
nohup ./processFiles.rb&
exit
./somefile.rb &
disown %1 && logout
Will achieve the same thing.
Under what shell? I’ve never seen “disown”.
Sam
···
On Mon, 2004-02-02 at 20:12, Zach Dennis wrote: