For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > December 2005 > Unsuccessful shmget









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 Unsuccessful shmget
felixfix@gmail.com

2005-12-07, 7:04 pm

Hi all,

I am writing a C program using shared memory.
Here it is how I do that with shmget:

if ((shmid = shmget(0x9131166, 9, 0600)) < 0)
printf("shmget error\n");

When the program runs, I'll get the error message.
If I use IPC_PRIVATE instead of 0x9131166, I do not encounter any
problem. I have to use an agreed upon key as there are several
different process using this portion of shared memory.

Any ideas?

Thanks.
fix.

Barry Margolin

2005-12-08, 3:58 am

In article <1133995619.304594.198090@g14g2000cwa.googlegroups.com>,
felixfix@gmail.com wrote:

> Hi all,
>
> I am writing a C program using shared memory.
> Here it is how I do that with shmget:
>
> if ((shmid = shmget(0x9131166, 9, 0600)) < 0)
> printf("shmget error\n");
>
> When the program runs, I'll get the error message.
> If I use IPC_PRIVATE instead of 0x9131166, I do not encounter any
> problem. I have to use an agreed upon key as there are several
> different process using this portion of shared memory.
>
> Any ideas?


Use perror() instead of printf() so you can find out what error is
occurring.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Nils O. Selåsdal

2005-12-08, 3:58 am

felixfix@gmail.com wrote:
> Hi all,
>
> I am writing a C program using shared memory.
> Here it is how I do that with shmget:
>
> if ((shmid = shmget(0x9131166, 9, 0600)) < 0)
> printf("shmget error\n");
>
> When the program runs, I'll get the error message.
> If I use IPC_PRIVATE instead of 0x9131166, I do not encounter any
> problem. I have to use an agreed upon key as there are several
> different process using this portion of shared memory.

Is the segment already created ? It will only be created
with the IPC_PRIVATE key or if you set IPC_CREAT in the shmflag.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com