|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
wolf
Joined: 02 Jul 2012 Posts: 11
|
Posted: Mon Mar 14, 2016 11:33 am Post subject: How to check if a program is running |
|
|
I need to detect if another program is running or not from within a F95 application.
From within a F95 program (P1) I start a second process (P2) and continue P1. (I use Start_PProcess to start P2). Before P1 starts P2 a second time P1 must wait until P2 finished.
Any idea how to do that?
Thanks in advance. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Mon Mar 14, 2016 10:38 pm Post subject: |
|
|
There will be a good way to do this but if you are happy with a cheap and nasty approach then just create a file in the process that is terminating and check if the file has been created in the process that is waiting. But while waiting make sure that you don't use up the cpu by calling sleep1@ in the waiting loop.
A more refined way is to use START_THREAD@ and WAIT_FOR_THREAD@. These are defined in cwplus.enh, the clearwin+ enhancements file.
There are other ways that may be better still. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Thu Mar 17, 2016 2:10 pm Post subject: |
|
|
Assume your 2 processes were both written in FTN95.
In the main window creation for P2, set it's process name and a callback function thus:
Code: | IA=WINIO@('%nc[P2_process_name]%rm&',MESSAGE_FN) |
The code to launch P2 needs to look something like:
Code: | INTEGER FUNCTION LaunchP2_FN()
C -------------------------------
C
C Launch P2.exe
C
C -----------------------------------------------------------------
INTEGER START_PPROCESS@, SEND_TEXT_MESSAGE@
CHARACTER*(25) REPLY
INCLUDE <WINDOWS.INS>
C ------------------------------------------------------------------
IA = SEND_TEXT_MESSAGE@('P2_process_name','RUNNING',REPLY)
IF (REPLY .NE. 'YES') THEN
IA = START_PPROCESS@('P2.EXE',' ')
IF (IA .NE. 0) write(*,*) 'Did not start P2'
ENDIF
LaunchP2_FN = 1
END |
The callback in P2 looks like this:
Code: | INTEGER FUNCTION MESSAGE_FN()
C -----------------------------
C
CHARACTER*(255) MESSAGE
INCLUDE <WINDOWS.INS>
MESSAGE = CLEARWIN_STRING@('MESSAGE_TEXT')
IF (MESSAGE .EQ. 'CLOSE') THEN
MESSAGE_FN = 0
RETURN
ELSE IF (MESSAGE .EQ. 'RUNNING') THEN
CALL REPLY_TO_TEXT_MESSAGE@('YES')
ENDIF
MESSAGE_FN = 1
RETURN
END |
Essentially, P1 sends the message 'RUNNING' to P2. If there is no reply, then P2 can be started. If there is an answer, it will be 'YES', in which case do not start P2 at all, because it is already running. P1 can also send the message 'CLOSE' (using SEND_TEXT_MESSAGE@), in which case P2 should shut itself down. In that case, the reply specified in the SEND_TEXT_MESSAGE@ call might just as well be ignored.
Be sure to read all about Windows messaging in FTN95.CHM.
Eddie |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|