Home > Archive > Unix Programming > July 2004 > Semaphore curiosity.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Semaphore curiosity.
|
|
| RJGraham 2004-07-16, 3:58 pm |
| Hello,
Below is 'ipcs' ouput from my linux box (RH9 2.4.x).
How can all the semaphores have the same key?
(running 'ipcrm -S 0' complains that the key is invalid).
I'm developing a C++ app and am having problems running out of
semaphores (ie. semget() returns ENOSPC).
Thanks for your help.
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 229376 rgraham 777 393216 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 141262848 rgraham 666 1
0x00000000 141393924 rgraham 666 1
0x00000000 141426693 rgraham 666 1
0x00000000 141459462 rgraham 666 1
0x00000000 141492231 rgraham 666 1
0x00000000 141525000 rgraham 666 1
0x00000000 141557769 rgraham 666 1
0x00000000 141590538 rgraham 666 1
0x00000000 141623307 rgraham 666 1
0x00000000 141656076 rgraham 666 1
0x00000000 141688845 rgraham 666 1
0x00000000 141721614 rgraham 666 1
0x00000000 141754383 rgraham 666 1
0x00000000 141787152 rgraham 666 1
0x00000000 141819921 rgraham 666 1
0x00000000 141852690 rgraham 666 1
0x00000000 141885459 rgraham 666 1
0x00000000 141918228 rgraham 666 1
0x00000000 141950997 rgraham 666 1
0x00000000 141983766 rgraham 666 1
0x00000000 142016535 rgraham 666 1
0x00000000 142049304 rgraham 666 1
0x00000000 142082073 rgraham 666 1
0x00000000 142114842 rgraham 666 1
0x00000000 142147611 rgraham 666 1
0x00000000 142180380 rgraham 666 1
0x00000000 142213149 rgraham 666 1
0x00000000 142245918 rgraham 666 1
0x00000000 142278687 rgraham 666 1
0x00000000 142311456 rgraham 666 1
0x00000000 142344225 rgraham 666 1
0x00000000 142376994 rgraham 666 1
0x00000000 142409763 rgraham 666 1
0x00000000 142442532 rgraham 666 1
0x00000000 142475301 rgraham 666 1
0x00000000 142508070 rgraham 666 1
0x00000000 142540839 rgraham 666 1
0x00000000 142573608 rgraham 666 1
0x00000000 142606377 rgraham 666 1
0x00000000 142639146 rgraham 666 1
0x00000000 142671915 rgraham 666 1
0x00000000 142704684 rgraham 666 1
0x00000000 142737453 rgraham 666 1
0x00000000 142770222 rgraham 666 1
0x00000000 142802991 rgraham 666 1
0x00000000 142835760 rgraham 666 1
0x00000000 142868529 rgraham 666 1
0x00000000 142901298 rgraham 666 1
0x00000000 142934067 rgraham 666 1
0x00000000 142966836 rgraham 666 1
0x00000000 142999605 rgraham 666 1
0x00000000 143032374 rgraham 666 1
0x00000000 143065143 rgraham 666 1
0x00000000 143097912 rgraham 666 1
0x00000000 143130681 rgraham 666 1
0x00000000 143163450 rgraham 666 1
0x00000000 143196219 rgraham 666 1
0x00000000 143228988 rgraham 666 1
0x00000000 143261757 rgraham 666 1
0x00000000 143294526 rgraham 666 1
0x00000000 143327295 rgraham 666 1
0x00000000 143360064 rgraham 666 1
0x00000000 143392833 rgraham 666 1
0x00000000 143425602 rgraham 666 1
0x00000000 143458371 rgraham 666 1
0x00000000 143491140 rgraham 666 1
0x00000000 143523909 rgraham 666 1
0x00000000 143556678 rgraham 666 1
0x00000000 143589447 rgraham 666 1
0x00000000 143622216 rgraham 666 1
0x00000000 143654985 rgraham 666 1
0x00000000 143687754 rgraham 666 1
0x00000000 143720523 rgraham 666 1
0x00000000 143753292 rgraham 666 1
0x00000000 143786061 rgraham 666 1
0x00000000 143818830 rgraham 666 1
0x00000000 143851599 rgraham 666 1
0x00000000 143884368 rgraham 666 1
0x00000000 143917137 rgraham 666 1
0x00000000 143949906 rgraham 666 1
0x00000000 143982675 rgraham 666 1
0x00000000 144015444 rgraham 666 1
0x00000000 144048213 rgraham 666 1
0x00000000 144080982 rgraham 666 1
0x00000000 144113751 rgraham 666 1
0x00000000 144146520 rgraham 666 1
0x00000000 144179289 rgraham 666 1
0x00000000 144212058 rgraham 666 1
0x00000000 144244827 rgraham 666 1
0x00000000 144277596 rgraham 666 1
0x00000000 144310365 rgraham 666 1
0x00000000 144343134 rgraham 666 1
0x00000000 144375903 rgraham 666 1
0x00000000 144408672 rgraham 666 1
0x00000000 144441441 rgraham 666 1
0x00000000 144474210 rgraham 666 1
0x00000000 144506979 rgraham 666 1
0x00000000 144539748 rgraham 666 1
0x00000000 144572517 rgraham 666 1
0x00000000 144605286 rgraham 666 1
0x00000000 144638055 rgraham 666 1
0x00000000 144670824 rgraham 666 1
0x00000000 144703593 rgraham 666 1
0x00000000 144736362 rgraham 666 1
0x00000000 144769131 rgraham 666 1
0x00000000 144801900 rgraham 666 1
0x00000000 144834669 rgraham 666 1
0x00000000 144867438 rgraham 666 1
0x00000000 144900207 rgraham 666 1
0x00000000 144932976 rgraham 666 1
0x00000000 144965745 rgraham 666 1
0x00000000 144998514 rgraham 666 1
0x00000000 145031283 rgraham 666 1
0x00000000 145064052 rgraham 666 1
0x00000000 145096821 rgraham 666 1
0x00000000 145129590 rgraham 666 1
0x00000000 145162359 rgraham 666 1
0x00000000 145195128 rgraham 666 1
0x00000000 145227897 rgraham 666 1
0x00000000 145260666 rgraham 666 1
0x00000000 145293435 rgraham 666 1
0x00000000 145326204 rgraham 666 1
0x00000000 145358973 rgraham 666 1
0x00000000 145391742 rgraham 666 1
0x00000000 145424511 rgraham 666 1
------ Message Queues --------
key msqid owner perms used-bytes messages
| |
| Jens.Toerring@physik.fu-berlin.de 2004-07-16, 3:58 pm |
| RJGraham <null@null.com> wrote:
> Below is 'ipcs' ouput from my linux box (RH9 2.4.x).
> How can all the semaphores have the same key?
> (running 'ipcrm -S 0' complains that the key is invalid).
> I'm developing a C++ app and am having problems running out of
> semaphores (ie. semget() returns ENOSPC).
> ------ Shared Memory Segments --------
> key shmid owner perms bytes nattch status
> 0x00000000 229376 rgraham 777 393216 2 dest
> ------ Semaphore Arrays --------
> key semid owner perms nsems
> 0x00000000 141262848 rgraham 666 1
> 0x00000000 141393924 rgraham 666 1
> 0x00000000 141426693 rgraham 666 1
No problem there, they were probably created with IPC_PRIVATE - important
is that the semids are all different. If you really need more than the
1024 semaphores that seem to be the default limit on Linux have a look
at the last of the four numbers in /proc/sys/kernel/sem, that's SEMMNI,
i.e. the maximum number of systemwide semaphores and it can be changed
by writing a new set of numbers into that pseudo-file (use echo, not
an editor;-).
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
| RJGraham 2004-07-16, 3:58 pm |
| Jens.Toerring@physik.fu-berlin.de wrote:
> RJGraham <null@null.com> wrote:
>
>
>
>
>
{snip...]
>
> No problem there, they were probably created with IPC_PRIVATE - important
> is that the semids are all different. If you really need more than the
> 1024 semaphores that seem to be the default limit on Linux have a look
> at the last of the four numbers in /proc/sys/kernel/sem, that's SEMMNI,
> i.e. the maximum number of systemwide semaphores and it can be changed
> by writing a new set of numbers into that pseudo-file (use echo, not
> an editor;-).
> Regards, Jens
Thank you very much.
I'd assumed that specifying IPC_PRIVATE would cause a unique key to be
generated as well.
I was surprised to find that the default limit on my box is 128. This
seems too low, so I'll try to increase it using your help above.
Thanks again.
-Randy
| |
| Jens.Toerring@physik.fu-berlin.de 2004-07-16, 3:58 pm |
| RJGraham <null@null.com> wrote:
> I was surprised to find that the default limit on my box is 128. This
> seems too low, so I'll try to increase it using your help above.
Just an update - I just looked on two other machine and there I also
only have 128, so 1024 is obviously not that common as I assumed by
looking only at the machine I am currently sitting at. Now I have to
figure out why it's that large here. "I didn't change anything";-)
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
| Joe Chung 2004-07-16, 8:58 pm |
| Jens.Toerring@physik.fu-berlin.de writes:
> RJGraham <null@null.com> wrote:
>
> Just an update - I just looked on two other machine and there I also
> only have 128, so 1024 is obviously not that common as I assumed by
> looking only at the machine I am currently sitting at. Now I have to
> figure out why it's that large here. "I didn't change anything";-)
Beware that SYSV semaphores are more than they appear.
At the top level are semaphore arrays (or sets), and your system
can have 128 of them by default as you saw.
However, each of these semaphore arrays can have SEMMSL
individual semaphores within it.
On Linux, if you cat /proc/sys/kernel/sem the first number is
SEMMSL and the last number is SEMMNI.
Rarely do you need more than 128 SEMMNI.
What usually happens is that applications that need inter-process
synchronization (this is what SYSV semaphores are for) allocate a
single SEMMNI array and within that array, use the SEMMSL
semaphores. Each semid names one semaphore array.
-jc
--
(apply 'concat (reverse (list "com"
(char-to-string 46) "yahoo"
(char-to-string 64) "joechung")))
| |
| Michael Kerrisk 2004-07-19, 3:57 am |
| On 16 Jul 2004 15:52:42 GMT, Jens.Toerring@physik.fu-berlin.de wrote:
>RJGraham <null@null.com> wrote:
>
>Just an update - I just looked on two other machine and there I also
>only have 128, so 1024 is obviously not that common as I assumed by
>looking only at the machine I am currently sitting at. Now I have to
>figure out why it's that large here. "I didn't change anything";-)
IIRC, I've observed that some distributions change the default values
for these limits, raising them to numbersd higher than in the vanilla
kernel.
Cheers,
Michael
| |
| Jens.Toerring@physik.fu-berlin.de 2004-07-19, 8:56 am |
| Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote:
> On 16 Jul 2004 15:52:42 GMT, Jens.Toerring@physik.fu-berlin.de wrote:
[color=darkred]
> IIRC, I've observed that some distributions change the default values
> for these limits, raising them to numbersd higher than in the vanilla
> kernel.
That would explain it nicely - the ones with 128 are SuSE 8.2 and
Debian, the one with 1024 is SuSE 9.0. Now only remains the question
why they would do that - I would tend to agree with Joe that 128
should be enough in nearly all cases.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
| Michael Kerrisk 2004-07-20, 3:57 am |
| On 19 Jul 2004 08:05:16 GMT, Jens.Toerring@physik.fu-berlin.de wrote:
>Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote:
>
>
>
>That would explain it nicely - the ones with 128 are SuSE 8.2 and
>Debian, the one with 1024 is SuSE 9.0. Now only remains the question
>why they would do that - I would tend to agree with Joe that 128
>should be enough in nearly all cases.
I assume that the reason was that the limit was felt to be too low for
_some_ application(s). But I don't find the rationale for such a
patch sound: it creates a (well yes, rather minor) porting difficulty
between Linux distributions.
SUSE was one of the kernels that I was thinking of -- I knew that on
8.0 the limit was 1024 instead of 128. I have also noticed that in
SUSE 9.1, the limit is once more 128; so perhaps they changed their
minds on this patch.
Cheers,
Michael
|
|
|
|
|