Question: 2. 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">&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> fd<span class="br0">[</span><span class="nu0">2</span><span class="br0">]</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">int</span> child<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw4">char</span> buff<span class="br0">[</span><span class="nu0">6</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>pipe<span class="br0">(</span>fd<span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">0</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">"pipe"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> child<span class="sy0">=</span>fork<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">switch</span><span class="br0">(</span>child<span class="br0">)</span><span class="br0">{</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">case</span> <span class="sy0">-</span><span class="nu0">1</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">"fork"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw3">exit</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">case</span> <span class="nu0">0</span> <span class="sy0">:</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">if</span> <span class="br0">(</span>write<span class="br0">(</span>fd<span class="br0">[</span><span class="nu0">1</span><span class="br0">]</span><span class="sy0">,</span><span class="st0">"Linux"</span><span class="sy0">,</span><span class="nu0">6</span><span class="br0">)</span> <span class="sy0">!=</span> <span class="nu0">6</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">"write"</span><span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">break</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw1">default</span> <span class="sy0">:</span></pre></li><li class="li1"><pre class="de1"> read<span class="br0">(</span>fd<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="sy0">,</span>buff<span class="sy0">,</span><span class="nu0">6</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">"%s<span class="es1">\n</span>"</span><span class="sy0">,</span>buff<span class="br0">)</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"> <span class="kw2">break</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:
this program will print the string “Linux”
this program will print nothing
segmentation fault
none of the mentioned
Answer: A