ipc - Interprocess Mutex In Perl -


I have a Pearl CGI program that executes under mod_perl. Within the program, I would like to stop a resource from reaching many processes at the same time.

  # Semaphore Start Code # 10023 is the unique ID, and this ID different Apache process. # 1, Only one semaphore is being made # 0722, as all the processes will be implemented under the Apache account. Therefore, they will have all '7' privileges with my $ sem = new IPC :: Semaphore (10023, 1, 0722 | IPCCATAT); # Code (1) # 0 set (one and only one) The value of semaphore 1, as I want to use this sequor as a mute x. $ Sem- & gt; Settle (0, 1);  

The problem is:

  1. How can I code (1) to create a new Alexander only when the semaphore 10023 id is ever before Can not be produced by the same process or other processes?
  2. How can I execute the code (2)? For the first time, do I create a CD with the 10023 ID? A semaphore will only be started one time.

Another way is to create an empty file to lock the object. However, it will end up being thousands of temporary files

IPC_XCL flag Adding the underlying semget to either create or fail a new semaphore, you can use it to achieve its desired effect.

This should work for you:

  Try to make # (if not existing) my $ sem = IPC :: semaphore- & gt; New (10023, 1, 0722 | IPC_CREAT | IPC_EXCL); If ($ sem) {#success, semaphore was created, proceed to set up. Print "new semaphore \ n"; $ Sem- & gt; Settle (0, 1); } And (#) print normally "Execute Secure" for the sequence \ n "; $ sem = IPC :: Semaphore-> New (10023, 1, 0722); #No IPC_CREAT die" Semaphore Received Could not? "Until $ sem;}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -