rmv has asked for the wisdom of the Perl Monks concerning the following question:

I have found the CPAN code for semaphores i.e semaphore.pm. I am a novice to Perl and would like to get the last semaphore id through GETPID of semctl when I give a semaphore id as input.

Please help me write this snippet which extracts the last pid give a semaphore id in Perl.

  • Comment on Get Semaphore info using CPAN semaphore.pm

Replies are listed 'Best First'.
Re: Get Semaphore info using CPAN semaphore.pm
by ww (Archbishop) on Sep 05, 2009 at 11:42 UTC
    1. Read http://perldoc.perl.org/Thread/Semaphore.html
    2. Write code
    3. Test, noting any failures, errors, etc
    4. Update OP with info from above

    We can offer better help (and speed your learning process) when you, yourself, try to work out your problem.

      I donot have root access on our system. And I got the below error. Please let me know how I can work with semaphores without installing any thing.

      perl Semphore_try.pl Can't locate Thread/Semaphore.pm in @INC (@INC contains: /usr/perl5/5. +8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/ +5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_p +erl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor +_perl/5.8.4 /usr/perl5/vendor_perl .) at Semphore_try.pl line 1. BEGIN failed--compilation aborted at Semphore_try.pl line 1.

      I have the source code of semaphore.pm . May be I need to try using it directly from IPC , instead of using threaded ones. Please guide me .

        try...
        1. Installing the CPAN library (and any missing dependencies) into a directory you can write to e.g. somewhere in your home directory, most easily achieved by using perl -MCPAN -e shell and then install semaphore
        2. Modify $PERL5LIB or %PERL5LIB% to point to the installation directory
        3. Re-run your script
        A user level that continues to overstate my experience :-))