Search code examples
c++execution

Detect double execution of app C++


Is there any way to stop a double execution of an application in C++ so only one instance of the application is running at once?


Edit: Windows 7


Solution

  • There is no way to do it in the C++ standard. What you need is to use a mechanism provided by the underlying platform. For example, here is how you would do it on Windows.

    Here is how you might do it on Mac OS X. As you can see, the approaches can be different and depends on what you want.

    It boils down to checking if your application is running and then exiting if it is.

    Here are a few more ways to check if your application is running on Windows (the code is in a different language, but the concepts are the same)