Windows 下创建互斥运行的进程

来源:互联网 发布:怎么在淘宝上找旗舰店 编辑:程序博客网 时间:2024/06/07 12:27
windows下程序互斥运行方式。
#include <Windows.h>void process_exclusively_running(void){    HANDLE hMutex = NULL;    char* lpszName = "ProcessMutex_1";    hMutex = CreateMutexA(NULL,FALSE,lpszName);    DWORD dwRet=GetLastError();    if(hMutex)    {        if(ERROR_ALREADY_EXISTS == dwRet)        {                        cout<<"already running"<<endl;            CloseHandle(hMutex);            return ;        }    }    }
通过系统范围的锁,即可实现windows下进程的互斥运行。

0 0