Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Through shmget and shmat, I am able to access the data stored in one program from another program. Here's the gist of the code:

key=ftok("shared.c",'c');
shmid=shmget(key,1024,0644|IPC_CREAT);
data=shmat(shmid,(void *)0,0);
printf("Enter the data");
gets(data);

Similarly I can write another program and use shmat there to access the data.

Now I wanted to know how can I access it from the host operating system. Since the shared memory id will be different in the host memory, shmat won't work. How can I access the shared memory from the host machine?

can we do it in this way: we know that there exist a page table with respect to each operating system in a hypervisor which will maps the logical address to physical address,there is a pmap table which maps the physical address of the hypervisor with the physical address of the host machine,and also there exist shadow page tables in hypervisor which maps the logical guest address to host physical address. Is there any way of accessing the shadow page tables or pagetable corresponding to the OS

share|improve this question
    
Is this related to this question? If so, you should close the other question and tag this one with VirtualBox. –  Nils Feb 5 '12 at 21:50
    
Why do you want to do that? –  Nils Feb 5 '12 at 21:54
add comment

3 Answers

You can't; that is kind of the point of a virtual machine: it thinks it is the only OS running.

share|improve this answer
    
Other way around: He wants to access from the Host machine. –  Nils Feb 5 '12 at 21:51
add comment

It doesn't work that way: the virtual machine and the host don't share the same memory. That's why it's called a virtual machine. Shared memory, as you've been using it, is an OS-level concept; you can't use it to share memory with something that's outside the control of the (guest) OS.

In principle, the virtual machine technology could offer some way to share memory between the guest and the host. But that would defeat the purpose of virtualization: it would allow guest programs to escape the virtual machine.

If you want to share data between a virtual machine and its host, use a file on the host, on a directory that's mounted in the virtual machine (e.g. through vboxsf on VirtualBox); or more generally use a file somewhere that's accessible on both sides.

share|improve this answer
    
Host - not Guest. This should be possible - e.g. VirtualBox runs in user space on the host. –  Nils Feb 5 '12 at 21:53
    
@Nils Sure, it's technically possible. It requires some cooperation between the VM machinery and the guest OS. As far as I know, the major VM engines have no such feature because it's too much work for something that runs against the usual uses of VMs. –  Gilles Feb 5 '12 at 22:07
add comment

Although I think that it should be possible you need to align memory segments. This alignment may change without notice after an upgrade of the VM technology.

As Gilles pointed out - you should use other means. SLES11 has a "nice" way to share information between Host and Guest(s): The Host generates a RAM-disk and updates its contents in regular intervals. The Guest(s) mount this RAM-disk RO and read the contents. By default it is used there to pass information about the Host status to the guests (available RAM, name of the Host, ...)

share|improve this answer
    
can we do like this :we know that there exist a page table with respect to each operating system in a hypervisor which will maps the logical address to physical address,there is a pmap table which maps the physical address of the hypervisor with the physical address of the host machine,and also there exist shadow page tables in hypervisor which maps the logical guest address to host physical address. Is there any way of accessing the shadow page tables or pagetable corresponding to the OS –  user44977 Feb 6 '12 at 5:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.