开发者

How many copies of console applications already launched

I have a开发者_如何学Python console application, written on C. Inside this application, I want to determine how many copies of the console application are already launched. Thank you.


I found this googling. It involves some knowledge (not much) of IPC. This works only for Windows. In unix this can be done in a similar manner by using the corresponding unix IPC.

LATER EDIT: Found also this. It counts the number of processes having a given process name (Windows only).


One way is to access your operating system's process list and count how many occurrences of the executable appear. But that could be fooled by multiple copies of the executable with different names.

To make sure you count all occurrences regardless of executable name, you could create a global shared memory object (protected with synchronized access, of course) where each instance registers its process ID. Then you can parse that list and validate against the OS process ID list in case any of the instances died before unregistering themselves.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