Using Mutex Through Processes

OS: Windows Language: C / C ++

The project requires the use of the mutex variable for the process and subprocesses. If I create a mutex in one process, I have to open the mutex in other processes to check the availability of the critical section. To open a mutex, I need to know the name of the mutex created in the parent process. Suppose if I save a mutex as the name of my application. I could find out the name of the mutex as it is fixed. However, if I download a second instance of my application in parallel, there will be confusion.

Could the following idea be better? I have an idea to name the mutex in the parent process as the process identifier. So now I need to get the ID of the parent process from the child process / large child process in order to open the mutex. I think there are no direct ways to get the parent process id from a large child process. Therefore, I have to pass the process identifier in every api creation process (in lpenvironment parm).

Can anyone suggest a simple method, since mutexes are most commonly used .... I'm a newbie.

+3
source share
3 answers

The basic idea is fine, but you can possibly make some improvements to the implementation.

-, , "", , PID . , .

, PID . , , PID. , , . , . Google Chrome.

, , , (GUID, ?) . , - , .

+5

, (PID) , . , , , .

, , PID, PID . ( , , ) fooobar.com/questions/171774/....

, , , - . Windows , , - .

, , , , .

0

" ", "/", , , ( , ). , , , , .

, - , :

#define MUTEXNAME "MzdhYTYzYzc3Mzk4ZDk1NDQ3MzI2MmUxYTAwNTdjMWU2MzJlZGE3Nw"

, , :

php -r "echo substr(base64_encode(sha1('some text')), 0, -2);"

Replace β€œsome text” with your name, current date, or any random words at the moment. The chances that any other application on your system will have the same mutex name is almost zero.

0
source

All Articles