Question: 7. What is the output of this program?<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="co2">#include&lt;stdio.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;fcntl.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/stat.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/mman.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> s_id<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> <span class="sy0">*</span>ptr<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> s_id <span class="sy0">=</span> shm_open<span class="br0">(</span><span class="st0">"shared_mem"</span><span class="sy0">,</span>O_CREAT<span class="sy0">|</span>O_RDWR<span class="sy0">,</span><span class="nu8">0666</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>s_id <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</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">"shm_open"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> ptr <span class="sy0">=</span> mmap<span class="br0">(</span>NULL<span class="sy0">,</span><span class="nu0">100</span><span class="sy0">,</span>PROT_WRITE<span class="sy0">,</span>MAP_PRIVATE<span class="sy0">,</span>s_id<span class="sy0">,</span><span class="nu0">0</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>ptr <span class="sy0">==</span> MAP_FAILED<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"mmap"</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>munmap<span class="br0">(</span>ptr<span class="sy0">,</span><span class="nu0">100</span><span class="br0">)</span> <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</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">"munmap"</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>shm_unlink<span class="br0">(</span><span class="st0">"shared_mem"</span><span class="br0">)</span> <span class="sy0">==</span> <span class="sy0">-</span><span class="nu0">1</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">"shm_unlink"</span><span class="br0">)</span><span class="sy0">;</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:
mmap: Success
mmap: Failure
munmap: Success
munmap: Failure
Answer: A