How to make a program that, once closed, opens another window?
willowblanket (1)

So, I'm trying to make a program that, once closed, opens another window of itself, so it never stops unless shut down by task manager or unless the computer itself is shut down, of course. This is just to prank a friend, so no maliciousness. I want to to do this in Python, but if there are any other languages that can help me do this more efficiently, please let me know. I'm a beginning programming student, so I kinda need explanations/answers to be simple. Thanks in advance for your help!

You are viewing a single comment. View All
mwilki7 (956)

Something like that is called a watchdog. If the target program dies, the watchdog restarts it. The only way you can stop the target program is to stop both the target and the watchdog.

For python you could try:

print("Watchdog start:")
while True: # run forever
    print("Watchdog: process started")  # program started message
    exec(open("./").read())   # run the program
    print("Watchdog: process finished") # program stopped message
print("Watchdog end:") # the watchdog is now finishing

import time

for i in range (0, 5):
print("I done")

For C/C++ you could look into forking/exec and poll the system for the process ID and just fork/exec it again if it dies.

KelvinVerhey (43)

@mwilki7 not a good idea to introduce fork bombs etc. servers were taken down with such silly antics.

mwilki7 (956)

@KelvinVerhey only if you write code that fork bombs