<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Check if process is already started in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768569#M21401</link>
    <description>[bash]!   create a mutex to block multiple invocations
CALL SetLastError(0)  !Just in case
ghMutex = CreateMutex(NULL_SECURITY_ATTRIBUTES, FALSE, "YourMutex"C)
IF (GetLastError() ==  ERROR_ALREADY_EXISTS) THEN
    rval = MessageBox (ghwndMain,                   &amp;amp;
                       "Program already running"C,   &amp;amp;
                       "Error"C, MB_OK              )
    WinMain = 0
    RETURN
END IF
[/bash]</description>
    <pubDate>Tue, 24 Apr 2012 17:33:14 GMT</pubDate>
    <dc:creator>Paul_Curtis</dc:creator>
    <dc:date>2012-04-24T17:33:14Z</dc:date>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768564#M21396</link>
      <description>Hi there,&lt;BR /&gt;&lt;BR /&gt;Im programming a client in a client server solution.&lt;BR /&gt;&lt;BR /&gt;My problem is, when I start a second instance of my client, the server crashes.&lt;BR /&gt;&lt;BR /&gt;Is there a possibility to check if an instance of the client process is already running so I could prevent a second instance?&lt;BR /&gt;&lt;BR /&gt;Im using Windows7 and XE Update 9.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Markus</description>
      <pubDate>Tue, 24 Apr 2012 11:07:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768564#M21396</guid>
      <dc:creator>onkelhotte</dc:creator>
      <dc:date>2012-04-24T11:07:41Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768565#M21397</link>
      <description>One simple way is to create a named Mutex and try to "acquire" the Mutex at the beginning of the program. If it fails, then another copy of the client is running and you should exit. The Windows API routines for mutexes are straightfoward.</description>
      <pubDate>Tue, 24 Apr 2012 13:52:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768565#M21397</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-04-24T13:52:56Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768566#M21398</link>
      <description>Steve, you made me curious. Could you give us an example of Fortran code for creating and accessing a named Mutex? I was not able to locate something usable at Microsoft's databases.</description>
      <pubDate>Tue, 24 Apr 2012 15:01:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768566#M21398</guid>
      <dc:creator>rase</dc:creator>
      <dc:date>2012-04-24T15:01:30Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768567#M21399</link>
      <description>Look at the DLL\DLL_Shared_Data sample included with the product. It does this.</description>
      <pubDate>Tue, 24 Apr 2012 15:35:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768567#M21399</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-04-24T15:35:54Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768568#M21400</link>
      <description>Thanks for the hint, Steve. It's indeed simpler than I expected.&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Apr 2012 15:56:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768568#M21400</guid>
      <dc:creator>rase</dc:creator>
      <dc:date>2012-04-24T15:56:47Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768569#M21401</link>
      <description>[bash]!   create a mutex to block multiple invocations
CALL SetLastError(0)  !Just in case
ghMutex = CreateMutex(NULL_SECURITY_ATTRIBUTES, FALSE, "YourMutex"C)
IF (GetLastError() ==  ERROR_ALREADY_EXISTS) THEN
    rval = MessageBox (ghwndMain,                   &amp;amp;
                       "Program already running"C,   &amp;amp;
                       "Error"C, MB_OK              )
    WinMain = 0
    RETURN
END IF
[/bash]</description>
      <pubDate>Tue, 24 Apr 2012 17:33:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768569#M21401</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2012-04-24T17:33:14Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768570#M21402</link>
      <description>Yes, that should work. When the creator exits, the mutex gets deleted automatically. MSDN offers this caution, though:&lt;BR /&gt;&lt;BR /&gt;If you are using a named mutex to limit your application to a single 
instance, a malicious user can create this mutex before you do and 
prevent your application from starting. To prevent this situation, 
create a randomly named mutex and store the name so that it can only be 
obtained by an authorized user. Alternatively, you can use a file for 
this purpose. To limit your application to one instance per user, create
 a locked file in the user's profile directory.&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Apr 2012 17:52:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768570#M21402</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-04-24T17:52:30Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768571#M21403</link>
      <description>It does work, perfectly. And, as long as that mutex is in existence, it can be used for other coding tasks as well.&lt;BR /&gt;&lt;BR /&gt;Your malicious user scenario seems a bit far-fetched; such a malefactor would have to be quite clever and industrious, and a programmer as well, and for what purpose? And the (pre)existence of the duplicate mutex would be easily found with ProcessExplorer or similar.</description>
      <pubDate>Tue, 24 Apr 2012 18:30:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768571#M21403</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2012-04-24T18:30:09Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768572#M21404</link>
      <description>It's not my scenario, I just quoted what MSDN said. It is a useful point to think about - while it may not apply in this case, it might in others. At the very least one should be aware of the limitations in using a mutex for this purpose</description>
      <pubDate>Tue, 24 Apr 2012 18:58:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768572#M21404</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-04-24T18:58:06Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768573#M21405</link>
      <description>Depending on the details and requirements for the "client/server" arrangement (particularly if the "server" will ever run as a Windows service) the name of the Mutex may also need to explicitly be in the global namespace.&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Apr 2012 01:32:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768573#M21405</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-04-25T01:32:35Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768574#M21406</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;That tips is very helpful. Is it sure that the mutex is destroyed even if the process crashes?</description>
      <pubDate>Wed, 25 Apr 2012 07:57:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768574#M21406</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2012-04-25T07:57:10Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768575#M21407</link>
      <description>Thanks Paul for the code, I altered it a little bit so it runs in my QuickWin program:&lt;BR /&gt;&lt;BR /&gt;[bash]
    subroutine checkSingleInstance(MutexName)&lt;BR /&gt;
