Question: 9. What is the output of second program if we run the san1 first and after that we run san2 in the different terminal?<div class="hk1_style-wrap4"><div class="hk1_style-wrap3"><div class="hk1_style-wrap2"><div class="hk1_style-wrap"><div class="hk1_style"><div class="c"><ol><li class="li1"><pre class="de1"> <span class="coMULTI">/*This is san1.c*/</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;stdio.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/ipc.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/shm.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;string.h&gt;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> shm_id<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">char</span> <span class="sy0">*</span>addr<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> shmid_ds ds<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> shm_id <span class="sy0">=</span> shmget<span class="br0">(</span><span class="br0">(</span>key_t<span class="br0">)</span><span class="nu0">1234</span><span class="sy0">,</span><span class="nu0">10</span><span class="sy0">,</span><span class="nu8">0666</span><span class="sy0">|</span>IPC_CREAT<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>shm_id <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmget"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> addr <span class="sy0">=</span> <span class="br0">(</span><span class="kw4">char</span><span class="sy0">*</span><span class="br0">)</span>shmat<span class="br0">(</span>shm_id<span class="sy0">,</span>NULL<span class="sy0">,</span>SHM_RND<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>addr <span class="sy0">==</span> <span class="br0">(</span><span class="kw4">char</span> <span class="sy0">*</span><span class="br0">)</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmat"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">strcpy</span><span class="br0">(</span>addr<span class="sy0">,</span><span class="st0">"Sanfoundry"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span> <span class="br0">(</span>shmdt<span class="br0">(</span>addr<span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmdt"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span> shmctl<span class="br0">(</span>shm_id<span class="sy0">,</span>IPC_RMID<span class="sy0">,</span><span class="nu0">0</span><span class="br0">)</span> <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmctl"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="coMULTI">/*This is san2.c*/</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;stdio.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/ipc.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/shm.h&gt;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> shm_id<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">char</span> <span class="sy0">*</span>addr<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> shmid_ds ds<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> shm_id <span class="sy0">=</span> shmget<span class="br0">(</span><span class="br0">(</span>key_t<span class="br0">)</span><span class="nu0">1234</span><span class="sy0">,</span><span class="nu0">10</span><span class="sy0">,</span><span class="nu8">0666</span><span class="sy0">|</span>IPC_CREAT<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>shm_id <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmget"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> addr <span class="sy0">=</span> <span class="br0">(</span><span class="kw4">char</span><span class="sy0">*</span><span class="br0">)</span>shmat<span class="br0">(</span>shm_id<span class="sy0">,</span>NULL<span class="sy0">,</span>SHM_RND<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span><span class="br0">(</span>addr <span class="sy0">==</span> <span class="br0">(</span><span class="kw4">char</span> <span class="sy0">*</span><span class="br0">)</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmat"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">printf</span><span class="br0">(</span><span class="st0">"%s<span class="es1">\n</span>"</span><span class="sy0">,</span>addr<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span> <span class="br0">(</span>shmdt<span class="br0">(</span>addr<span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">0</span><span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"shmdt"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span></pre></li></ol></div></div></div></div></div></div>
Options:
the program will print the string “Sanfoundry”
the program will nothing
segmentaion fault
none of the mentioned
Answer: A