Microsoft Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
I believe it should be possible via shared memory. While using shared memory, we attach that shared memory to the address space of our process. So, shared memory becomes part of the address spaces of both the processes. Although, we need to do some synchronization b/w the two processes accessing the shared memory.
I doubt that.
You can't use a pointer because there's no way to ensure that the shared memory is mapped at the same address in both processes. One process would no have idea what to do with a pointer into the other process' virtual address space.
So instead, you store the offset into the block of shared memory. Both processes know exactly what the 712th byte of the block of shared memory is. To access such an offset, you add the offset to the base address at which the block of shared memory is mapped in this particular process, and that creates a pointer you can use within that particular process.
I agree with Nayan. The shared memory area isn't accessed by same memory map by the two processes. So when one process writes data to the buffer (and also the size of writen data), the other process reads those many bytes. Usually, there's a pre-defined op-code list to which the request is compared and the right event is triggered. (trivia: IPC on one core can be optimized by using better algo than op-code list, but for multi-core arch, op-code list seems the common way to get things done.) The response is pasted along with the size. These request/response messages to shared mem form an integral part of sw debugging. More comments are welcome.
it depends upon the situations okay. if the variable which is pointed by the pointer in other process in not global or shared then its sure that the process will crash because of the segmentation fault generated by the os and signalled to the process which wants to change it .
but wait!! if the variable is shared one then it can be easily modified by the other process .
It should be possible. But the module/program for both the processes should be coded by in such a way that, altering a variable of a process by the other shouldn't cause any data loss, or alternation.
So basically such programs are coded by a single team who knows behavior of both the processed.
And, if the processes/code are developed by different teams having no knowledge on the other process. In such cases above operations may lead to crashes.
Normally processes have their own address spaces and this address space is not visible from other processes (but read: interprocess communication - how to create a visible address space that is shared between two or more processes). This is the usual case but there are operating systems (some embedded systems for example) where it is not the case, protected memory/separate address space is "expensive" (read: task switch penalty)
- Selmeczy, Péter January 18, 2012Threads do share the same address space, so in case of threads the answer is yes.