View Single Post

   
  #1 (permalink)  
Old 03-20-2008, 01:42 PM
Alex Vinokur
 
Posts: n/a
Default Detect if a segment existes in sharred memoty

> uname -smrsv
HP-UX B.11.23 U ia64


Here are two functions to detect if some segment exists in shared
memory.


bool shmSegmentExists(key_t key)
{
if ((shmget(key, 0, myFlags | IPC_CREAT | IPC_EXCL) == -1)
{
if (errno == EEXIST)
{
return true;
}
}

return false;
}

bool shmSegmentIsAbsent(key_t key)
{
assert (!(myFlags & IPC_CREAT));
if ((shmget(key, 0, myFlags) == -1)
{
if (errno == ENOENT)
{
return true;
}
}

return false;
}


--------------------------

1. Are those functions valid?

2. If the functions are indeed valid, is this always true:
assert (shmSegmentExists(key) == !shmSegmentIsAbsent (key));
?


Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

?
Reply With Quote