Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

shmget() and EINVAL
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
????


Report this thread to moderator Post Follow-up to this message
Old Post
Nithya Venkatachalam
09-16-04 10:01 AM


Re: shmget() and EINVAL
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

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Kerrisk
09-16-04 10:01 AM


Re: shmget() and EINVAL
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.")

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Clark
09-17-04 09:03 AM


Re: shmget() and EINVAL
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)

Report this thread to moderator Post Follow-up to this message
Old Post
Juha Laiho
09-18-04 02:00 AM


Re: shmget() and EINVAL
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

Report this thread to moderator Post Follow-up to this message
Old Post
Robert J. Clark
09-18-04 08:57 AM


Re: shmget() and EINVAL
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

Report this thread to moderator Post Follow-up to this message
Old Post
Jonathan Adams
09-18-04 01:56 PM


Re: shmget() and EINVAL
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.")

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Clark
09-19-04 08:56 AM


Re: shmget() and EINVAL
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

Report this thread to moderator Post Follow-up to this message
Old Post
Jonathan Adams
09-19-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.