Pregunta

I am currently writing a program that works on both Linux and Windows and uses the GLib library. When the program is run by the user I would like to make sure that there is only one instance of the program that is allowed to be running. How can I do this in a platform agnostic manner that also does not have any race conditions?

I know GIO has an Application class that uses DBus to handle this, but I am uncertain if this is portable to the Windows environment, or my wine testing environment.

¿Fue útil?

Solución

the GApplication class uses GDBus, which reliably works on Linux, *BSD, Windows, and MacOS X.

on Windows, the first connection to the session bus using the GDBus API will result in a new process spawning a GDBusDaemon instance; the address for the newly created session bus will be stored inside a named mutex, and all new processes requiring that mutex will be able to connect to the same session bus. this way it's possible to reuse the same mechanism of acquiring a name on the session bus on all platforms.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top