且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查是否有其他正在运行的应用程序实例

更新时间:2022-11-06 17:47:15

有没有简单的方法来知道一个程序的实例运行在同一个二进制文件的一些机器上 - 你需要计划在哪里比它可以以某种方式报道我跑到一些共享位置检查是否有其他正在运行的实例。

There is no easy way to know that instance of a program runs on some machine from the same binaries - you program need to somehow report "I'm running" to some shared location where than it can check if there are other instances running.

如果你只需要检查单个实例它可能会打开从同一位置的文件,它会失败,如果多个对于共享位置情况下,尝试打开它。

If you only need to check for single instance it may be possible to open a file from the same location and it will fail if multiple instances try to open it.

夫妻选项来计算实例:


  • 与计算机的名称更新一些文件

  • 某些Web服务/网站来ping

  • 共享DB

请注意,这也意味着,如果程序死亡有可能无法在大约完成此特定实例共享位置报告

Note that it also means if program dies there may not be report in the shared location about this particular instance finished.