System V message queues?

Gordon Cross crossgl at ingr.com
Thu Feb 23 05:07:37 AEST 1989


In article <561 at pvab.PVAB.SE> robert at PVAB.SE (Robert Claeson) writes:
>
>Now, the first process creates a message queue with a parameter of
>IPC_PRIVATE to msgget() before it starts the second process. But how
>do I pass the queue id to the new process?

IPC_PRIVATE causes the creation of a message queue that is meant to be used
exclusively by the process that created it.  The correct way to use message
queues for interprocess communication is to create it using a value for
'key' that is known (or can be determined) by the other processes that wish
to use the queue.  There is a function 'ftok' available that can be used to
generate such a key.  It requires the path name of an existing file and an
unique id (the manual suggests that this id should uniquely identify a
project).  My personal opinion of 'ftok' is UGHHHH!  I usually just pick
some random number and use that as the key then we register this number so
no other project will use the same one.  Another method I've seen used before
is to use the PID of the master (controlling) process as the key but this
method presents problems in situations where (a) there isn't any real "master"
process or its PID is not known to all and (b) PIDs roll-over often.  Hope
this helps!!
-- 

Gordon Cross             UUCP:      uunet!ingr!crossgl     "all opinions are
111 Westminister Way     INTERNET:  crossgl at ingr.com        mine and not those
Madison, AL 35758        MA BELL:   (205) 772-7842          of my employer."



More information about the Comp.unix.questions mailing list