&lt;BR /&gt;    use ifwin
    use ifqwin
    
    implicit none
    
    integer(kind=4) hMutex
    character*(*) MutexName
    logical(kind=4) l
    
    !   create a mutex to block multiple invocations
    call SetLastError(0)  !Just in case
    hMutex = CreateMutex(NULL, .false., MutexName)
    if (GetLastError() ==  ERROR_ALREADY_EXISTS) then
        l = MessageBoxQQ ( &amp;amp;
            'Process '//MutexName//' is already running.'//char(10)//char(10)// &amp;amp;
            'The program will not start.'//char(0), &amp;amp;
            'Error'//char(0), MB$OK.or.MB$ICONSTOP)
        stop
    end if

    end subroutine checkSingleInstance[/bash]It works as it should (for my purpose). When I kill the first process via Task Manager, I can start another "first" instance.&lt;BR /&gt;&lt;BR /&gt;Btw, I get an run-time error "fort: (7): Attempt to use pointer NULL_SECURITY_ATTRIBUTES when it is not associated with a target", so I changed it to NULL.&lt;BR /&gt;&lt;BR /&gt;Markus</description>
      <pubDate>Wed, 25 Apr 2012 08:45:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768575#M21407</guid>
      <dc:creator>onkelhotte</dc:creator>
      <dc:date>2012-04-25T08:45:22Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768576#M21408</link>
      <description>The 2nd argument for CreateMutex is the Win32 constant &lt;B&gt;FALSE&lt;/B&gt;, which is &lt;I&gt;not the same&lt;/I&gt; as the Fortran boolean &lt;B&gt;.&lt;/B&gt;FALSE&lt;B&gt;.&lt;/B&gt;</description>
      <pubDate>Wed, 25 Apr 2012 11:00:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768576#M21408</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2012-04-25T11:00:13Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768577#M21409</link>
      <description>Well, it will be the same value, but it would be more correct to use FALSE here.&lt;BR /&gt;&lt;BR /&gt;Microsoft says that the mutex will be destroyed when the last handle to it is closed, and exiting a process closes all handles.</description>
      <pubDate>Wed, 25 Apr 2012 16:25:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768577#M21409</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-04-25T16:25:12Z</dc:date>
    </item>
    <item>
      <title>Check if process is already started</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768578#M21410</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1335649389781="58" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=90977" href="https://community.intel.com/en-us/profile/90977/" class="basic"&gt;onkelhotte&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;...&lt;I&gt;&lt;BR /&gt;Is there a possibility to check if an instance of the client process is already running so I could prevent a second instance?&lt;BR /&gt;...&lt;/I&gt;&lt;/DIV&gt;&lt;BR /&gt;It can be done in a very simple way:&lt;BR /&gt;&lt;BR /&gt;If your &lt;STRONG&gt;Client&lt;/STRONG&gt; application has some title than a call to a &lt;STRONG&gt;Win32 API&lt;/STRONG&gt; function &lt;STRONG&gt;FindWindow&lt;/STRONG&gt;(..."title"...) or &lt;STRONG&gt;FindWindowEx&lt;/STRONG&gt;(..."title"...)&lt;BR /&gt;will return some &lt;STRONG&gt;HWND&lt;/STRONG&gt; value if the &lt;STRONG&gt;Client&lt;/STRONG&gt; is already started.&lt;BR /&gt;&lt;BR /&gt;I used that method many times because it is simple.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Sergey&lt;/DIV&gt;</description>
      <pubDate>Sat, 28 Apr 2012 21:52:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Check-if-process-is-already-started/m-p/768578#M21410</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2012-04-28T21:52:36Z</dc:date>
    </item>
  </channel>
</rss>

