Loop a program on exit?

i want to have a program restart when its closed via the X button on the
window / terminal

any ideas?

Michael L. wrote:

i want to have a program restart when its closed via the X button on the
window / terminal

any ideas?

A program cannot restart itself after it is closed down. I suggest a
parent program that runs the one that you want to have running. Then,
when the child program ends, the parent can restart it.

Caveat: Make sure that there is a way to end it. You do not want it to
turn into a “never-ending story.”

On Sep 16, 2007, at 12:51 AM, Michael L. wrote:

i want to have a program restart when its closed via the X button
on the
window / terminal

any ideas?

Posted via http://www.ruby-forum.com/.

You’re going into very platform specific territory there. Potentially
malware like behavior.
Normally, the paradigm a user expects is that a GUI widget functions
the same as in other applications. If all you want is to have an
application not quit via that GUI widget, disable that widget, and
visually gray it out.
If you want a restart button, make one.
Don’t break expected behaviors like that.
If you want a daemon process, you probably don’t want it running in a
GUI.

END{
code
}

“Declares code to be called at the end of the program (when the
interpreter quits).”

Ruby In A Nutshell: page 29.

I do have the first edition so could have changed.

SbeckerIV

On 9/15/07, Michael L. [email protected] wrote:

i want to have a program restart when its closed via the X button on the
window / terminal

any ideas?

Posted via http://www.ruby-forum.com/.

at_exit {exec “ruby”, $0, *ARGS}

Should work on all platforms, but you will not get the original flags
to the ruby interpreter. You should register a signal handler to trap
SIGKILL or SIGTERM and do an exit! from the handler. This will prevent
the at_exit blocks from running.

Blessings,
TwP

John J. wrote:

You’re going into very platform specific territory there. Potentially
malware like behavior.

this is true, i do see how it could be seen as malware behavior and i
should probably stay away from that. Its purpose is to make sure the
user cannot exit while its running its given functions, if they were to
do this, it could cause some serious problems :frowning:

at_exit {exec “ruby”, $0, *ARGS}
thanks Tim P. ill look into that

END{
code
}

i will give that a shot as well

On 17.09.2007 22:12, Michael L. wrote:

at_exit {exec “ruby”, $0, *ARGS}
thanks Tim P. ill look into that

END{
code
}

i will give that a shot as well

Here’s another mechanism:

loop do
Process.waitpid( fork do
# your program goes here
end )
end

Kind regards

robert

Potentially
thanks Tim P. ill look into that

END{
code
}

i will give that a shot as well

Posted via http://www.ruby-forum.com/.

Maybe treat the whole thing as a service and look into daemon
supervisors,
there are several solutions out there. One somewhat popular one are
djb’s
daemontools (http://cr.yp.to/daemontools.html), though his
software/licensing in general has been subject to some controversy.

Then the supervisor monitors when your application closes (or a shell
script
that starts a terminal that then automatically runs your application)
and
respawns another instance. Entirely outside Ruby, and I’d expect many
platforms to have specific implementations you could use.

HTH,

FElix

On 9/17/07, Robert K. [email protected] wrote:

Here’s another mechanism:

loop do
Process.waitpid( fork do
# your program goes here
end )
end

Windows is the fork nazi … “No fork for you!”

But clever, nonetheless.

Blessings,
TwP

2007/9/18, Tim P. [email protected]:

Windows is the fork nazi … “No fork for you!”

$ ruby <<XXX

3.times do |i|
Process.waitpid( fork { sleep 1; puts i } )
end
XXX
0
1
2

$ uname -a
CYGWIN_NT-5.1 padrklemme1 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin

Now someone will be telling me that I’m cheating again. :wink:

But clever, nonetheless.

Thanks!

Kind regards

robert

2007/9/18, Robert K. [email protected]:

Windows is the fork nazi … “No fork for you!”

PS: since the OP mentioned X I figured he might not be on X anyway. :-))

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs