Difference between shared memory IPC mechanism and API/system-call invocation
I am studying about operating systems(Silberscatz, Galvin et al). My programming experiences are limited to occasional coding of exercise problems given in a programing text or an algorithm text. In other words I do not have a proper application programming or system programming experience. I think my below question is a result of a lack of experience of the above and hence a lack of context. I am specifically studying IPC mechanisms. While reading about shared memory(SM) I couldn't imagine a real life scenario where processes communicate using SM. An inspection of processes attached to the same SM segment on my linux(ubuntu) machine(using 'ipcs' in a small shell script) is uploaded here Most of the sharing by applications seem to be with the X deamon. From what I know , X is the process responsible for giving me my GUI. I infered that these applications(mostly applets which stay on my taskbar) share data with X about what needs to change in their appearances and displayed values. Is this a reasonable inference?? If so, my question is, what is the difference between my applications communicating with 'X' via shared memory segments versus my applications invoking certain API's provided by 'X' and communicate to 'X' about the need to refresh their appearances?? BY difference I mean, why isn't the later approach used? Isn't that how user processes and the kernel communicate? Application invokes a system call when it wants to, say read a file, communicating the name of the file and other related info via arguments of the system call? Also could you provide me with examples of routinely used applications which make use of shared memory and message-passing for communication? EDIT I have made the question more clearer. I have formatted the edited part to be bold
The difference is that with an API you as a developer might not have access to what is happening inside these functions, so memory would not necessarily be shared. Shared Memory is mostly a specific region of memory to which both apps can write and read from. This off course requires that access to that memory is synchronized so things don't get corrupted. Using somebody's API does not mean you are sharing memory with them, that process will just do what you asked and perhaps return the result of that operation to you, however that doesn't necessarily go via shared memory. Although it could, it depends, as always. The preference for one over another I'd say depends on the specifications of the particular application and what it is doing and what it needs to share. I can imagine that a big dataset of some kind or another would be shared by shared memory, but passing a file name to another app might only need an API call. However largely dependent on requirements I'd say.
First, since the X server is just another user space process, it cannot use the operating system's system call mechanism. Even when the communication is done through an API, if it is between user space processes, there will be some inter-process-communication (IPC) mechanism behind that API. Which might be shared memory, sockets, or others. Typically shared memory is used when a lot of data is involved. Maybe there is a lot of data that multiple processes need to access, and it would be a waste of memory for each process to have its own copy. Or a lot of data needs to be communicated between processes, which would be slower if it were to be streamed, a byte at a time, through another IPC mechanism. For graphics, it is not uncommon for a program to keep a buffer containing a pixel map of an image, a window, or even the whole screen that then needs to be regularly copied to the screen. Sometimes at a very high rate...30 times a second or more. I suspect this is why X uses shared memory when possible.
Operating System Overhead [closed]
How the Scheduler decides about the time for the time-quantum in RoundRobin Scheduling Algorithm?
interrupt handler from scratch [closed]
What exactly happens in a power-fail interrupt?
creating task inside other task in freertos
Three threads one for input from keyboard second for encryption and third to print the input
what should i study to get an indepth understanding of operating systems
I am getting the following error after installing Pint-OS and trying to run multiple alarm. I am using bochs as emulator. Any possible work around?
implementation of a simulated disk for an instructional operating system?
rust calling failure::fail_bounds_check with no-landing-pads flag enabled
Is running Docker on bare metal maintainable?
How does a bootstrap program do dual booting of OS
In user-mode, an application will never know what physical address its memory is at, then why does the linker give physical addresses to all sections?
Ones-compliment or sign-magnitude integer representation platform?
How are the code, the hardware, and the OS related? [closed]
dynamic linking v/s dynamic loading