<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; deepanshuemblinux</title>
	<atom:link href="https://www.emblogic.com/blog/author/deepanshuemblinux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Call Stack</title>
		<link>https://www.emblogic.com/blog/09/call-stack/</link>
		<comments>https://www.emblogic.com/blog/09/call-stack/#comments</comments>
		<pubDate>Thu, 18 Sep 2014 18:01:18 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=11493</guid>
		<description><![CDATA[Programs written in the procedural style (as opposed to object-oriented style) are organized as a logical hierarchy of subroutine calls. In general, each subroutine call involves passing arguments from the caller to the callee. In addition, the callee may declare &#8230; <a href="https://www.emblogic.com/blog/09/call-stack/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a name="cs"></a></p>
<h3></h3>
<p><a name="cs"></a></p>
<p><a name="cs"></a> Programs written in the procedural style (as opposed to object-oriented style) are organized as a logical hierarchy of subroutine calls. In general, each subroutine call involves passing arguments from the <span class="rdu">caller</span> to the <span class="rdu">callee</span>. In addition, the callee may declare temporary local variables. Subroutine arguments and <em>automatic</em> local variables are accommodated at the top of virtual memory in an area known as the <em>stack segment</em> or simply as the <em>stack</em>. See <a href="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html#figure5">Figure 5</a>.</p>
<p><a name="figure5"></a></p>
<div class="fig"><img title="Figure 5" src="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/images/mem/figure5.png" alt="Figure 5" /><b>Fig. 5</b> Memory map showing the stack segment.</p>
</div>
<p><a name="figure5"></a></p>
<p><a name="figure5"></a> The hierarchy of subroutine calls begins when the operating system invokes the program&#8217;s <span class="in">main()</span> function in C or the <span class="in">MAIN</span> program in Fortran. Under normal circumstances, it ends when &#8220;main&#8221; returns to the operating system. The entire sequence can be represented as a <span class="rdu">call graph</span> like that in <a href="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html#figure6">Figure 6</a>.</p>
<p><a name="figure6"></a></p>
<div class="fig"><img title="Figure 6" src="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/images/mem/figure6.png" alt="Figure 6" /></p>
<ol>
<li>OS calls main</li>
<li>main calls func1</li>
<li>func1 calls func2</li>
<li>func2 returns to func1</li>
<li>func1 calls func3</li>
<li>func3 returns to func1</li>
<li>func1 returns to main</li>
<li>main calls func4</li>
<li>func4 returns to main</li>
<li>main returns (exit status) to OS</li>
</ol>
<p><b>Fig. 6</b> Typical subroutine call graph.</p>
</div>
<p><a name="figure6"></a></p>
<p>Before calling main, the operating system <span class="rdu">pushes</span> the elements of the command line that was used to invoke the program on &#8220;top&#8221; of the initially empty stack. In C, the <span class="in">main()</span> function has access to these arguments through the <span class="in">argc</span> and <span class="in">argv</span> parameters, while Fortran <span class="in">MAIN</span> programs can use the <span class="in">IARGC</span> and <span class="in">GETARG</span> subroutines, which are non-standard extensions.</p>
<p><a name="figure6"></a></p>
<p><a name="figure6"></a> As execution commences, main pushes its automatic variables on top of the stack. This makes the stack &#8220;grow&#8221; towards lower addresses. Then, just prior to calling func1, main pushes the arguments to func1. Together, main&#8217;s automatic variables and the arguments to func1 constitute a <em>stack frame</em>. Stack frames accumulate on the stack as the program descends the call graph, and are dismantled as it ascends. The procedure is outlined in <a href="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html#figure7">Figure 7</a> below.</p>
<p><a name="figure7"></a></p>
<div class="fig"><img title="Figure 7" src="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/images/mem/figure7.png" alt="Figure 7" /><b>Fig. 7</b> Evolution of the stack segment corresponding to the call graph shown in Figure 6.</p>
</div>
<p><a name="figure7"></a></p>
<p>By convention, the currently active subroutine can only reference the arguments it was passed and its own local automatic and static variables (plus any globally accessible data). For example, while func2 is executing, it can not access func1&#8242;s local variables, unless of course func1 passes references to its local variables in the argument list to func2.</p>
<p><a name="figure7"></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/09/call-stack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install grub on a floppy disk or a partition?</title>
		<link>https://www.emblogic.com/blog/08/how-to-install-grub-on-a-floppy-disk-or-a-partition/</link>
		<comments>https://www.emblogic.com/blog/08/how-to-install-grub-on-a-floppy-disk-or-a-partition/#comments</comments>
		<pubDate>Thu, 28 Aug 2014 10:14:13 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 00: Linux System / Network Administration]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=11441</guid>
		<description><![CDATA[  When you are working on an already installed linux distribution, the grub package will be bydefault installed on the system. I will be showing you, the example&#8217;s of working with grub-legacy. Because any grub version number thats in the &#8230; <a href="https://www.emblogic.com/blog/08/how-to-install-grub-on-a-floppy-disk-or-a-partition/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2><span style="color: #800080"> </span></h2>
<p><span style="font-size: 16px">When you are working on an already installed linux distribution, the grub package will be bydefault installed on the system</span>.</p>
<p><span style="font-size: 16px">I will be showing you, the example&#8217;s of working with grub-legacy. Because any grub version number thats in the form 0.9x is grub-legacy now.(Please note the fact that grub-legacy is no longer under active developement.)</span></p>
<p><span style="font-size: 16px">For this example, i will be working on a Red hat enterprise linux 5.</span></p>
<div class="geshifilter">
<pre class="text geshifilter-text" style="font-family: monospace"><span style="font-size: 16px">[root@localhost ~]# rpm -qa | grep grub
grub-0.97-13.5
[root@localhost ~]#</span></pre>
</div>
<p><span style="font-size: 16px">the above shown package, will also provide you with a command called grub-install.</span></p>
<div class="geshifilter">
<pre class="text geshifilter-text" style="font-family: monospace"><span style="font-size: 16px">[root@localhost ~]# whereis grub-install
grub-install: /sbin/grub-install /usr/share/man/man8/grub-install.8.gz
[root@localhost ~]# rpm -qf /sbin/grub-install
grub-0.97-13.5</span></pre>
</div>
<div>
<p><span style="font-size: 16px">As you can clearly see from the above command results that the grub-install command comes from the package grub-0.97-13.5</span></div>
<div></div>
<div><span style="font-size: 16px">You can simply install grub, on your desired partition, as shown below, with the help of grub-install command.</span></div>
<div></div>
<div class="geshifilter">
<pre class="text geshifilter-text" style="font-family: monospace"><span style="font-size: 16px">[root@localhost ~]# grub-install /dev/sda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0)     /dev/sda
[root@localhost ~]#</span></pre>
</div>
<p><span style="font-size: 16px">In the above command, it will install grub in the MBR of the hard disk /dev/sda.</span><br />
<span style="font-size: 16px">the above command result tells you an important fact to understand. It tells that, there is a device map file, and is asking us to check and confirm whether the file is correct or not.</span></p>
<h2></h2>
<h2><span style="font-size: 16px"><img style="width: 70px;height: 70px;float: left" src="http://www.slashroot.in/images/important%20note.gif" alt="note" />Device map file is used by grub to identify the OS device names in a precise way. GRUB uses this file to map the device names of BIOS to operating system device names.</span><span style="font-size: 16px">This was devised, because there was inconstancies with, Linux operating system&#8217;s device naming convention.</span></h2>
<p><span style="font-size: 16px">This file is configurable as per your requirement.</span></p>
<p><span style="font-size: 16px">In the above example output of the /boot/grub/device.map tells that (hd0) in grub means /dev/sda in the operating system.</span></p>
<p><span style="font-size: 16px"><img style="width: 70px;height: 70px;float: left" src="http://www.slashroot.in/images/important%20note.gif" alt="note" />Whenever you install GRUB, on any of your partition, it gets installed and images are put under the directory &#8220;boot&#8221; in that partition.</span><br />
<span style="font-size: 16px">If you want to install grub, under a directory other than the default &#8220;boot&#8221;, you need to specify the boot directory with a command line argument to <strong>grub-install </strong>command.</span></p>
<p><span style="font-size: 16px">Imagine that you want to install grub, on one of your external hard disk, and is currently mounted under /mydisk. lets see how to do it.</span></p>
<pre><span style="font-size: 16px"><span class="geshifilter"><code class="text geshifilter-text">[root@localhost ~]# grub-install --root-directory=/mydisk/grub/ /dev/sdb</code></span></span></pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/08/how-to-install-grub-on-a-floppy-disk-or-a-partition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>difference between monolithic and microlithic kernel</title>
		<link>https://www.emblogic.com/blog/07/difference-between-monolithic-and-microlithic-kernel/</link>
		<comments>https://www.emblogic.com/blog/07/difference-between-monolithic-and-microlithic-kernel/#comments</comments>
		<pubDate>Mon, 21 Jul 2014 05:13:36 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 00: Linux System / Network Administration]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=11210</guid>
		<description><![CDATA[Monolithic Kernel (Macro Kernel): Kernel Image = (Kernel Core+Kernel Services). When system boots up entire services  are loaded and resides in memory. Example: Windows and Unix. &#160; Micro kernel : Kernel Image = Kernel Core. Services are build in to &#8230; <a href="https://www.emblogic.com/blog/07/difference-between-monolithic-and-microlithic-kernel/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Monolithic Kernel (Macro Kernel): Kernel Image = (Kernel Core+Kernel Services). When system boots up entire services  are loaded and resides in memory.</p>
<p><em>Example:</em> Windows and Unix.</p>
<p>&nbsp;</p>
<p>Micro kernel : Kernel Image = Kernel Core. Services are build in to special modules which can be loaded and unloaded as per need.</p>
<p>&nbsp;</p>
<p>We have another type of kernel integration technique called</p>
<p>Modular, this is derived from best of micro and monolithic kernel) In</p>
<p>Modular kernel integration:  Kernel Image = (Kernel core + IPC service modules +Memory  module +Process Management module). All other modules are loadable kernel modules.</p>
<p><em>Example</em>: Linux kernel</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/07/difference-between-monolithic-and-microlithic-kernel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>check this code out on function pointers</title>
		<link>https://www.emblogic.com/blog/06/check-this-code-out-on-function-pointers/</link>
		<comments>https://www.emblogic.com/blog/06/check-this-code-out-on-function-pointers/#comments</comments>
		<pubDate>Thu, 19 Jun 2014 09:32:30 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10546</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.emblogic.com/blog/wp-content/uploads/2014/06/snap1.png"><img class="alignnone size-medium wp-image-10547" src="http://www.emblogic.com/blog/wp-content/uploads/2014/06/snap1-300x168.png" alt="snap1" width="300" height="168" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/check-this-code-out-on-function-pointers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>code to pass more than one number of variables into a thread by parent thread</title>
		<link>https://www.emblogic.com/blog/06/code-to-pass-more-than-one-number-of-variables-into-a-thread-by-parent-thread/</link>
		<comments>https://www.emblogic.com/blog/06/code-to-pass-more-than-one-number-of-variables-into-a-thread-by-parent-thread/#comments</comments>
		<pubDate>Mon, 16 Jun 2014 11:35:05 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 04: FTP based Client Server using Threads and Sockets]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10499</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.emblogic.com/blog/wp-content/uploads/2014/06/snap.png"><img class="alignnone size-medium wp-image-10500" src="http://www.emblogic.com/blog/wp-content/uploads/2014/06/snap-300x168.png" alt="snap" width="300" height="168" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/code-to-pass-more-than-one-number-of-variables-into-a-thread-by-parent-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Structure Member Alignment and structure  Padding</title>
		<link>https://www.emblogic.com/blog/06/structure-member-alignment-and-structure-padding/</link>
		<comments>https://www.emblogic.com/blog/06/structure-member-alignment-and-structure-padding/#comments</comments>
		<pubDate>Sat, 14 Jun 2014 13:01:08 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10478</guid>
		<description><![CDATA[What do we mean by data alignment, structure packing and padding? Predict the output of following program. #include &#60;stdio.h&#62; // Alignment requirements // (typical 32 bit machine) // char         1 byte // short int    2 &#8230; <a href="https://www.emblogic.com/blog/06/structure-member-alignment-and-structure-padding/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="post-title-info">
<h2 class="post-title"></h2>
</div>
<p>What do we mean by data alignment, structure packing and padding?</p>
<p>Predict the output of following program.<span id="more-9705"></span></p>
<div>
<div id="highlighter_187904" class="syntaxhighlighter nogutter  cpp">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="cpp preprocessor">#include &lt;stdio.h&gt;</code></div>
<div class="line number2 index1 alt1"></div>
<div class="line number3 index2 alt2"><code class="cpp comments">// Alignment requirements</code></div>
<div class="line number4 index3 alt1"><code class="cpp comments">// (typical 32 bit machine)</code></div>
<div class="line number5 index4 alt2"></div>
<div class="line number6 index5 alt1"><code class="cpp comments">// char         1 byte</code></div>
<div class="line number7 index6 alt2"><code class="cpp comments">// short int    2 bytes</code></div>
<div class="line number8 index7 alt1"><code class="cpp comments">// int          4 bytes</code></div>
<div class="line number9 index8 alt2"><code class="cpp comments">// double       8 bytes</code></div>
<div class="line number10 index9 alt1"></div>
<div class="line number11 index10 alt2"><code class="cpp comments">// structure A</code></div>
<div class="line number12 index11 alt1"><code class="cpp keyword bold">typedef</code> <code class="cpp keyword bold">struct</code> <code class="cpp plain">structa_tag</code></div>
<div class="line number13 index12 alt2"><code class="cpp plain">{</code></div>
<div class="line number14 index13 alt1"><code class="cpp spaces">   </code><code class="cpp color1 bold">char</code>        <code class="cpp plain">c;</code></div>
<div class="line number15 index14 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">short</code> <code class="cpp color1 bold">int</code>   <code class="cpp plain">s;</code></div>
<div class="line number16 index15 alt1"><code class="cpp plain">} structa_t;</code></div>
<div class="line number17 index16 alt2"></div>
<div class="line number18 index17 alt1"><code class="cpp comments">// structure B</code></div>
<div class="line number19 index18 alt2"><code class="cpp keyword bold">typedef</code> <code class="cpp keyword bold">struct</code> <code class="cpp plain">structb_tag</code></div>
<div class="line number20 index19 alt1"><code class="cpp plain">{</code></div>
<div class="line number21 index20 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">short</code> <code class="cpp color1 bold">int</code>   <code class="cpp plain">s;</code></div>
<div class="line number22 index21 alt1"><code class="cpp spaces">   </code><code class="cpp color1 bold">char</code>        <code class="cpp plain">c;</code></div>
<div class="line number23 index22 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">int</code>         <code class="cpp plain">i;</code></div>
<div class="line number24 index23 alt1"><code class="cpp plain">} structb_t;</code></div>
<div class="line number25 index24 alt2"></div>
<div class="line number26 index25 alt1"><code class="cpp comments">// structure C</code></div>
<div class="line number27 index26 alt2"><code class="cpp keyword bold">typedef</code> <code class="cpp keyword bold">struct</code> <code class="cpp plain">structc_tag</code></div>
<div class="line number28 index27 alt1"><code class="cpp plain">{</code></div>
<div class="line number29 index28 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">char</code>        <code class="cpp plain">c;</code></div>
<div class="line number30 index29 alt1"><code class="cpp spaces">   </code><code class="cpp color1 bold">double</code>      <code class="cpp plain">d;</code></div>
<div class="line number31 index30 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">int</code>         <code class="cpp plain">s;</code></div>
<div class="line number32 index31 alt1"><code class="cpp plain">} structc_t;</code></div>
<div class="line number33 index32 alt2"></div>
<div class="line number34 index33 alt1"><code class="cpp comments">// structure D</code></div>
<div class="line number35 index34 alt2"><code class="cpp keyword bold">typedef</code> <code class="cpp keyword bold">struct</code> <code class="cpp plain">structd_tag</code></div>
<div class="line number36 index35 alt1"><code class="cpp plain">{</code></div>
<div class="line number37 index36 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">double</code>      <code class="cpp plain">d;</code></div>
<div class="line number38 index37 alt1"><code class="cpp spaces">   </code><code class="cpp color1 bold">int</code>         <code class="cpp plain">s;</code></div>
<div class="line number39 index38 alt2"><code class="cpp spaces">   </code><code class="cpp color1 bold">char</code>        <code class="cpp plain">c;</code></div>
<div class="line number40 index39 alt1"><code class="cpp plain">} structd_t;</code></div>
<div class="line number41 index40 alt2"></div>
<div class="line number42 index41 alt1"><code class="cpp color1 bold">int</code> <code class="cpp plain">main()</code></div>
<div class="line number43 index42 alt2"><code class="cpp plain">{</code></div>
<div class="line number44 index43 alt1"><code class="cpp spaces">   </code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"sizeof(structa_t) = %d\n"</code><code class="cpp plain">, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(structa_t));</code></div>
<div class="line number45 index44 alt2"><code class="cpp spaces">   </code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"sizeof(structb_t) = %d\n"</code><code class="cpp plain">, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(structb_t));</code></div>
<div class="line number46 index45 alt1"><code class="cpp spaces">   </code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"sizeof(structc_t) = %d\n"</code><code class="cpp plain">, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(structc_t));</code></div>
<div class="line number47 index46 alt2"><code class="cpp spaces">   </code><code class="cpp functions bold">printf</code><code class="cpp plain">(</code><code class="cpp string">"sizeof(structd_t) = %d\n"</code><code class="cpp plain">, </code><code class="cpp keyword bold">sizeof</code><code class="cpp plain">(structd_t));</code></div>
<div class="line number48 index47 alt1"></div>
<div class="line number49 index48 alt2"><code class="cpp spaces">   </code><code class="cpp keyword bold">return</code> <code class="cpp plain">0;</code></div>
<div class="line number50 index49 alt1"><code class="cpp plain">}</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Before moving further, write down your answer on a paper, and read on. If you urge to see explanation, you may miss to understand any lacuna in your analogy. Also read the <a href="http://geeksforgeeks.org/forum/topic/what-is-the-output-2" target="_blank">post</a> by Kartik.</p>
<p><strong>Data Alignment:</strong></p>
<p>Every data type in C/C++ will have alignment requirement (infact it is mandated by processor architecture, not by language). A processor will have processing word length as that of data bus size. On a 32 bit machine, the processing word size will be 4 bytes.</p>
<p><a href="http://geeksforgeeks.org/wp-content/uploads/MemoryAlignment1.gif"><img class="aligncenter size-full wp-image-9731" src="http://geeksforgeeks.org/wp-content/uploads/MemoryAlignment1.gif" alt="" width="590" height="287" /></a></p>
<p>Historically memory is byte addressable and arranged sequentially. If the memory is arranged as single bank of one byte width, the processor needs to issue 4 memory read cycles to fetch an integer. It is more economical to read all 4 bytes of integer in one memory cycle. To take such advantage, the memory will be arranged as group of 4 banks as shown in the above figure.</p>
<p>The memory addressing still be sequential. If bank 0 occupies an address X, bank 1, bank 2 and bank 3 will be at (X + 1), (X + 2) and (X + 3) addresses. If an integer of 4 bytes is allocated on X address (X is multiple of 4), the processor needs only one memory cycle to read entire integer.</p>
<p>Where as, if the integer is allocated at an address other than multiple of 4, it spans across two rows of the banks as shown in the below figure. Such an integer requires two memory read cycle to fetch the data.</p>
<p><a href="http://geeksforgeeks.org/wp-content/uploads/MemoryAlignment2.gif"><img class="aligncenter size-full wp-image-9732" src="http://geeksforgeeks.org/wp-content/uploads/MemoryAlignment2.gif" alt="" width="420" height="123" /></a></p>
<p>A variable’s <em><strong>data alignment</strong></em> deals with the way the data stored in these banks. For example, the natural alignment of <em><strong>int</strong></em> on 32-bit machine is 4 bytes. When a data type is naturally aligned, the CPU fetches it in minimum read cycles.</p>
<p>Similarly, the natural alignment of <strong><em>short int</em></strong> is 2 bytes. It means, a <em><strong>short int</strong></em> can be stored in bank 0 – bank 1 pair or bank 2 – bank 3 pair. A <strong><em>double</em></strong> requires 8 bytes, and occupies two rows in the memory banks. Any misalignment of <strong><em>double</em></strong> will force more than two read cycles to fetch <strong><em>double</em></strong> data.</p>
<p>Note that a <strong>double</strong> variable will be allocated on 8 byte boundary on 32 bit machine and requires two memory read cycles. On a 64 bit machine, based on number of banks, <strong>double</strong> variable will be allocated on 8 byte boundary and requires only one memory read cycle.</p>
<p><strong>Structure Padding:</strong></p>
<p>In C/C++ a structures are used as data pack. It doesn’t provide any data encapsulation or data hiding features (C++ case is an exception due to its semantic similarity with classes).</p>
<p>Because of the alignment requirements of various data types, every member of structure should be naturally aligned. The members of structure allocated sequentially increasing order. Let us analyze each struct declared in the above program.</p>
<p><strong>Output of Above Program:</strong></p>
<p><strong><span style="color: #3366ff">For the sake of convenience, assume every structure type variable is allocated on 4 byte boundary (say 0×0000), i.e. the base address of structure is multiple of 4 (need not necessary always, see explanation of structc_t).</span></strong></p>
<p><strong><span style="color: #3366ff">structure A</span></strong></p>
<p><span style="color: #3366ff">The <em>structa_t</em> first element is <em>char</em> which is one byte aligned, followed by <em>short int</em>. short int is 2 byte aligned. If the the short int element is immediately allocated after the char element, it will start at an odd address boundary. The compiler will insert a padding byte after the char to ensure short int will have an address multiple of 2 (i.e. 2 byte aligned). The total size of structa_t will be sizeof(char) + 1 (padding) + sizeof(short), 1 + 1 + 2 = 4 bytes.</span></p>
<p><strong><span style="color: #3366ff">structure B</span></strong></p>
<p><span style="color: #3366ff">The first member of <em>structb_t</em> is short int followed by char. Since char can be on any byte boundary no padding required in between short int and char, on total they occupy 3 bytes. The next member is int. If the int is allocated immediately, it will start at an odd byte boundary. We need 1 byte padding after the char member to make the address of next int member is 4 byte aligned. On total, the <em>structb_t</em> requires 2 + 1 + 1 (padding) + 4 = 8 bytes.</span></p>
<p><span style="color: #808080"><strong><span style="color: #3366ff">structure C – Every structure will also have alignment requirements</span></strong></span></p>
<p><span style="color: #3366ff">Applying same analysis, <em>structc_t</em> needs sizeof(char) + 7 byte padding + sizeof(double) + sizeof(int) = 1 + 7 + 8 + 4 = 20 bytes. However, the sizeof(structc_t) will be 24 bytes. It is because, along with structure members, structure type variables will also have natural alignment. Let us understand it by an example. </span><span style="color: #3366ff">Say, we declared an array of structc_t as shown below</span></p>
<pre><span style="color: #3366ff">structc_t structc_array[3];</span></pre>
<p><span style="color: #3366ff">Assume, the base address of <em>structc_array</em> is 0×0000 for easy calculations. If the structc_t occupies 20 (0×14) bytes as we calculated, the second structc_t array element (indexed at 1) will be at 0×0000 + 0×0014 = 0×0014. It is the start address of index 1 element of array. The double member of this structc_t will be allocated on 0×0014 + 0×1 + 0×7 = 0x001C (decimal 28) which is not multiple of 8 and conflicting with the alignment requirements of double. As we mentioned on the top, the alignment requirement of double is 8 bytes.</span></p>
<p><span style="color: #3366ff">Inorder to avoid such misalignment, compiler will introduce alignment requirement to every structure. It will be as that of the largest member of the structure. In our case alignment of structa_t is 2, structb_t is 4 and structc_t is 8. If we need nested structures, the size of largest inner structure will be the alignment of immediate larger structure.</span></p>
<p><span style="color: #3366ff">In structc_t of the above program, there will be padding of 4 bytes after int member to make the structure size multiple of its alignment. Thus the sizeof (structc_t) is 24 bytes. It guarantees correct alignment even in arrays. You can cross check.</span></p>
<p><strong><span style="color: #3366ff">structure D - How to Reduce Padding?</span></strong></p>
<p><span style="color: #3366ff">By now, it may be clear that padding is unavoidable. There is a way to minimize padding. The programmer should declare the structure members in their increasing/decreasing order of size. An example is structd_t given in our code, whose size is 16 bytes in lieu of 24 bytes of structc_t.</span></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/structure-member-alignment-and-structure-padding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>foreground and background processes</title>
		<link>https://www.emblogic.com/blog/06/foreground-and-background-processes/</link>
		<comments>https://www.emblogic.com/blog/06/foreground-and-background-processes/#comments</comments>
		<pubDate>Mon, 09 Jun 2014 13:19:34 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10431</guid>
		<description><![CDATA[Background Process Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes. Within the limit of the amount of memory available, you can enter many background &#8230; <a href="https://www.emblogic.com/blog/06/foreground-and-background-processes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h3>Background Process</h3>
<p>Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes. Within the limit of the amount of memory available, you can enter many background commands one after another. To run a command as a background process, type the command and add a space and an ampersand to the end of the command. For example:</p>
<p>$ <i>command1 &amp;</i></p>
<p>Immediately after entering the above command, the shell will execute the command. While that is running in the background, the shell prompt (% for the C Shell, and $ for the Bourne Shell and the Korn Shell) will return. At this point, you can enter another command for either foreground or background process. Background jobs are run at a lower priority to the foreground jobs.</p>
<p>You will see a message on the screen when a background process is finished running.</p>
<h3>Foreground Process</h3>
<p>A foreground process is different from a background process in two ways:</p>
<p>1. Some foreground processes show the user an interface, through which the user can interact with the program.<br />
2. The user must wait for one foreground process to complete before running another one.</p>
<p>To start a foreground process, enter a command at the prompt, e.g.,</p>
<p>$ <i>command1</i></p>
<p>The next prompt will not appear until command1 finishes running.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/foreground-and-background-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Phony Targets, Macros and Special Characters in MAKEFILES</title>
		<link>https://www.emblogic.com/blog/06/phony-targets-macros-and-special-characters-in-makefiles/</link>
		<comments>https://www.emblogic.com/blog/06/phony-targets-macros-and-special-characters-in-makefiles/#comments</comments>
		<pubDate>Sat, 07 Jun 2014 12:35:24 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10400</guid>
		<description><![CDATA[Sometimes a target does not mean a file but it might represent an action to be performed. When a target  is not related to a file it is called phony target. For instance: getobj: mv obj/*.o . 2&#62;/dev/null getobj target move &#8230; <a href="https://www.emblogic.com/blog/06/phony-targets-macros-and-special-characters-in-makefiles/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2></h2>
<p>Sometimes a <strong>target</strong> does not mean a <strong>file</strong> but it might represent an action to be performed. When a <strong>target </strong> is not related to a file it is called <strong>phony target.</strong></p>
<p>For instance:</p>
<div id="premain6" class="pre-action-link"><span id="precollapse6" style="cursor: pointer;margin-bottom: 0pt"></span></div>
<pre id="pre6" style="margin-top: 0pt">getobj:
	mv obj<span class="code-comment">/*</span><span class="code-comment">.o .  2&gt;/dev/null</span></pre>
<p><strong>getobj</strong> <strong>target</strong> move all files with <strong>.o</strong> extension from <em>obj</em> directory to current directory &#8212; not a big deal. However, you should be asking yourself: &#8220;What if there is no file in <strong>obj</strong> ?&#8221; That is a good question. In that case, the <strong>mv</strong> command would return an error that would be passed to the <strong>make</strong> command.</p>
<p><strong>Note: make</strong> command default behavior is to abort the processing when an error is detected while executing commands in <strong>rules.</strong></p>
<p>Of course, there will be situations that the <em>obj </em>directory will be empty. How will you avoid the <strong>make</strong> command from aborting when an error happens?</p>
<p>You can use a special character <strong>-</strong> (minus) preceding the <strong>mv</strong> command. Thus:</p>
<div id="premain7" class="pre-action-link"><span id="precollapse7" style="cursor: pointer;margin-bottom: 0pt"></span></div>
<pre id="pre7" style="margin-top: 0pt">getobj:
	-mv obj/*.o .  2&gt;/dev/null</pre>
<p>- Tells the <strong>make</strong> to ignore errors. There is another special character: <strong>@ &#8211; </strong>Tells <strong>make</strong> not to print the command to standard output before executing. You can combine both always preceding the command:</p>
<div id="premain8" class="pre-action-link"><span id="precollapse8" style="cursor: pointer;margin-bottom: 0pt"></span></div>
<pre id="pre8" style="margin-top: 0pt">getobj:
	-@mv obj/*.o .  2&gt;/dev/null</pre>
<p>There is a special <strong>phony target</strong> called <strong>all </strong>where you can group several <strong>main targets</strong> and <strong>phony targets</strong>. <strong>all phony target </strong> is often used to lead <strong>make</strong> command while reading <strong>makefile</strong>.</p>
<p>For instance:</p>
<pre id="pre9" style="margin-top: 0pt">all: getobj app install putobj</pre>
<p>The <strong>make </strong>command will execute the <strong>targets</strong> in sequence: <strong>getobj, app, install </strong>and<strong> putobj</strong>.</p>
<p>Another interesting feature, <strong>make</strong> command supports is the concept of <strong>MACRO</strong> in <strong>makefiles</strong>. We can define a <strong>MACRO</strong> by writing:</p>
<div id="premain10" class="pre-action-link"><span id="precollapse10" style="cursor: pointer;margin-bottom: 0pt"></span></div>
<pre id="pre10" style="margin-top: 0pt">MACRONAME=value</pre>
<p>and access the value of MACRONAME by writing either $(MACRONAME) or ${MACRONAME}.</p>
<p>For instance:</p>
<div id="premain11" class="pre-action-link"><span id="precollapse11" style="cursor: pointer;margin-bottom: 0pt"></span></div>
<pre id="pre11" style="margin-top: 0pt">EXECPATH=./bin

INCPATH=./include

OBJPATH=./obj

CC=cc

CFLAGS=-g -Wall -I$(INCPATH)</pre>
<p>While executing, <strong>make</strong> replaces $(MACRONAME) with the appropriated definition. Now we know what <strong>phony targets</strong> and <strong>macros</strong> are we can move to the next sample.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/phony-targets-macros-and-special-characters-in-makefiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what does a makefile contain??</title>
		<link>https://www.emblogic.com/blog/06/what-does-a-makefile-contain/</link>
		<comments>https://www.emblogic.com/blog/06/what-does-a-makefile-contain/#comments</comments>
		<pubDate>Fri, 06 Jun 2014 09:52:22 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10350</guid>
		<description><![CDATA[A make file consists of a set of targets, dependencies and rules. A target most of time is a file to be created/updated. target depends upon a set of source files or even others targets described in Dependency List. Rules &#8230; <a href="https://www.emblogic.com/blog/06/what-does-a-makefile-contain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img src="http://www.codeproject.com/KB/cpp/makefiles_linux/lnxmk_01.jpg" alt="" width="439" height="258" border="0" /></p>
<p>A make file consists of a set of <strong>targets</strong>, <strong>dependencies </strong>and <strong>rules</strong>. A <strong>target</strong> most of time is a file to be created/updated. <strong>target</strong> depends upon a set of source files or even others <strong>targets</strong> described in <strong>Dependency List</strong>. <strong>Rules</strong> are the necessary commands to create the <strong>target</strong> file by using <strong>Dependency List</strong>.</p>
<p>As you see in <strong>figure 1</strong> each command in the <strong>Rules</strong> part must be on lines that start with a <strong>TAB</strong> character. Space issue errors. Also, a space at end of the <strong>rule</strong> line may cause <strong>make </strong>issues an error message.</p>
<p>The <strong>makefile</strong> is read by <strong>make </strong>command which determines <strong>target</strong> files to be built by comparing the dates and times (timestamp) of source files in <strong>Dependency</strong> <strong>List</strong>.If any dependency has a changed timestamp since the last build <strong>make</strong> command will execute the rule associated with the <strong>target</strong>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/what-does-a-makefile-contain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Process States</title>
		<link>https://www.emblogic.com/blog/06/process-states/</link>
		<comments>https://www.emblogic.com/blog/06/process-states/#comments</comments>
		<pubDate>Thu, 05 Jun 2014 08:16:05 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10333</guid>
		<description><![CDATA[  Linux processes generally go through six major states, which are listed below: 1. Running or Runnable ( R ) – A running state has a broader concept here. Running always does not mean utilising the CPU. Even while a &#8230; <a href="https://www.emblogic.com/blog/06/process-states/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2 class="western"><span style="text-decoration: underline"> </span></h2>
<p>Linux processes generally go through six major states, which are listed below:</p>
<p><strong>1</strong>. <span style="text-decoration: underline">Running or Runnable ( R )</span> – A running state has a broader concept here. Running always does not mean utilising the CPU. Even while a process is ready to run, the state is running state.</p>
<p>Hence, there are two sub-states, when the process is queued in the ready queue to run and when the process is actually being executed, it is in the executing sub-state as has been scheduled by the scheduler.</p>
<p><strong>2</strong>. <span style="text-decoration: underline">Stopped (T)</span> – If a running process receives a stop signal, it is moved to the stopped state. A process can also be in stopped state if it has been halted by a trace while debugging. .</p>
<p><strong>3</strong>. <span style="text-decoration: underline">Uninterruptible sleep (D)</span> – It is a sleeping state, process has been blocked. Mostly, process goes into an uninterruptible sleep during an IO operation.</p>
<p><strong>4</strong>. <span style="text-decoration: underline">Interruptible sleep (S)</span> – It is a sleeping state i.e. a blocking state where the process is waiting for an event to occur.</p>
<p><strong>5</strong>. <span style="text-decoration: underline">Zombie/Defunct state(Z)</span> – It is the process state in which process has been terminated but not reaped by its parent process.</p>
<p><strong>6</strong>. <span style="text-decoration: underline">Dead (X)</span> – A process never reaches this state, as as soon as it is dead, it is gone.</p>
<p><span style="text-decoration: underline">Note</span>: For BSD formats and when the <em>stat</em> keyword is used, additional characters may be displayed:</p>
<ul>
<li>
<p style="margin-bottom: 0in"><strong>&lt;</strong> high-priority (not nice to other users)</p>
</li>
<li>
<p style="margin-bottom: 0in"><strong>N</strong> low-priority (nice to other users)</p>
</li>
<li>
<p style="margin-bottom: 0in"><strong>L</strong> has pages locked into memory (for real-time and custom IO)</p>
</li>
<li>
<p style="margin-bottom: 0in"><strong>s</strong> is a session leader</p>
</li>
<li>
<p style="margin-bottom: 0in"><strong>l</strong> is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)</p>
</li>
<li><strong>+</strong> is in the foreground process group.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/process-states/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>points to remember about &#8216;extern&#8217; in C</title>
		<link>https://www.emblogic.com/blog/06/points-to-remember-about-extern-in-c/</link>
		<comments>https://www.emblogic.com/blog/06/points-to-remember-about-extern-in-c/#comments</comments>
		<pubDate>Tue, 03 Jun 2014 13:05:16 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10304</guid>
		<description><![CDATA[1. Declaration can be done any number of times but definition only once. 2. “extern” keyword is used to extend the visibility of variables/functions(). 3. Since functions are visible through out the program by default. The use of extern is &#8230; <a href="https://www.emblogic.com/blog/06/points-to-remember-about-extern-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>1. Declaration can be done any number of times but definition only once.</strong><br />
<strong> 2. “extern” keyword is used to extend the visibility of variables/functions().</strong><br />
<strong> 3. Since functions are visible through out the program by default. The use of extern is not needed in function declaration/definition. Its use is redundant.</strong><br />
<strong> 4. When extern is used with a variable, it’s only declared not defined.</strong><br />
<strong> 5. As an exception, when an extern variable is declared with initialization, it is taken as definition of the variable as well.</strong></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/points-to-remember-about-extern-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>an overview of how the system call in linux works</title>
		<link>https://www.emblogic.com/blog/05/an-overview-of-how-the-system-call-in-linux-works/</link>
		<comments>https://www.emblogic.com/blog/05/an-overview-of-how-the-system-call-in-linux-works/#comments</comments>
		<pubDate>Sat, 31 May 2014 12:33:28 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10251</guid>
		<description><![CDATA[0) There is global system_call_table which has offsets of every system call provided by the kernel (system call is just some function inside kernel). The global means every process share the same system_call_table 1) User software prepares arguments of the &#8230; <a href="https://www.emblogic.com/blog/05/an-overview-of-how-the-system-call-in-linux-works/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>0) There is global system_call_table which has offsets of every system call<br />
provided by the kernel (system call is just some function inside kernel). The global<br />
means every process share the same system_call_table<br />
1) User software prepares arguments of the system call, basically it puts them<br />
to the CPU registers<br />
2) User puts system call number to the appropriate CPU register (for example EAX)<br />
3) User passes control to VDSO page<br />
4) Code at this page executes either int $0&#215;80 or syscall CPU instruction and generates<br />
a special trap which is executed within kernel context.<br />
5) The trap handler extracts the system call number from EAX and checks that it is good.<br />
6) The trap handler prepares stack frame (put the values from register to stack)<br />
7) The trap handler calls the code from the system_call_table using value extracted<br />
at step 5 as an index in this table.<br />
8) The system_call_table code returns back to the trap handler code, the trap hander<br />
puts the returned value to the EAX and passes control back to the user space.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/an-overview-of-how-the-system-call-in-linux-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZOMBIE PROCESSES</title>
		<link>https://www.emblogic.com/blog/05/zombie-processes/</link>
		<comments>https://www.emblogic.com/blog/05/zombie-processes/#comments</comments>
		<pubDate>Tue, 27 May 2014 06:51:33 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10217</guid>
		<description><![CDATA[What is a Zombie Process ? It’s a pretty much common question asked in most of the interviews related to Linux, and most of the time people got it confused with Orphan Process. But these two are totally different from &#8230; <a href="https://www.emblogic.com/blog/05/zombie-processes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2 class="western">What is a Zombie Process ?</h2>
<p align="JUSTIFY">It’s a pretty much common question asked in most of the interviews related to Linux, and most of the time people got it confused with Orphan Process. But these two are totally different from each other. A Zombie Process is nearly the same thing which we see in lot of horror movies. Like the dead people which don’t have any life force left, Zombie processes are the dead processes sitting in the process table and doing nothing.</p>
<p align="JUSTIFY">To explain this in much better way, “Zombie process or defunct process is a process that have completed the execution, have released all the resources (CPU, memory) but still had an entry in the process table.”</p>
<h3 class="western" align="JUSTIFY">Reasons of Zombie Process:</h3>
<p align="JUSTIFY">Most of the time, the reason for existence of Zombie process is bad coding. Normally, when a child (subprocess) finishes it’s task and exits, then it’s parent is suppose to use the “wait” system call and get the status of the process. So, until the parent process don’t check for the child’s exit status, the process is a Zombie process, but it usually is very small duration. But if due to any reason (bad programming or a bug), the parent process didn’t check the status of the child and don’t call “wait”, the child process stays in the state of Zombie waiting for parent to check it’s status.</p>
<h3 class="western" align="JUSTIFY">Finding Zombie processes:</h3>
<p align="JUSTIFY">To check whether you have any Zombie processes in your system, simply run linux command line utility “top”. It shows the number of zombie processes at the upper-right side of its output.</p>
<p align="JUSTIFY">At the same time, you can use one more command to check that</p>
<pre class="western" style="margin-bottom: 0.2in;text-align: justify"># ps aux</pre>
<p align="JUSTIFY">All the processes which are having “z” in their Stat column are Zombie processes.</p>
<h3 class="western" align="JUSTIFY">Killing a Zombie Process:</h3>
<p align="JUSTIFY">Well, before taking any decision of killing the Zombie process, you should wait, as it is possible that the parent process is intentionally leaving the process in a zombie state to ensure that future children that it may create will not receive the same pid. Or perhaps the parent is occupied, and will reap the child process momentarily.</p>
<p align="JUSTIFY">If that didn’t happen then you can send a SIGCHLD signal to the parent process of zombie which will instruct parents to reap their zombie children.</p>
<pre class="western" style="margin-bottom: 0.2in;text-align: justify"># kill -s SIGCHLD &lt;PPID&gt;</pre>
<p align="JUSTIFY">Even if this don’t work, then the last option you will have is to kill the parent process. You can easily find out the parent’s process ID with this command:</p>
<pre class="western" style="text-align: justify"># ps aux -eo ppid | grep &lt;Zombie Process ID&gt;
# kill -9 &lt;PPID&gt;</pre>
<p align="JUSTIFY">So when a Zombie process loses it’s parent process, it becomes orphan and adopted by “init”. Init periodically executes the wait system call to reap any zombies with init as parent.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/zombie-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>https://www.emblogic.com/blog/05/10085/</link>
		<comments>https://www.emblogic.com/blog/05/10085/#comments</comments>
		<pubDate>Tue, 13 May 2014 11:06:58 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Project 6: Client Server using Inter Process Communication Mechanism]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10085</guid>
		<description><![CDATA[                What are  processes and threads?? A process is a program (object code stored on some media) in execution.  Processes are, however, more than just the executing program code (often called the text &#8230; <a href="https://www.emblogic.com/blog/05/10085/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><span style="font-family: Georgia, Times New Roman, serif;font-size: large"><b>    </b></span><br />
<span style="font-family: Georgia, Times New Roman, serif;font-size: large"><b><br />
</b></span> <span style="font-family: Georgia, Times New Roman, serif;font-size: large"><b>            What are  processes and threads??</b></span><br />
<span style="font-family: Georgia, Times New Roman, serif;font-size: large"><b><br />
</b></span> <span style="font-family: Georgia, Times New Roman, serif;font-size: large"><b><br />
</b></span></p>
<div class="docText"></div>
<ul style="text-align: left">
<li>A process is a program (object code stored on some media) in execution.</li>
<li> Processes are, however, more than just the executing program code (often called the <span class="docEmphasis">text section</span> in Unix). They also include a set of resources such as open files and pending signals, internal kernel data, processor state, an address space, one or more <span class="docEmphasis">threads of execution,</span> and a <span class="docEmphasis">data section</span> containing global variables. Processes, in effect, are the living result of running program code.</li>
</ul>
<div></div>
<div></div>
<ul style="text-align: left">
<li>Threads of execution, often shortened to <span class="docEmphasis">threads</span>, are the objects of activity within the process.</li>
<li> Each thread includes a unique program counter, process stack, and set of processor registers. The kernel schedules individual threads, not processes.</li>
<li> In traditional Unix systems, each process consists of one thread. In modern systems, however, multithreaded programs those that consist of more than one thread are common.</li>
<li> But,to Linux, a thread is just a special kind of process.</li>
<li>People generally are confused that a program is a process but a process is an <span class="docEmphasis">active</span> program and related resources. Indeed, two or more processes can exist that are executing the <span class="docEmphasis">same</span> program. In fact, two or more processes can exist that share various resources, such as open files or an address space.</li>
<li>A process begins its life when, not surprisingly, it is created. In Linux, this occurs by means of the <tt>fork()</tt> system call, which creates a new process by duplicating an existing one.</li>
<li><span style="background-color: white;line-height: 19.600000381469727px"><span style="font-family: Georgia, Times New Roman, serif">The new process is an exact copy of the old process. (Now, a question might come immediately to our mind- who creates the first process?? The first process is the init process which is literally created from scratch during booting).</span></span></li>
<li>The process that calls <tt>fork()</tt> is the <span class="docEmphasis">parent,</span> whereas the new process is the <span class="docEmphasis">child</span>. The parent resumes execution and the child starts execution at the same place, where the call returns. The <tt>fork()</tt> system call returns from the kernel twice: once in the parent process and again in the newborn child.</li>
<li>Often, immediately after a fork it is desirable to execute a new, different, program. The <tt>exec</tt><span class="docEmphasis"><tt>*</tt></span><tt>()</tt> family of function calls is used to create a new address space and load a new program into it. In modern Linux kernels, <tt>fork()</tt> is actually implemented via the <tt>clone()</tt> system call,</li>
<li>Finally, a program exits via the <tt>exit()</tt> system call. This function terminates the process and frees all its resources.</li>
<li>A parent process can inquire about the status of a terminated child via the <tt>wait4()</tt>system call, which enables a process to wait for the termination of a specific process.</li>
<li> When a process exits, it is placed into a special zombie state that is used to represent terminated processes until the parent calls <tt>wait()</tt> or <tt>waitpid()</tt>.</li>
<li>The kernel implements the <span class="docEmphasis"><tt>wait4()</tt></span> system call. Linux systems, via the C library, typically provide the <span class="docEmphasis"><tt>wait()</tt>,<tt>waitpid()</tt>,<tt>wait3()</tt></span> , and <span class="docEmphasis"><tt>wait4()</tt></span> functions. All these functions return status about a terminated process, albeit with slightly different semantics.</li>
<li>Another name for a process is a <span class="docEmphasis">task</span>.  although when we say <span class="docEmphasis">task</span> we generally mean a process from the kernel&#8217;s point of view</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/10085/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>https://www.emblogic.com/blog/05/10074/</link>
		<comments>https://www.emblogic.com/blog/05/10074/#comments</comments>
		<pubDate>Tue, 13 May 2014 08:55:35 +0000</pubDate>
		<dc:creator><![CDATA[deepanshuemblinux]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10074</guid>
		<description><![CDATA[Kernel Space and User Space Understanding of Kernel space and User space in detail is very important if you wish to have a strong base of Linux Kernel. Here Kernel Space and User Space corresponds to their Virtual address space. &#8230; <a href="https://www.emblogic.com/blog/05/10074/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<blockquote>
<h3 class="post-title entry-title"><em>Kernel Space and User Space</em></h3>
</blockquote>
<div class="post-header"></div>
<p>Understanding of Kernel space and User space in detail is very important if you wish to have a strong base of Linux Kernel.</p>
<ul style="text-align: left">
<li>Here Kernel Space and User Space corresponds to their Virtual address space.</li>
<li>Every process in linux utilizes  its own separate virtual space.</li>
<li>In a linux system based on 32 bit Architecture, user space address space corresponds to lower 3GB of virtual space and kernel space the upper 1GB.(general way)</li>
<li>The kernel space virtual address space is shared between all the processes.</li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif">When a process is active, it can either be running in &#8220;user mode&#8221; or &#8220;kernel mode&#8221;.</span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif">In a process is running in User mode it means that the CPU is running the user space side of code.</span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif">A process running in the user mode has limited capability and is controlled by a flag in the CPU.</span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif">Even though the kernel memory is present in the process&#8217;s memory map the user space code is not allowed to access the kernel space code.(can do in some special way).</span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif">When a process wants to do something other than move data around in its own (userspace) virtual memory, like opening a file for example, it must make a syscall to communicate with the kernel space.</span></span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif">Each CPU architecture has it&#8217;s unique way of making a system call but the basic remains the same i.e.</span></span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif">A magic instruction is executed, the CPU turns on the &#8220;privileged mode&#8221; flag, and jumps to a special address in kernel space, the &#8220;syscall entry point&#8221;.( read another post to understand what syscall is)</span></span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif">Now when the syscall has reached the kernel space then the process is running in kernel mode and executing instructions from the kernel space memory.</span></span></span></li>
<li><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px"><span style="font-family: Georgia, Times New Roman, serif"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif">Taking the same example of open system call, t</span></span></span><span style="background-color: white;font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;font-size: 14px;line-height: 17.804800033569336px">o find the requested file, the kernel may consult with filesystem drivers (to figure out where the file is) and block device drivers (to load the necessary blocks from disk) or network device drivers and protocols (to load the file from a remote source).</span></li>
<li><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px">These drivers can be either built in or can be loaded as module but the key point that remains it that they are the part of kernel space.</span></span></li>
<li><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px">Loading a module is done with a syscall that asks the kernel to copy the module&#8217;s code and data into kernel space and run its initialization code in kernel mode.</span></span></li>
<li><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px">If the kernel can&#8217;t process the request then the process is made to sleep by the kernel and when the request is complete then the syscall returns back to the user space.</span></span></li>
<li><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="background-color: white;font-size: 14px;line-height: 17.804800033569336px">Returning back to user mode means restoring the CPU registers to what they were before coming to Kernel Mode and changing the CPU privilege level to non-privilege .</span></span></li>
<li><span style="background-color: white;font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;font-size: 14px;line-height: 17.804800033569336px">Apart from syscalls there are some other things that take CPU to kernel mode eg. </span></li>
</ul>
<div><span style="background-color: white;font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;font-size: 14px;line-height: 17.804800033569336px"> </span></div>
<p><span style="background-color: white;font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;font-size: 14px;line-height: 17.804800033569336px">1. Page faults- If the process tries to access a virtual memory address that doesn&#8217;t have a physical address assigned to it then the CPU enters the Kernel mode  and jumps to page fault handler and the kernel sees whether the virtual addresss is valid or not and depending upon this it either tries to create a physical page for the given virtual address or if it can&#8217;t then sends a segmentation fault signal (SIGSEGV).</span></p>
<div><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="font-size: 14px;line-height: 17.804800033569336px"> </span></span></div>
<div><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="font-size: 14px;line-height: 17.804800033569336px">2. Interrupts- When the CPU receives some interrupt from the hardware then it jumps to the kernel mode and executes the interrupt handler and when the kernel is finished handing the interrupt the the code return to the user space where it was executing.</span></span></div>
<p><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif"><span style="font-size: 14px;line-height: 17.804800033569336px"><br />
</span></span></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/10074/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
