shmget() and EINVAL
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > shmget() and EINVAL




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    shmget() and EINVAL  
Nithya Venkatachalam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-04 04:16 PM

Hi,

test_shmid = shmget(key,0,(SHM_R|SHM_W|IPC_CREAT));
If i specify like this,
And if the shared memory segment corresponding to the key specified
already exists,
Will the errno corresponding to shmget() failure be set to EINVAL
????






[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Michael Kerrisk


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-04 04:16 PM

On 15 Sep 2004 23:54:09 -0700, "Nithya  Venkatachalam"
<vnithya@gmail.com> wrote:

>Hi,
>
>test_shmid = shmget(key,0,(SHM_R|SHM_W|IPC_CREAT));
>If i specify like this,
>And if the shared memory segment corresponding to the key specified
>already exists,
>Will the errno corresponding to shmget() failure be set to EINVAL
>????

Did you read the man page?  You need IPC_EXCL.

By the way, (size == 0) with IPC_CREAT is strange.

Cheers,

Michael





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Robert Clark


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

Michael Kerrisk wrote:

> On 15 Sep 2004 23:54:09 -0700, "Nithya  Venkatachalam"
> <vnithya@gmail.com> wrote:
> 
>
> By the way, (size == 0) with IPC_CREAT is strange.

Just adding a couple of cents of my own, if you run this on a system with
the shared memory minimum size set to 1 (the usual default) or larger, this
will also fail with errno set to EINVAL.

Just ran across this kind of thing with a customer. They had their Solaris
kernel set so that the minimum shared memory size (SHMMIN) was 200 bytes.
My code tried to allocate less that that. Made for a very interesting error
to try and track down.

Which reminds me, anyone know how to figure out (at runtime) the value of
SHMMIN and SHMMAX on any of the common Unix/Linux systems? I did a bit of
googling around and found the /etc/system file on Solaris
and /proc/sys/kernel/* on Linux. Anyone know about AIX or HP-UX?

- Rob

--
(to email me, remove "warez.")





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Juha Laiho


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

Robert Clark <clark@warez.exiter.com> said:
>Which reminds me, anyone know how to figure out (at runtime) the value of
>SHMMIN and SHMMAX on any of the common Unix/Linux systems? I did a bit of
>googling around and found the /etc/system file on Solaris
>and /proc/sys/kernel/* on Linux. Anyone know about AIX or HP-UX?

The last I worked with HP-UX, the kernel parameters were easiest to
configure using their 'sam' configuration tool. There's also a file (in
/usr/conf/master.d, IIRC) you can change, but direct changes to the file
may be overwritten by subsequent runs of 'sam'.

For AIX, I'd see if it's doable using the 'smit' tool.
--
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Robert J. Clark


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

Juha Laiho wrote:
> Robert Clark <clark@warez.exiter.com> said: 
>
> The last I worked with HP-UX, the kernel parameters were easiest to
> configure using their 'sam' configuration tool. There's also a file (in
> /usr/conf/master.d, IIRC) you can change, but direct changes to the file
> may be overwritten by subsequent runs of 'sam'.
>
> For AIX, I'd see if it's doable using the 'smit' tool.

I have to plead temporary insanity. I was using smit this morning and
never even thought to check. Thanks for the suggestions, I appreciate it.

- Rob





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Jonathan Adams


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

Robert Clark <clark@warez.exiter.com> wrote:
> Michael Kerrisk wrote:
>
> Just ran across this kind of thing with a customer. They had their Solaris
> kernel set so that the minimum shared memory size (SHMMIN) was 200 bytes.
> My code tried to allocate less that that. Made for a very interesting erro
r
> to try and track down.

Note that in Solaris 10, SHMMIN has been removed, partially because it
makes absolutely no sense.

> Which reminds me, anyone know how to figure out (at runtime) the value of
> SHMMIN and SHMMAX on any of the common Unix/Linux systems? I did a bit of
> googling around and found the /etc/system file on Solaris
> and /proc/sys/kernel/* on Linux. Anyone know about AIX or HP-UX?

In Solaris 10, this is different -- there's a pair of per-project RCTLS:

project.max-shm-memory  maximum size (SHMMAX)
project.max-shm-ids     maximum # of SysV shm ids

prctl(1) and getrctl(2) can be used to retrieve the current values of
them.  (not that reading /etc/system is a particularly great way to get
them in pre-S10 days)

- jonathan





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Robert Clark


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

Jonathan Adams wrote:

> Robert Clark <clark@warez.exiter.com> wrote: 
>
> Note that in Solaris 10, SHMMIN has been removed, partially because it
> makes absolutely no sense.

Ain't that the truth. I could not get a strait answer from our customer as
to why they though they needed this.

> 
>
> In Solaris 10, this is different -- there's a pair of per-project RCTLS:
>
>         project.max-shm-memory  maximum size (SHMMAX)
>         project.max-shm-ids     maximum # of SysV shm ids
>
> prctl(1) and getrctl(2) can be used to retrieve the current values of
> them.

That one goes into my tips and tricks file. Thanks.

> (not that reading /etc/system is a particularly great way to get
> them in pre-S10 days)

I'm not terribly thrilled about it either. Do you know of any other ways to
get the values for Solaris 2.6-9 ? I have a feeling that we will have to
support those for quite a while.

Thanks,
Rob

--
(to email me, remove "warez.")





[ Post a follow-up to this message ]



    Re: shmget() and EINVAL  
Jonathan Adams


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-04 02:21 AM

In article <1512291.XWtyWrSfCr@warez.exiter.com>,
Robert Clark <clark@warez.exiter.com> wrote:

> Jonathan Adams wrote:
> 
>
> Ain't that the truth. I could not get a strait answer from our customer as
> to why they though they needed this.

They probably picked it up from some website.

> That one goes into my tips and tricks file. Thanks.
> 
>
> I'm not terribly thrilled about it either. Do you know of any other ways t
o
> get the values for Solaris 2.6-9 ? I have a feeling that we will have to
> support those for quite a while.

I believe many people parse the output of /usr/sbin/sysdef -- this is
better than reading /etc/system (it's at least got the current numbers,
if the modules are loaded).  Still not fantastic, but it's the best
available, AFAIK.

Cheers,
- jonathan





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:40 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register