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

Hi,

I have a simple script to test variable sharing between two perl processes,

use IPC::Shareable; $robj = {status=>'init'}; tie $robj->{status}, 'IPC::Shareable', 'data_glue', {create => 1, mode => 664, destroy => 1}; $pid = fork(); unless(defined $pid){ print "Error durigng fork\n"; } if($pid){ $robj->{parent=>'parent'}; }else{ tie $robj->{status}, 'IPC::Shareable', 'data_glue', {create => 0, mode => 664, destroy => 0}; $robj->{status} = 'updated'; sleep(5); exit(0); } print "\n", $robj->{status}, "\n";

When i run i get following error.

IPC::Shareable::SharedMem: shmget: Permission denied at /usr/lib/perl5/site_perl/5.8.3/IPC/Shareable.pm line 566 Could not create shared memory segment: at test_ipc_shareable.pl line 3

Problem: I get above error when run as user account other than 'root' . But the script used to work before, but started throwing this error, after server where this script runs was down due to storage corruption. I am getting this error after server came online. I am using perl v5.8.3 and IPC::Shareable v0.60. I tried reinstalling the package, using cpan shell, force make IPC::Shareable', but the unfortunately 'test IPC::Shareable' fails.

Does any one know how to resolve this? Because running as 'root' creates other problems for my main scripts.

Thanks in advance,
katharnakh

Replies are listed 'Best First'.
Re: IPC::Shareable::SharedMem: shmget: Permission denied
by tilly (Archbishop) on Jan 16, 2009 at 08:04 UTC
    My guess is that after the reboot the shared memory segment was somehow created by root and not cleaned up. Now when you try to run the scripts as anything else, they try to access the existing one and fail to have permission because that segment is owned by root. And when you run it as root it doesn't clean it up because it didn't create it.

    Try running it once by root with the following line at the end:

    (tied $robj->{status})->remove();
    If that doesn't clear things up, my guess is wrong. At that point you need help from someone who understands Unix system administration better than I do. :-(
      Thanks, the solution worked out.
      katharnakh
      Hi,
      After doing so like as above said, it worked for me when tried as 'root' and 'cbsrepl' users. But again for some reason, it started again throwing the same error.
      I tried once by having only two lines, just to check whether i can delete previously created one,
      use IPC::Shareable; tie $robj->{status}, 'IPC::Shareable', 'data_glue', {create => 0, mode + => 664, destroy => 0}; (tied $robj->{status})->remove();
      but after this there was nothing printed on the screen, as there is nothing to print. Then i checked
      > ipcs -ma ------ Shared Memory Segments -------- key shmid owner perms bytes nattch stat +us 0x61746164 16187392 root 230 65536 0 ------ Semaphore Arrays -------- key semid owner perms nsems 0x61746164 15630336 root 230 3 ------ Message Queues -------- key msqid owner perms used-bytes messages 0x00001f58 0 root 600 0 0
      But still, it looks something remains even after having (tied $robj->{status})->remove();. May be because of this am i getting the error again? If so, how can delete this and take measures to create once again and delete once done?
      Thanks in advance,
      katharnakh.
        At a guess, one time the program ran and the job was killed unexpectedly before it did its cleanup.

        If that is the case the best solution is probably to clean it up again as root, then run as "cbsrepl" and deliberately leave the memory segment there. Now it will work as cbsrepl and root indefinitely as long as nobody cleans up the existing memory segment. (But you'll need to deal with this when the machine next reboots, talk to your sysadmin about setting up an init script to create the memory segment as cbsrepl to avoid it next time.)

Re: IPC::Shareable::SharedMem: shmget: Permission denied
by mje (Curate) on Jan 16, 2009 at 10:37 UTC

    In addition to the other comments you can probably run something like

    ipcs -ma

    to find out what shared memory exists and who owns it. The command might be slightly different depending on your operating system. I'd guess your shared memory already exists belonging to someone else.

Re: IPC::Shareable::SharedMem: shmget: Permission denied
by Corion (Patriarch) on Jan 16, 2009 at 08:01 UTC

    Ask your server administrator what changed. This seems to be a permissions issue, which you can only debug together with your machine administrator or somebody else who knows the operating system very well.