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?
FishMongerConnect With a Mentor Commented:
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

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?

Adam314Connect With a Mentor Commented:
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.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.