tags:

views:

194

answers:

2

I'm learning Unix IPC, and my book only talks about the msg* family of functions. However while browsing the man pages I learned about the mq_ equivalents. http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi/0650/bks/SGI%5FDeveloper/books/T%5FIRIX%5FProg/sgi%5Fhtml/ch06.html describes some differences between the two, but I'm not sure how much of that is implementation-specific. Are there any compelling reasons to use one family over the other? Is either one "better" than the other?

+1  A: 

The mq_* functions are the POSIX functions. The msg* functions are from what is generally known as 'System V IPC' (because they are part of the IPC facility introduced with UNIX System V that included shared memory and semaphores too). I think it is fair to say that the msg* functions are included in the POSIX and X/Open standard more because of backwards compatibility than for being otherwise desirable; that may be doing them an injustice, but normally standards try to avoid multiple ways of achieving the same result. They were neither of them in the original versions of POSIX.

You need to consider where you will port your code. I'd would suggest using the more modern mq_* functions if they are available everywhere you need to go - though I haven't used them myself. Generally speaking, the msg* functions were less frequently used than the shared memory and semaphore functions, but that interface has been around (a decade or more) longer than the POSIX one, so it might be more widely available.

Jonathan Leffler
Wow, so msg* functions aren't POSIX? My book calls them "POSIX:XSI" message queues...
Steven
I think that's called re-branding. ;)
Duck
They _are_ in POSIX - they did not originate with POSIX (they pre-date POSIX, in fact). And your book is correct to label them POSIX:XSI.
Jonathan Leffler
+1  A: 

Generally you should try to use the POSIX versions when you can as they should be more portable to a wider range of platforms.

The major differences are that POSIX queues can generate a signal or spawn a new thread when messages are put onto an empty queue. POSIX queues also always return the oldest message of the highest priority; the SysV queues can return a message of any priority you specify.

Everyone's mileage will vary but I find the POSIX interface to be more intuitive and less quirky than SYSV, or SysV IPC in general.

Duck