m5@lynx.uucp (Mike McNally) (03/03/90)
I have recently discovered that message queues with a key of IPC_PRIVATE are not implicitly removed when all using tasks exit. In other words, if my program does: my_private_q = msgget(IPC_PRIVATE, IPC_CREAT | 0666); and then has fun sending messages to itself and its offspring until dying a timely death, the queue will remain in the system. Of course, because the IPC_PRIVATE key was used, by definition no other process will ever be able to "open" the queue in the future. I realize that it would be "nice" to do a msgctl() to get rid of the thing, but it seems a little user-hostile for the kernel to not do this automatically. Is any purpose served by keeping the queue around? (I found this out, BTW, on our Interactive Systems 386 system.) -- Mike McNally Lynx Real-Time Systems uucp: {voder,athsys}!lynx!m5 phone: 408 370 2233 Where equal mind and contest equal, go.
cpcahil@virtech.uucp (Conor P. Cahill) (03/04/90)
In article <7114@lynx.UUCP> m5@lynx.uucp (Mike McNally) writes: > [ story of how kernel does not delete unused message queues deleted] >Of course, because the >IPC_PRIVATE key was used, by definition no other process will ever be able >to "open" the queue in the future. This is not true. As long as someone has saved, or has access to the message id, the queue can be re-used by any process. This is the same for all of the System V IPCs. None of them will be removed without an explicit remove operation (via the *ctl()). Shared memory is a special case where the remove will not take place until there are no longer any processes attached to the segment. That way you can create the segment, attach to it, and then call the remove. Once your program exits, the segment will go away. >I realize that it would be "nice" to do a msgctl() to get rid of the thing, >but it seems a little user-hostile for the kernel to not do this automatically. >Is any purpose served by keeping the queue around? Maybe, maybe not. It depends upon the application, but I am glad that the kernel doesn't force the issue. If it had forced the issue, you (or somebody else) would be complaining that there is no way to keep the queue around. This way you get to make the choice. -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170
rice@dg-rtp.dg.com (Brian Rice) (03/04/90)
In article <7114@lynx.UUCP>, m5@lynx.uucp (Mike McNally) writes: > I have recently discovered that message queues with a key of IPC_PRIVATE are > not implicitly removed when all using tasks exit. > Is any purpose served by keeping the queue around? Remember that a "private" message queue is not so private that only one process group can use it: in fact, any process which knows the queue's id (as originally returned by msgget()) may read or write from the queue if the queue's access permissions are satisfied. The source of confusion here, I think, is that msgget() does not somehow declare that a process is using a queue; it serves basically two functions: to create a new message queue and to look up the id of a queue if all you know is the key. If I know that somebody else has created a queue whose id is 17, then I don't need to use msgget() at all. I can immediately do a msgsnd(17,...), for instance...even if the queue was created with IPC_PRIVATE. All IPC_PRIVATE does is to block another process's looking up your queue's key. A process may distribute a message queue id at will--it may even store it in a file for use by another process next Wednesday. For this reason, implicitly killing message queues not "in use" would make the message queue facility less useful. (It's also not clear that, given these facts about message queues, one can coherently define when a queue is unused--but that's a whole 'nother bucket of borscht.) Brian Rice rice@dg-rtp.dg.com (919) 248-6328 DG/UX Product Assurance Engineering Data General Corp., Research Triangle Park, N.C. "My other car is an AViiON."
john@chinet.chi.il.us (John Mundt) (03/06/90)
In article <7114@lynx.UUCP> m5@lynx.uucp (Mike McNally) writes: >I have recently discovered that message queues with a key of IPC_PRIVATE are >not implicitly removed when all using tasks exit. > ... >I realize that it would be "nice" to do a msgctl() to get rid of the thing, >but it seems a little user-hostile for the kernel to not do this automatically. >Is any purpose served by keeping the queue around? > >(I found this out, BTW, on our Interactive Systems 386 system.) > You'll find the same thing on AT&T's 3b2 line using V3.2. I carefully remove the queue when a user exits, but when the program was in develop- ment, and crashed several times, the queue stayed there. :-( It would be nice if the kernel did clean up after a process died. -- --------------------- John Mundt Teachers' Aide, Inc. P.O. Box 1666 Highland Park, IL john@admctr.chi.il.us *OR* fred@teacha.chi.il.us (312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem