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;stdlib.h&gt;</span></pre></li><li class="li1"><pre class="de1"> <span class="co2">#include&lt;sys/types.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/sem.h&gt;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"> <span class="kw4">static</span> <span class="kw4">int</span> sem_p<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">static</span> <span class="kw4">int</span> sem_v<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">union</span> semun<span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> val<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> semid_ds <span class="sy0">*</span>buf<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">unsigned</span> <span class="kw4">short</span> array<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="br0">}</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> sem_id<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> semid_ds myds<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">struct</span> sembuf mybuf<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">union</span> semun myun<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">static</span> <span class="kw4">int</span> sem_p<span class="br0">(</span><span class="kw4">void</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"> mybuf.<span class="me1">sem_num</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> mybuf.<span class="me1">sem_op</span> <span class="sy0">=</span> <span class="sy0">-</span><span class="nu0">1</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> mybuf.<span class="me1">sem_flg</span> <span class="sy0">=</span> SEM_UNDO<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> semop<span class="br0">(</span>sem_id<span class="sy0">,&amp;</span>mybuf<span class="sy0">,</span><span class="nu0">1</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="kw4">static</span> <span class="kw4">int</span> sem_v<span class="br0">(</span><span class="kw4">void</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"> mybuf.<span class="me1">sem_num</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> mybuf.<span class="me1">sem_op</span> <span class="sy0">=</span> <span class="nu0">1</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> mybuf.<span class="me1">sem_flg</span> <span class="sy0">=</span> SEM_UNDO<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> semop<span class="br0">(</span>sem_id<span class="sy0">,&amp;</span>mybuf<span class="sy0">,</span><span class="nu0">1</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="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> wfd<span class="sy0">,</span> rfd<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_id <span class="sy0">=</span> semget<span class="br0">(</span><span class="br0">(</span>key_t<span class="br0">)</span><span class="nu0">911</span><span class="sy0">,</span><span class="nu0">1</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"> myun.<span class="me1">val</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> semctl<span class="br0">(</span>sem_id<span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,</span>IPC_RMID<span class="sy0">,</span>myun<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> semctl<span class="br0">(</span>sem_id<span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,</span>SETVAL<span class="sy0">,</span>myun<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_p<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">printf</span><span class="br0">(</span><span class="st0">"Sanfoundry<span class="es1">\n</span>"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_v<span class="br0">(</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:
this process will remain block
this program will print the string “Sanfoundry”
this program will print the string “Sanfoundry” & process will remain block
none of the mentioned
Answer: B