Problems with Win32::Semaphore

use Win32::Semaphore;
$sem = Win32::Semaphore->new(0, 1,"reliance2692") or print "Can't create semaphore\n";
$sem = Win32::Semaphore->open("reliance2692") or print "Can't open semaphore\n";
print "Semaphore:" . $sem . "\n";

By running the above program, I am getting the following output
Can't create semaphore
Can't open semaphore

The output shows that its failed to create a semaphore and even failed to open semaphore.
creating a semaphore might have failed if a semaphore already exists with the given name.
I don't understand why opening a semaphore failed.

Can some clarify the scenario where both creating semaphore & opening semaphore fails.

Are there any permissions with semaphore such that a new semaphore created can be accessed only by certain processes??

Thanks in advance,
Naga Kiran
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What is the output of:
perl -v

I'm unable to duplicate your issue.
use strict;
use warnings;
use Win32::Semaphore;
use Data::Dumper;
my $sem = Win32::Semaphore->new(0, 1,"reliance2692")
        or warn "Can't create semaphore\n";
print "Semaphore:", Dumper $sem;
$sem = Win32::Semaphore->open("reliance2692")
     or warn "Can't open semaphore\n";
print "Semaphore:", Dumper $sem;
Semaphore:$VAR1 = bless( do{\(my $o = 88)}, 'Win32::Semaphore' );
Semaphore:$VAR1 = bless( do{\(my $o = 92)}, 'Win32::Semaphore' );

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nagkiAuthor Commented:
use Win32::Semaphore;
$sem = Win32::Semaphore->new(0, 1,"reliance2692") or print "Can't create semaphore $^E!\n";
$sem = Win32::Semaphore->open("reliance2692") or print "Can't open semaphore $^E!!\n";
print "Semaphore:" . $sem . "\n";

specified semaphore is already created by another perl process [launched from Apache web server]. By printing $^E for both cases creating the semaphore and opening the semaphore,this is the output
Can't create semaphore Access is denied *
Can't open semaphore Access is denied  *
It looks like that both cases creating & opening semaphore failed as semaphore already exists and access is denied.

As this semaphore is created by perl process invoked by Apache process, this access restriction may apply..Is there any way to configure permissions in Apache to make semaphore accessible by all processes?

Your script and Apache will have to be run by the same user (or possibly have the script run as Administrator, but not generally a good idea).  In the httpd.conf file, you can specify the user that Apache will use.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.