Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting same physical address in a c program
    primarykey
    data
    text
    <p>Is there is a way to print the same physical address in these programs (while using the shared memory concept) rather than printing different logical addresses?</p> <p>The reason for me to print the same physical address :...</p> <p>/*It's optional to read this, since I have provided a lot of information which is not to the core */</p> <p>In my lab, I have two programs: one to store a string in a physical memory via shared memory concept and one to print the same string via accessing the shared memory.</p> <p>Program 1:</p> <pre><code>#include&lt;sys/types.h&gt; #include&lt;string.h&gt; #include&lt;sys/ipc.h&gt; #include&lt;sys/shm.h&gt; #include&lt;stdio.h&gt; main() { key_t key; int shmid; char* addr1; key = ftok("/home/tamil/myc/pws.c",'T'); shmid = shmget(key,128*1024,IPC_CREAT|SHM_R|SHM_W); addr1 = shmat(shmid,0,0); printf("\nIPC SHARED MEMORY"); printf("\n SENDER ADDRESS"); printf("\nTHE ADDRESS IS %p",addr1); printf("\nENTER THE MESSAGE:"); scanf("%s",addr1); printf("\nMESSAGE STORED IN %p IS %s",addr1,addr1); } </code></pre> <p>Program 2:</p> <pre><code>#include&lt;sys/types.h&gt; #include&lt;string.h&gt; #include&lt;sys/ipc.h&gt; #include&lt;sys/shm.h&gt; #include&lt;stdio.h&gt; main() { int shmid; char* addr1; key_t key; key = ftok("/home/tamil/myc/pws.c",'T'); shmid = shmget(key,128*1024,SHM_R|SHM_W); addr1 = shmat(shmid,0,0); printf("\nIPC SHARED MEMORY"); printf("\n SENDER ADDRESS"); printf("\nTHE ADDRESSS IS %p",addr1); printf("\nMESSAGE STORED IN %p IS %s",addr1,addr1); } </code></pre> <p>Output:</p> <pre><code>tamil@ubuntu:~/myc$ cc shmget.c tamil@ubuntu:~/myc$ ./a.out IPC SHARED MEMORY SENDER ADDRESS THE ADDRESS IS 0xb786c000 ENTER THE MESSAGE:helloworld MESSAGE STORED IN 0xb786c000 IS helloworld tamil@ubuntu:~/myc$ cc shmget2.c tamil@ubuntu:~/myc$ ./a.out IPC SHARED MEMORY SENDER ADDRESS THE ADDRESSS IS 0xb7706000 MESSAGE STORED IN 0xb7706000 IS helloworld tamil@ubuntu:~/myc$ </code></pre> <p>Here these programs are printing the 2 different logical address. But (to satisfy the college professor) is there is a way to print the same physical address? Please help..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload