Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!batcomputer!itsgw!steinmetz!uunet!ingr!crossgl From: crossgl@ingr.com (Gordon Cross) Newsgroups: comp.unix.questions Subject: Re: System V message queues? Message-ID: <4043@ingr.com> Date: 22 Feb 89 19:07:37 GMT References: <561@pvab.PVAB.SE> Reply-To: crossgl@ingr.UUCP (Gordon Cross) Organization: Intergraph Corp. Huntsville, Al Lines: 25 In article <561@pvab.PVAB.SE> robert@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@ingr.com mine and not those Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."