Question: 5. 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;semaphore.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"> sem_t<span class="sy0">*</span> sem_id<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> value<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_id <span class="sy0">=</span> sem_open<span class="br0">(</span><span class="st0">"new_13"</span><span class="sy0">,</span>O_CREAT<span class="sy0">,</span><span class="nu8">0666</span><span class="sy0">,</span><span class="nu0">3</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>sem_id <span class="sy0">==</span> SEM_FAILED<span class="br0">)</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">perror</span><span class="br0">(</span><span class="st0">"sem_open"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_wait<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_wait<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_wait<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_wait<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_post<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_post<span class="br0">(</span>sem_id<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> sem_getvalue<span class="br0">(</span>sem_id<span class="sy0">,&amp;</span>value<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">"%d<span class="es1">\n</span>"</span><span class="sy0">,</span>value<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>sem_close<span class="br0">(</span>sem_id<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">"sem_close"</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:
2
3
0
none of the mentioned
Answer: D