[ILUG] OT : Semaphore Key creation
Bryan O'Donoghue
bryano at europlex.ie
Thu Mar 11 11:02:22 GMT 2004
ftok(), if I'm not mistaken, does *not* gaurantee, a unique key for the
likes of semget();
What is the accepted methodology/wisdom for generating unique sem/shm keys?
Even something like
int a;
srand(time*getpid());
a=rand();
if(a<0)
a*=-1;
key_t key=(key_t)a;
semget(key,1,0666 | whatever);
Has the potential for key collision if I'm not wrong.
Is there some sort of function I can call, which will list keys in use
and from which I can then disjoin key id's against?
More to the point, if I do an "ipcs" and get.
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 557059 beths 600 393216 2 dest
0x00000000 589828 root 600 4331 0
All with the same key, my thinking is it dones't really matter 'what'
the key is, so long as the semid/shmid is unique... but I could be wrong.
I'm a bit confused here Batman, shouldn't the key be unique and not just
the sem/shm id?
--
Bryan O'Donoghue
Embedded Software Engineer
Europlex Technologies Ltd
Clonshaugh Business & Technology Park
Dublin 17
Ireland
T:+353 (0) 1 2500500
F:+353 (0) 1 2500590
E:bryano at euoplex.ie
W:www.europlex.ie
More information about the ILUG
mailing list