06-20-2010
Well, let's take a look at some situations where these things are used...
Shared memory avoids having to write data into and read it back out of the kernel, making it a blindingly fast way to share the same data with swarms of processes. Since it's not arbitrated by the kernel, it's got race conditions and pitfalls, so isn't as easy as it looks; when solving a complex enough problem you might find you're writing your own sockets from scratch instead of anything faster. You see it in situations with very demanding performance requirements, like high-performance audio or video interfaces(X11 drivers, XSHM video, DirectX). Linux's modern pthreads implementation builds mutexes and the like out of atomic operations on shared memory.
Named pipes are kind of an old-fashioned hack kept for portability reasons. Their behavior can be a bit obscure when dealing with more than one reader and/or writer. Occasionally handy in the shell to bridge unbridgables, otherwise I don't see them get much serious use.
UNIX domain sockets are very often used for local client/server interfaces because they're network-like(one server, multiple clients) without the overhead of loopback networking. Big things like X11 and MySQL servers serve clients with UNIX domain sockets when possible. Lots of less demanding system daemons and controllers(system loggers, linux udev, linux acpid, linux's wpa authentication manager) also use UNIX domain sockets for their convenience of network-like connect/disconnect without the complication of actual networking. They can't do any kind of sharing or broadcast sending.
pthreads is a threading implementation but often called (and used as) IPC anyway. Some implementations do allow seperate processes to share mutexes etc(the current NPTL linux implementation), some don't(linux's old linuxthreads implementation). Its features are tightly defined, fairly portable, and somewhat limited, mostly restricted to control mechanisms, not communication structures. By and large its overhead is quite low, but implementations of course vary. For simple control of threads it's difficult to beat.
System V IPC seems a bit overbuilt. Unlike POSIX thread primitives, this API is geared towards communications between unrelated processes, and frilled with so many features it's hard to imagine it not having significant overhead(most objects semi-persistent and given their own owner/group/attributes set, mtimes kept for many kinds of things, sometimes even last-user-modified). It has some interesting and difficult-to-implement features(grouping several semaphore operations atomically) which would be useful if implemented brilliantly, but can stall and starve if done badly, and implementations do vary. Message queues I'm unfortunately quite unfamiliar with.
Last edited by Corona688; 06-20-2010 at 04:13 PM..
This User Gave Thanks to Corona688 For This Post:
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have a parent that is passing data to child A and then child A has to process it and pass to child B. I am able to pass the data to child A but am not able to pass it to child B. Child B seems to only be receiving the last data instead of the whole data.
I saw one example in a book but it uses... (1 Reply)
Discussion started by: scmay
1 Replies
2. UNIX for Dummies Questions & Answers
I have no IPC Mechanisms program which includes data transfer on the same Linu machine. All mechanisms of IPC must be tested. If anyone have programs about it, could you send to me?? I am waiting your answers. please help me...!!!! (2 Replies)
Discussion started by: boris35
2 Replies
3. UNIX for Dummies Questions & Answers
hai,
i am doing my masters degree in computers.please any one tell me about
fork(),semaphores,mutex,messaging queues,messaging using pipes ,and msgget(),msgrecv() funtions
in ipc programming .
i have exam on that i have a book but in that they not given clearly.
hope u will
... (2 Replies)
Discussion started by: G.Vishnuvardhan
2 Replies
4. Programming
Hi guys, I'm new to Linux and Unix I have just simple code . But I don't know why it doesn't work ..
But, the outputfile is Blank.. I don't understand why.. Please help me.. Thank you very much
P.S: sorry, I don't know how to edit this post clearly.. it's hard to read.. Please try.. (2 Replies)
Discussion started by: thanh_sam_khac
2 Replies
5. Solaris
I was asked to look into a problem with a Sun Netra 440 in another department. On the server in question, the relevant 'uname -a' information is, "SunOS host1 5.9 Generic_118558-16 sun4u sparc SUNW,Netra-440". That information aside, while the other admin is logged into the ALOM, these errors are... (0 Replies)
Discussion started by: Borealis
0 Replies
6. UNIX for Dummies Questions & Answers
hey everyone,
I'm reading a tutorial on the Mach kernel principles, however, the port and port rights part are kind of confusing to me. I don't know if the book has typos or something but it seems a bit contradictory. It says that "ports, themselves, are not named. It is the port rights that are"... (10 Replies)
Discussion started by: neur0n
10 Replies
7. HP-UX
Hi Experts,
Need your help for checking te interprocess communications settings on HP-UX box.
Using ipcs command I am able to view Message queue,semapohores etc, but from that output I m not able to understand how to determine if there is any issue with ipc settings and how to resolve that? (1 Reply)
Discussion started by: sai_2507
1 Replies
8. Shell Programming and Scripting
Actually i am thinking of some usefull application that involves both IPC and pthreads.But i am not quite sure what type of application involves both these together :confused:.
Anyways i am now working on creating a simple featured file manager that can do the following:
Display file name and... (2 Replies)
Discussion started by: ronmaximus
2 Replies
9. Shell Programming and Scripting
I wonder are there any IPC mechanisms in cygwin? such as shared memory, semaphores , message queues and piping? Thanks Jack (2 Replies)
Discussion started by: lucky7456969
2 Replies
10. UNIX for Beginners Questions & Answers
Hello and thanks in advance for any help anyone can offer to help me understand this
I'm curious about a 30.000 ft view on how IPC works in Linux between parent-child processes...I understand there's multiple types of IPC's... But I'm currently trying to figure out if parent-child process IPC... (1 Reply)
Discussion started by: bodisha
1 Replies
LEARN ABOUT ULTRIX
sem_overview
SEM_OVERVIEW(7) Linux Programmer's Manual SEM_OVERVIEW(7)
NAME
sem_overview - overview of POSIX semaphores
DESCRIPTION
POSIX semaphores allow processes and threads to synchronize their actions.
A semaphore is an integer whose value is never allowed to fall below zero. Two operations can be performed on semaphores: increment the
semaphore value by one (sem_post(3)); and decrement the semaphore value by one (sem_wait(3)). If the value of a semaphore is currently
zero, then a sem_wait(3) operation will block until the value becomes greater than zero.
POSIX semaphores come in two forms: named semaphores and unnamed semaphores.
Named semaphores
A named semaphore is identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX-4 (i.e., 251)
characters consisting of an initial slash, followed by one or more characters, none of which are slashes. Two processes can operate
on the same named semaphore by passing the same name to sem_open(3).
The sem_open(3) function creates a new named semaphore or opens an existing named semaphore. After the semaphore has been opened,
it can be operated on using sem_post(3) and sem_wait(3). When a process has finished using the semaphore, it can use sem_close(3)
to close the semaphore. When all processes have finished using the semaphore, it can be removed from the system using
sem_unlink(3).
Unnamed semaphores (memory-based semaphores)
An unnamed semaphore does not have a name. Instead the semaphore is placed in a region of memory that is shared between multiple
threads (a thread-shared semaphore) or processes (a process-shared semaphore). A thread-shared semaphore is placed in an area of
memory shared between the threads of a process, for example, a global variable. A process-shared semaphore must be placed in a
shared memory region (e.g., a System V shared memory segment created using shmget(2), or a POSIX shared memory object built created
using shm_open(3)).
Before being used, an unnamed semaphore must be initialized using sem_init(3). It can then be operated on using sem_post(3) and
sem_wait(3). When the semaphore is no longer required, and before the memory in which it is located is deallocated, the semaphore
should be destroyed using sem_destroy(3).
The remainder of this section describes some specific details of the Linux implementation of POSIX semaphores.
Versions
Prior to kernel 2.6, Linux supported only unnamed, thread-shared semaphores. On a system with Linux 2.6 and a glibc that provides the NPTL
threading implementation, a complete implementation of POSIX semaphores is provided.
Persistence
POSIX named semaphores have kernel persistence: if not removed by sem_unlink(3), a semaphore will exist until the system is shut down.
Linking
Programs using the POSIX semaphores API must be compiled with cc -pthread to link against the real-time library, librt.
Accessing named semaphores via the filesystem
On Linux, named semaphores are created in a virtual filesystem, normally mounted under /dev/shm, with names of the form sem.somename.
(This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.)
Since Linux 2.6.19, ACLs can be placed on files under this directory, to control object permissions on a per-user and per-group basis.
NOTES
System V semaphores (semget(2), semop(2), etc.) are an older semaphore API. POSIX semaphores provide a simpler, and better designed inter-
face than System V semaphores; on the other hand POSIX semaphores are less widely available (especially on older systems) than System V
semaphores.
EXAMPLE
An example of the use of various POSIX semaphore functions is shown in sem_wait(3).
SEE ALSO
sem_close(3), sem_destroy(3), sem_getvalue(3), sem_init(3), sem_open(3), sem_post(3), sem_unlink(3), sem_wait(3), pthreads(7), shm_over-
view(7)
COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2017-05-03 SEM_OVERVIEW(7)