How to detect if the program already is running?

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 122
Joined: Thu May 02, 2019 11:53 am

How to detect if the program already is running?

Post by amyren »

Is there a way to check if the program is running, to avoid the possibility of starting two copies of the program?

I found this discussed in an old feature request, but I couldnt find if it have been adressed yet.
viewtopic.php?p=15375

User avatar
jPV
Posts: 365
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How to detect if the program already is running?

Post by jPV »

If you're making your program only for Amiga compatibles, ARexx is quite handy for that.

You could do something like this:

Code: Select all

rexxport = "MYTESTPROGRAM"
err = ?CreateRexxPort(rexxport)
If err = #ERR_PORTNOTAVAIL
    DebugPrint("Program is already running.")
    ; You could send updated information to the running instance for example like this:
    ; SendRexxCommand(rexxport, "OPEN '" .. GetFileArgument() .. "'")
    End
EndIf
WaitLeftMouse()

amyren
Posts: 122
Joined: Thu May 02, 2019 11:53 am

Re: How to detect if the program already is running?

Post by amyren »

Thanks for the reply.
Actually I was looking for a solution that will work on windows too.

I have a workaround plan in case Hollywood dont have an internal way to detect it.
Just let the program create a file at startup, and then delete the file when quitting. Then check if this file exists on every startup.
The weakness of this plan is in case of a forced quit or a crash, the file will not be deleted. But at least I could use it to bring up a warning.

User avatar
airsoftsoftwair
Posts: 4394
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to detect if the program already is running?

Post by airsoftsoftwair »

amyren wrote:
Wed Aug 12, 2020 12:14 pm
Thanks for the reply.
Actually I was looking for a solution that will work on windows too.
Just use CreatePort() instead of CreateRexxPort() for a platform-independent solution.

amyren
Posts: 122
Joined: Thu May 02, 2019 11:53 am

Re: How to detect if the program already is running?

Post by amyren »

Thanks.
CreatePort() works for me, even without actually using the port to send anything.
The first copy of the program creates the port, then double-starting the next program will throw an error when it tries to create a port that already exists.
So I now just set ExitOnError(false) and make my own error handler to give a warning message to the user before ending the second copy of the program.

amyren
Posts: 122
Joined: Thu May 02, 2019 11:53 am

Re: How to detect if the program already is running?

Post by amyren »

I recently tried to run a program on LinuxArm on raspberry pi, and found that using CreatePort() to detect if the program is already running will not work. CreatePort() will produce an error regardless if the program is running or not.

Post Reply