loop a program on exit?

M

Michael Linfield

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

any ideas?
 
J

John Joyce

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

any ideas?
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.
 
L

Lloyd Linklater

Michael said:
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."
 
T

Tim Pease

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

any ideas?

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
 
R

RubyTalk

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
 
M

Michael Linfield

John said:
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 :(

at_exit {exec "ruby", $0, *ARGS}
thanks Tim Pease ill look into that
END{
code
}

i will give that a shot as well
 
R

Robert Klemme

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 :(


thanks Tim Pease ill look into that


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
 
T

Tim Pease

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
 
R

Robert Klemme

2007/9/18 said:
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. ;-)
But clever, nonetheless.

Thanks!

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top