English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 16 December 2019, 09:41   #1
Honitos
Registered User
 
Honitos's Avatar
 
Join Date: Nov 2019
Location: Celle / Germany
Posts: 145
How to check if a Task is already running?

I want to check, if my program has been started before to prevent another instance by double clicking the icon again by mistake.


I cannot use FindTask() as it will always find itself, so I cannot find the other task that MAY be started before.
Honitos is offline  
Old 16 December 2019, 09:58   #2
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
AttemptSemaphore?
deimos is offline  
Old 16 December 2019, 11:24   #3
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 3,303
Check if program message port is open or not maybe?
daxb is offline  
Old 16 December 2019, 11:47   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
I check with
jsr (_LVOFindPort,a6)
if there is already a named port, possibly added with a precedent
jsr (_LVOAddPort,a6)
.

There are probably better methods but this works, in every kickstart, and is very simple.
ross is offline  
Old 23 December 2019, 08:22   #5
BastyCDGS
Registered User
 
Join Date: Nov 2015
Location: Freiburg / Germany
Age: 44
Posts: 200
Send a message via ICQ to BastyCDGS
Another possibility is to Lock() your program's executable with exclusive access mode straight after start.

This way you get a meaningful error message via IoErr() (202: object is busy), if it's opened again.
However, there is a caveat, if your program crashes, the lock might remain open forever, so prepare special cleanup code for this.

The FindPort solution is nice, too, but you should be careful about name collisions with other applications running.

And beware of race conditions occuring by both methods! Always sempahore protect such code!
BastyCDGS is offline  
Old 28 February 2020, 10:30   #6
Wilsom1992
Registered User
 
Join Date: Feb 2020
Location: Munich/Germany
Posts: 2
Quote:
Originally Posted by BastyCDGS View Post
Another possibility is to Lock() your program's executable with exclusive access mode straight after start.

This way you get a meaningful error message via IoErr() (202: object is busy), if it's opened again.
However, there is a caveat, if your program crashes, the lock might remain open forever, so prepare special cleanup code for this.

The FindPort solution is nice, too, but you should be careful about name collisions with other applications running.

And beware of race conditions occuring by both methods! Always sempahore protect such code!
wanted to advice the same.
Wilsom1992 is offline  
Old 29 February 2020, 21:05   #7
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Ia the port introduces race conditions, and has to be protected with a semaphore, then wouldn't it make more sense to use AttemptSemaphore already mentioned by deimos?

After all you will need a semaphore anyway, and this is a exactly the purpose this is for.
sparhawk is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
pc task 4.4:) 8bitbob support.Apps 42 25 August 2023 19:29
PC Task 4.4 Jimbo request.Apps 61 25 February 2023 05:56
Once again PC Task! lurkist request.Apps 58 04 July 2022 23:16
Simple way to check that the game is running on a CD32? earok Coders. Blitz Basic 11 18 September 2017 15:19
PC-Task DyLucke request.Apps 18 06 February 2010 21:52

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:29.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09782 seconds with 15 queries