简体   繁体   English

linux下的qt,如何检测一个进程已经在运行?

[英]Qt under linux, how to detect a process is already running?

I am developing under ubuntu 16.04. 我正在Ubuntu 16.04下开发。 The issue I run into is: I want to detect whether the user has already started the application, if yes, it exits directly. 我遇到的问题是:我想检测用户是否已经启动了该应用程序,如果是,则直接退出。

I have tried using QLocalServer , QSharedMemory to achieve that. 我尝试使用QLocalServerQSharedMemory来实现这一点。 But the problem is: 但是问题是:

If the program crash without properly close the local server or destroy the shared memory , the local socket/shared memory will remain in the OS and prevent the user to launch the program again. 如果程序崩溃而没有正确关闭本地服务器或破坏共享内存 ,则本地套接字/共享内存保留在操作系统中,并阻止用户再次启动程序。

How to deal with this? 该如何处理?

For the shared memory issue you could take a look at this question QSharedMemory is not getting deleted on Application crash 对于共享内存问题,您可以看一下此问题QSharedMemory不会在应用程序崩溃时被删除

For a more generic answer about having a single instance of an application, you can take a look at Qt Single Application which is part of qt-solutions 有关具有单个应用程序实例的更通用答案,请查看qt-solutions的一部分Qt Single Application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM