http://qs1969.pair.com?node_id=11133147

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

Consider the following:
use IPC::Shareable; use IPC::SysV qw(ftok); $ftok = ftok($0); printf("ftok=$ftok (0x%08X)\n", $ftok); $tied = tie %Sess, 'IPC::Shareable', {key => $ftok, mode => 0666, crea +te=>"yes"};

Before executing the above, I do an ipcs -a

It tells me that there are no Semaphore Arrays and only a handful of shared-memory segments.

I invoke the perl-debugger and execute the above code (including the tie).

ftok() gives me 0x01003A83

I now do another ipcs -a ... and now I see:

 Shared-memory-segment with key 0x01003A83 and size 65536 bytes

 Semaphore-array with the same key and 3 semaphores

Question-1: is it normal that a semaphore is created when a shared-memory-segment is set up?

In the debugger, I now do $Sess{abc} = 1

There is no change to what is reported by ipcs -a

However, if I do now $Sess{a}{b}{c}{d}{e} = 1

I now find 4 more 65536 shared-memory-segments created and a load of corresponding semaphores.

Question-2:Does that seem reasonable?

It just seems very curious that the originally created shared-memory segment doesn't simply grow as the data-structure %Sess gets populated

And the %Sess isn't heavily populated, yet I now have five 65536-byte segments, each with it's own semaphore ... very curious?