Re: shmget() returning EINVAL for constant size and flags
Re: shmget() returning EINVAL for constant size and flags
- Subject: Re: shmget() returning EINVAL for constant size and flags
- From: rohan a <email@hidden>
- Date: Sat, 5 Dec 2009 20:00:44 +0530
Hi,
I do not think the key is invalid because shmget() with the same key
has succeeded several times.
Is it possible to use another key if either EEXIST or EINVAL is
returned or should I necessarily have to check using shmctl() if
another process is using that key ?
Thanks,
Rohan
On Sat, Dec 5, 2009 at 11:53 AM, Tyler Sample <email@hidden> wrote:
> EINVAL is also returned if your key is entirely invalid. Double check that
> before your function call.
>
> If that's not the problem, if the shmget call fails, you can try making
> another call with the size set to 0, then make sure that call succeeds. Then
> you can use shmctl to find out about the memory....In particular, you can
> print the size. If it's something reasonable, you probably have a duplicate
> key with another process.
>
>
>
>
>
> ----- Original Message ----- From: "rohan a" <email@hidden>
> To: <email@hidden>
> Sent: Friday, December 04, 2009 9:30 PM
> Subject: shmget() returning EINVAL for constant size and flags
>
>
>> Hello All,
>> I am using shmget() to allocate shared memory in my backup/restore
>> utility.
>>
>> int shmget(key_t key, size_t size, int shmflg);
>>
>> The size and shmflg I am passing are always constant. If shmget()
>> returns EEXIST I try again with another key until shared memory is
>> allocated.
>>
>> On some occasions, shmget() fails and I am getting an EINVAL error.
>> I dont think the arguments are invalid because, I am using constant
>> values for size and shmflg for every call and most of the calls are
>> successful.
>>
>> The Man page says this for EINVAL :
>>
>> [EINVAL] No shared memory segment is to be created, and a
>> shared memory segment exists for
>> key, but the size of the segment associated
>> with it is less than size, which is non-zero. nonzero.
>> zero.
>>
>> However, with every shmget() call, I use the same size 524288 and same
>> flags with different key ofcourse.
>>
>> Then why should I get an EINVAL ?
>>
>> Is it possible that another application is allocating shared memory
>> using this key but a size lesser than 524288 ?
>>
>> Along with checking EEXIST for existence of a memory location with
>> this key should I also check for EINVAL ?
>> That is if EINVAL is returned, should I try to allocate with another key ?
>>
>> Thanks,
>> Rohan
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Darwin-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden