- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shmget returns EINVAL
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 04:02 AM
тАО04-22-2004 04:02 AM
It works fine until the server recreates the shared memory segment. Then shmget returns an error with errno = EINVAL. If I then restart the program, it will work until the next night when the server recreates the shared memory segment. Since the shared memory key doesn't change and I call shmget every time to get the memory ID, I don't understand why I can't attach to the new shared memory segment.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 04:09 AM
тАО04-22-2004 04:09 AM
Re: shmget returns EINVAL
Couple of things.
1) If shmdt() is called then the process must do another shmat() before the next shmget().
2) From the shmat() man page:
[EINVAL] shmid is not a valid shared memory identifier,
(possibly because the shared memory segment was
already removed using shmctl(2) with IPC_RMID), or
the calling process is already attached to shmid.
[EINVAL] shmaddr is not zero and the machine does not
permit nonzero values, or shmaddr is not equal to
the current attach location for the shared memory
segment.
So again the most likely cause is the process is detaching from the segment & then trying to access it w/o reattaching.
May need to trace the process with tusc to validate this.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 04:18 AM
тАО04-22-2004 04:18 AM
Re: shmget returns EINVAL
Why in the world is the segment being recreated in the first place? How is this being done? Sounds to me like you'll just have to restart the process every time the segment is broken down & recreated.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 04:51 AM
тАО04-22-2004 04:51 AM
Re: shmget returns EINVAL
Of course, there is an inherent danger to your use of shared memory and that is synchronization. Even your quick shmget,shmat,shmdt calls on the client could fall at the wrong time.
Probably the best way to handle this is not to recreate the shared memory segment each time. The server process should only create the shared memory segment when the shmid does not already exist. If it exists, let it update the existing data. That way, you could let your client processes remain attached and the problem goes away. You would need to add a bit of flag data toi indicate that yes the server is still running and store this in the segment. It would probably be a good idea to add a semaphore for synchronization issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 05:08 AM
тАО04-22-2004 05:08 AM
Re: shmget returns EINVAL
The shared memory segment is created once a day at midnight by the server. (I don't have access to the server code so I don't know how it is being done.) I access the shared memory sement every 10 seconds all day by doing a shmget(), shmat() and shmdt() sequence. Immediately after midnight I start getting the error return from shmget(). I tried sleeping for 10 seconds before calling shmget again (and repeating for an hour) but I always get the EINVAL return from shmget.
So far, my only option has been to kill the client process and restart it after midnight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 05:19 AM
тАО04-22-2004 05:19 AM
Re: shmget returns EINVAL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 07:01 AM
тАО04-22-2004 07:01 AM
Re: shmget returns EINVAL
I read the shared memory key out of a database table. Here are the calls to shmget() shmat() and shmdt().
After the three calls I've included the function that calls them and after the function is the error message generated.
Thanks for your help!
Galen
******************************************
adhere_id = shmget(rtaSession()->memory_id,
rtaSession()->record_count * sizeof(ADHERE), SHM_R)
adhrec = (ADHERE *) shmat(adhere_id, 0,0)
shmdt((void *)adhrec);
*****************************************
#define MAXSHMERRS 3
/* Acesses the shared memory region containing the current SWITCH agent info */
int getAgentsState(char *Switch, AGENT aInfo[])
{
ADHERE *adhrec;
int adhere_id;
int i;
int shmErrs = 0;
char *fmtdate(char *);
/*rtaDebug("Entered getAgentsState ...", __FILE__, __LINE__);*/
shmErrs = 0;
while((adhere_id = shmget(rtaSession()->memory_id,
rtaSession()->record_count * sizeof(ADHERE), SHM_R)) == -1)
{
if(++shmErrs > MAXSHMERRS)
{
char buf[1024];
sprintf(buf, "ERROR: Can't access shared memory.\n"
" shared memory key = 0x%08x\n"
" record count = %d\n"
" error count = %d\n"
" errno = %d\n",
rtaSession()->memory_id,
rtaSession()->record_count, shmErrs, errno);
sleep(60);
rtaExit(rtaSession()->socket, buf, NULL,
__FILE__, __LINE__);
}
sleep(shmErrs*2);
}
/* Get the pointer to shared memory */
shmErrs = 0;
while ((int)( adhrec = (ADHERE *) shmat(adhere_id, 0,0)) == -1)
{
if(++shmErrs > MAXSHMERRS)
{
char buf[1024];
sprintf(buf, "ERROR: Can't attach to shared memory.\n"
" shared memory key = %d\n"
" record count = %d\n"
" error count = %d\n"
" errno = %d\n",
rtaSession()->memory_id,
rtaSession()->record_count, shmErrs, errno);
rtaLog(buf, __FILE__, __LINE__);
/* If we just exit, TotalView will immediately send */
/* another login request, so we'll sleep awhile to */
/* keep the logfile from growing too fast */
sleep (60);
rtaExit(rtaSession()->socket, buf, NULL,
__FILE__, __LINE__);
}
sleep(shmErrs*2);
}
for (i=0; i < rtaSession()->record_count; i++)
{
bzero(aInfo[i], sizeof(AGENT));
sprintf(aInfo[i].agentId, "%d", adhrec[i].login_id);
strcpy(aInfo[i].agentState, adhrec[i].dn1_state);
sprintf(aInfo[i].timeStamp, "%s|%s",
adhrec[i].cur_hms, (char *)fmtdate(adhrec[i].cur_date));
}
shmdt((void *)adhrec);
return (i);
}
******************************************
PID: 27303 PPID: 24538 04222004.000127: File: agent.c Line: 160
DN4DCD: 04222004.000127: ERROR: Can't access shared memory.
shared memory key = 0x000003f2
record count = 718
error count = 4
errno = 22
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 07:11 AM
тАО04-22-2004 07:11 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 07:35 AM
тАО04-22-2004 07:35 AM
Re: shmget returns EINVAL
I'll try it this weekend.
Galen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 08:24 AM
тАО04-22-2004 08:24 AM