<?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; Linux Internals and System Programming</title>
	<atom:link href="https://www.emblogic.com/blog/category/lisp/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>How to Send a signal -Using Kill command</title>
		<link>https://www.emblogic.com/blog/01/how-to-send-a-signal-using-kill-command/</link>
		<comments>https://www.emblogic.com/blog/01/how-to-send-a-signal-using-kill-command/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 12:01:08 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[ipc]]></category>
		<category><![CDATA[kill]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[linux system programming]]></category>
		<category><![CDATA[pid]]></category>
		<category><![CDATA[sending signals]]></category>
		<category><![CDATA[signal]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13175</guid>
		<description><![CDATA[Send a signal by Kill command ======================= - To send a signal to a process other than current task. - It has prototype :- int kill(pid_t pid, int signo); - It is included using header :- #include&#60;signal.h&#62; - The system &#8230; <a href="https://www.emblogic.com/blog/01/how-to-send-a-signal-using-kill-command/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Send a signal by Kill command<br />
=======================<br />
- To send a signal to a process other than current task.<br />
- It has prototype :-<br />
int kill(pid_t pid, int signo);<br />
- It is included using header :-<br />
#include&lt;signal.h&gt;<br />
- The system data type pid_t is defined in header :-<br />
#include&lt;sys/types.h&gt;<br />
- signo is the signal number of signal to be send.<br />
- pid is the PID of the process to which signal is to be send.<br />
- pid can take value:-<br />
* 0 &#8211;&gt; To send signo signal to every process in invoking process&#8217; process group<br />
* -1 &#8211;&gt;To send signo signal to every process for which invoking process has permission to send a signal, except itself and init<br />
* n(&lt;-1) &#8211;&gt; All process in process group<br />
* n(&gt;0)  &#8211;&gt; process with PID n is signalled.<br />
- This take an optional signal name or number and the PID to send the signal.</p>
<p>- For eg. To send &#8216;hangup&#8217; signal to shell running on PID 1001, we use command :-<br />
kill(1001,HUP);<br />
- killall is used to send signal to all the processes running.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/how-to-send-a-signal-using-kill-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to register a signal</title>
		<link>https://www.emblogic.com/blog/01/how-to-register-a-signal/</link>
		<comments>https://www.emblogic.com/blog/01/how-to-register-a-signal/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 11:59:04 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[ipc]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[linux system programming]]></category>
		<category><![CDATA[register a signal]]></category>
		<category><![CDATA[signals]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13173</guid>
		<description><![CDATA[Register a signal ================== - Program can handle a signal using signal library function signal(). - signal() is used to register the signal handler function with kernel on behalf of current process. - It is included in header :- #include&#60;header.h&#62; &#8230; <a href="https://www.emblogic.com/blog/01/how-to-register-a-signal/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Register a signal<br />
==================<br />
- Program can handle a signal using signal library function signal().<br />
- signal() is used to register the signal handler function with kernel on behalf of current process.<br />
- It is included in header :-<br />
#include&lt;header.h&gt;<br />
- Prototype of function is :-<br />
void* (signal(int signo,void(*func)(int)))(int);<br />
- signal() function takes 2 parameters, signo and func.<br />
- The signal to be caught or ignored is given as argument signo.<br />
- The function to be called when the specified signal is received is given as func.<br />
- The function must take a single int argument (the signal received) and has return type void.</p>
<p>- The signal() command can be used in 3 modes :-<br />
(i) Default mode (Terminate the process)<br />
SIG_DFL &#8211;&gt; is used in place of func.<br />
(ii) Ignore the signal<br />
SIG_IGN &#8211;&gt; is used in place of func.<br />
(iii) User defined mode<br />
User defined function is used in place of func.</p>
<p>- The signal command returns the function which is setup to handle the signal, SIG_DFL or SIG_IGN in 3rd, 1st and 2nd cases respectively.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/how-to-register-a-signal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About Signals</title>
		<link>https://www.emblogic.com/blog/01/about-signals/</link>
		<comments>https://www.emblogic.com/blog/01/about-signals/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 11:57:12 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[ipc]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13171</guid>
		<description><![CDATA[Signals ======== - A signal is an event generated by UNIX/LINUX system in response to some condition. - On receipt of a signal, process may in turn take some action. - Signals are generated by some error conditions such as:- &#8230; <a href="https://www.emblogic.com/blog/01/about-signals/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Signals<br />
========<br />
- A signal is an event generated by UNIX/LINUX system in response to some condition.<br />
- On receipt of a signal, process may in turn take some action.<br />
- Signals are generated by some error conditions such as:-<br />
* Memory Segment Violation<br />
* Floating Point Processor error<br />
* Illegal Instruction etc.<br />
- They are generated by shell and terminal handlers.<br />
- They cause interrupts.</p>
<p>- They can also be used to sent from one process to another as a way of passing information or modifying behaviour.</p>
<p>- As default, if a process receives any signal, process will be terminated immediately.<br />
- Usually a core dump file is created.</p>
<p>- The signals are defined by including header file signal.h<br />
- They all begn with &#8220;SIG&#8221;.<br />
- There are 64 signals in LINUX.<br />
- The can be listed using command :-<br />
kill -l<br />
- Some of the signals are :-</p>
<p>Signal Name       Description<br />
SIGABORT          Process Abort<br />
SIGALRM           Alarm Clock<br />
SIGFPE            Floating Point Exception<br />
SIGHUP            Hangup<br />
SIGILL            Illegal Instruction<br />
SIGINT            Terminal Interrupt<br />
SIGKILL           Kill (can&#8217;t be caught or ignored)<br />
SIGPIPE           Write on a pipe with no reader<br />
SIGQUIT           Terminal Quit<br />
SIGSEGV           Invalid memory segment access (Segmentation Fault)<br />
SIGTERM           Termination<br />
SIGUSR1           User-defined signal 1<br />
SIGUSR2           User-defined signal 2</p>
<p>SIGCHLD           Child process has stopped or exited<br />
SIGCONT           Continue exexuting, if stopped<br />
SIGSTOP           Stop Executing (Can&#8217;t be caught or ignored)<br />
SIGTSTP           Terminal stop signal<br />
SIGTTIN           Background process trying to read<br />
SIGTTOU           Background process trying to write</p>
<p>- SIGINT can be called using Ctrl-C<br />
- A signal has 3 steps:-<br />
1) raise<br />
2) catch<br />
3) ignore/handle</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/about-signals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replacing a Process Image</title>
		<link>https://www.emblogic.com/blog/01/replacing-a-process-image/</link>
		<comments>https://www.emblogic.com/blog/01/replacing-a-process-image/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:40:34 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[execl]]></category>
		<category><![CDATA[execv]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[process replacement]]></category>
		<category><![CDATA[Replacing a Process Image]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13167</guid>
		<description><![CDATA[Replacing a Process Image ========================= - The exec function replaces current process with a new process. - The path of new process is specified as argument to exec. - It is defined in header : #include&#60;unistd.h&#62; - Last argument of &#8230; <a href="https://www.emblogic.com/blog/01/replacing-a-process-image/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Replacing a Process Image<br />
=========================<br />
- The exec function replaces current process with a new process.<br />
- The path of new process is specified as argument to exec.<br />
- It is defined in header :<br />
#include&lt;unistd.h&gt;<br />
- Last argument of function should be NULL.<br />
- It has 6 types of functions, whose prototype are :-<br />
(i) Complete path is specified<br />
int execl(const char * path, const char * arg0,const char * arg1,&#8230;,NULL);<br />
(ii) If file is at one of default paths<br />
int execlp(const char * file, const char * arg0,const char * arg1,&#8230;,NULL);<br />
(iii) If arguments are given as an vector(array)<br />
int execv(const char *path,char *const argv[]);<br />
(iv) If arguments are given as an vector(array) and file is at one of default paths<br />
int execvp(const char* file, char *const argv[]);<br />
(v) int execle(const char *path, const char * arg0, const char * arg1,&#8230;,NULL, char *const envp[]);<br />
(vi) int execve(const char *path, char *const argv[],char *const envp[] );</p>
<p>- The suffix p means to search PATH environmental variable.</p>
<p>- If the exec is executed successfully the statements after it will not be executed.<br />
- It is because the current process is replaced.<br />
- The arguments given to exec are used by main() function of new process as command line argument.<br />
- If exec fails, it returns -1<br />
- The open file descriptors remain open after the exec command.<br />
- These file descriptors can be passed to exec as command and can be used by the replaced process to read/write from opened file.<br />
- The argument is passed to exec as character.<br />
- For this sprintf() is used.<br />
- And for getting the file descriptors back , atoi() or integer typecasting can be used on the arguments of main().</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/replacing-a-process-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Orphan Process</title>
		<link>https://www.emblogic.com/blog/01/orphan-process/</link>
		<comments>https://www.emblogic.com/blog/01/orphan-process/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:39:03 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[orphan]]></category>
		<category><![CDATA[orphan process]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13165</guid>
		<description><![CDATA[Orphan Process =============== If in a process, the parent process is terminated before the child process, the child process become orphan - It takes the lowest possible process as its parent - And its PPID is changed to the PID &#8230; <a href="https://www.emblogic.com/blog/01/orphan-process/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Orphan Process<br />
===============<br />
If in a process, the parent process is terminated before the child process, the child process become orphan<br />
- It takes the lowest possible process as its parent<br />
- And its PPID is changed to the PID of its new parent process.<br />
- Mostly the new parent process in init process (PID = 1).<br />
- It is because init adopts the orphan process.<br />
- The child is then terminated normally by the init process.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/orphan-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zombie or Defunct Process</title>
		<link>https://www.emblogic.com/blog/01/zombie-or-defunct-process/</link>
		<comments>https://www.emblogic.com/blog/01/zombie-or-defunct-process/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:37:43 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[defunct]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[zombie]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13163</guid>
		<description><![CDATA[Zombie or Defunct Process ========================== If a child proces tries to teminate,its association with parent remains until the parent terminates normally or calls wait. - The child process entry in process table is therfore not freed up immediately. - Althougth &#8230; <a href="https://www.emblogic.com/blog/01/zombie-or-defunct-process/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Zombie or Defunct Process<br />
==========================<br />
If a child proces tries to teminate,its association with parent remains until the parent terminates normally or calls wait.<br />
- The child process entry in process table is therfore not freed up immediately.<br />
- Althougth the process is no longer active, the child remains still in system because its exit code is needed to be stored in case of parent subsequently</p>
<p>calls wait.<br />
- The process becomes defunct or zombie process.<br />
- It is shown by &#8216;Z&#8217; or &#8216;Z+&#8217; in process table.</p>
<p>- If the parent is terminated abnormally, the zombie child process will not be terminated (which is not good).</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/zombie-or-defunct-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>waiting for a process</title>
		<link>https://www.emblogic.com/blog/01/waiting-for-a-process/</link>
		<comments>https://www.emblogic.com/blog/01/waiting-for-a-process/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:36:05 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[wait]]></category>
		<category><![CDATA[waiting for a process]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13160</guid>
		<description><![CDATA[Waiting For a Process ===================== - Sometime we would like to find out when a child process has finished. - It is needed for parent process to wait until the child finishes before continuing by calling wait. - It has &#8230; <a href="https://www.emblogic.com/blog/01/waiting-for-a-process/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Waiting For a Process<br />
=====================<br />
- Sometime we would like to find out when a child process has finished.<br />
- It is needed for parent process to wait until the child finishes before continuing by calling wait.<br />
- It has prototype :<br />
pid_t wait(int *stat_loc);<br />
- It is declared in header :<br />
#include&lt;sys/wait.h&gt;<br />
- It has a return type pid_t which is declared in header :<br />
#include&lt;sys/types.h&gt;<br />
- The wait system call causes a parent process to pause until one of its child processes is stopped.<br />
- The wait returns PID of child process which is terminated.<br />
- The status information determine the exit status of child process (i.e  value returned from main or passed to exit)<br />
- If stat_loc is not a null pointer, the status information will be written to location to which it points.<br />
- The status information can be determined by using macros defined in header sys/wait.h</p>
<p>Macro                                        Defination<br />
WIFEXITED(stat_val)          Nonzero if child terminated normally<br />
WEXITSTATUS(stat_val)    If WIFEXITED is nonzero, this returns child exit code</p>
<p>WIFSIGNALED(stat_val)    Nonzero if child is terminated on an uncaught signal<br />
WTERMSIG(stat_val)           If WIFSIGNALED is nonzero, this returns signal number</p>
<p>WIFSTOPPED(stat_val)       Nonzero if the child has stopped<br />
WSTOPSIG(stat_val)            If WIFSTOPPED is nonzero, this returns signal number</p>
<p>- The wait() is used when a result of process done by child is used by the parent for further processing.<br />
- For eg :-<br />
In a program child process write to file1 and parent has to read from (the written data of)file1.<br />
If the scheduler runs read() command of the parent process before the write() command of child process, it reads nothing.<br />
- So, wait() is used before read() statement in parent process to avoid the unnecessory error.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/waiting-for-a-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Process Duplication using fork</title>
		<link>https://www.emblogic.com/blog/01/process-duplication-using-fork/</link>
		<comments>https://www.emblogic.com/blog/01/process-duplication-using-fork/#comments</comments>
		<pubDate>Fri, 15 Jan 2016 10:28:24 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>
		<category><![CDATA[c programming]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[process duplication]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13158</guid>
		<description><![CDATA[Process Duplication using system call fork ============================== - A new process is created using fork(). - fork() is a system call. - fork duplicates the current process. - It creates a new entry in the process table with many of &#8230; <a href="https://www.emblogic.com/blog/01/process-duplication-using-fork/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Process Duplication using system call fork<br />
==============================<br />
- A new process is created using fork().<br />
- fork() is a system call.<br />
- fork duplicates the current process.<br />
- It creates a new entry in the process table with many of same</p>
<p>attributes as current process.<br />
- The new process (known as child process) is almost identical to</p>
<p>original process (known as parent process).<br />
- PPID (Parent Process Identification) of new process is PID of</p>
<p>original process.<br />
- PID (Process Identification) of new process is lowest PID</p>
<p>available after the PID of original process .Mostly it is 1 greater</p>
<p>than the original process(If available).<br />
- Prototype of fork :-<br />
pid_t fork(void);<br />
- Function fork() is declared in header:<br />
#include&lt;unistd.h&gt;<br />
- It has a return type pid_t .<br />
- System type pid_t is declared in header :<br />
#include&lt;sys/types.h&gt;<br />
- The Process counter of new process starts from fork() statement.<br />
- So, fork() is executed twice.<br />
- When fork() is executed by parent, it returns PID of child</p>
<p>process on success.<br />
- When fork() is executed by child, it returns 0 for success.<br />
- If fork fails, it returns -1.<br />
- Falure may be due to :-<br />
* Limit on the number of child processes that a parent may</p>
<p>have (CHILD_MAX), in which errno will be set to &#8220;EAGAIN&#8221;</p>
<p>* If process table or virtual memory is filled (not enough</p>
<p>space), errno variable will be set to &#8220;ENOMEM&#8221;.<br />
- The return value of fork() can be used to determine whether child</p>
<p>or parent is executing.<br />
- For eg. :-<br />
#include&lt;stdio.h&gt;<br />
#include&lt;unistd.h&gt;<br />
#include&lt;sys/types.h&gt;<br />
int main()<br />
{<br />
pid_t fret;<br />
printf(&#8220;Only parent execute\n&#8221;);<br />
fret = fork();//Fork statement<br />
printf(&#8220;Both parent and child execute this statement.\n&#8221;);<br />
switch(fork)<br />
{<br />
case -1 :<br />
perror(&#8220;fork&#8221;);<br />
exit(EXIT_FAILURE);<br />
break;<br />
case 0 :<br />
printf(&#8220;Child executing\n&#8221;);<br />
break;<br />
default :<br />
printf(&#8220;Parent executing\n&#8221;);<br />
break;<br />
}<br />
return 0;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/01/process-duplication-using-fork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>THE LINUX FIRE WALL</title>
		<link>https://www.emblogic.com/blog/03/the-linux-fire-wall/</link>
		<comments>https://www.emblogic.com/blog/03/the-linux-fire-wall/#comments</comments>
		<pubDate>Thu, 26 Mar 2015 12:47:56 +0000</pubDate>
		<dc:creator><![CDATA[saurabh.aggarwal]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Project 00: Linux System / Network Administration]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=12480</guid>
		<description><![CDATA[&#160; If we talk about firewall the first thing that comes to our mind is a software &#8220;Barrier&#8221; between a system and a network it may be either internal or external. The purpose of this software is to protect our &#8230; <a href="https://www.emblogic.com/blog/03/the-linux-fire-wall/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>If we talk about firewall the first thing that comes to our mind is a software &#8220;Barrier&#8221; between a system and a network it may be either internal or external. The purpose of this software is to protect our system from various threats. This network security system, can be used to control incoming and outgoing network traffic based on a specific set of rules. This firewall can be used in various devices like routers .</p>
<p>Now if we talk about it is a kernel (or in other word a piece of software )acting on hardware.</p>
<p>So the kernel provides us with XTABLES which stores chins and all the rule ,act as a firewall in system. XTABLE consist of different modules for different protocols. The various modules are:-</p>
<p>1 &gt; iptables applies to IPv4</p>
<p>2&gt; ip6tables to IPv6</p>
<p>3&gt; arptables to ARP</p>
<p>4&gt; ebtables for Ethernet frames</p>
<p>SO our current focus will be on iptables ,what is IPTABLES ???</p>
<p>Its a built in firewall application fro configuring the tables provided by the LINUX KERNEL FIREWALL . Two major things associated with these utilities or application are its chain and rule.</p>
<p>iptables is command that uses the concept of chains to handle the network traffic .It places the rules into chains which are checked against the network traffic.Decisions are made as to what to do with the packets based on these rules (i.e whether the packet should be accepted or dropped). The predefined chains  are as follows</p>
<p><code>PREROUTING</code>: Packets will enter this chain before a routing decision is made.</p>
<p><code>INPUT</code>: Packet is going to be locally delivered. It does not have anything to do with processes having an opened socket; local delivery is controlled by the &#8220;local-delivery&#8221; routing table: <code>ip route show table local</code>.</p>
<p><code>FORWARD</code>: All packets that have been routed and were not for local delivery will traverse this chain.</p>
<p><code>OUTPUT</code>: Packets sent from the machine itself will be visiting this chain.</p>
<p><code>POSTROUTING</code>: Routing decision has been made. Packets enter this chain just before handing them off to the hardware.</p>
<p>Tables associated with Iptables are :-</p>
<p>Filter table , NAT table, Raw Table, Mangle Table</p>
<p>Rules are :- ACCEPT , DROP, QUEUE, RETURN</p>
<p>Their are various flags associated with iptables like</p>
<p>-A      to add a rule</p>
<p>-p      to indicate the protocol</p>
<p>-s       to indicate the source of packet</p>
<p>-d      to indicate the destination</p>
<p>-dport    port number of the destination port</p>
<p>-sport     port number of the source port</p>
<p>their are various other flags for which u can refer the man page</p>
<p>You can use the iptables service using command:-</p>
<p><strong>service iptables</strong> start/stop/restart/status</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/the-linux-fire-wall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inter process communication using pipe successfully done.</title>
		<link>https://www.emblogic.com/blog/02/inter-process-communication-using-pipe-successfully-done/</link>
		<comments>https://www.emblogic.com/blog/02/inter-process-communication-using-pipe-successfully-done/#comments</comments>
		<pubDate>Fri, 27 Feb 2015 11:02:45 +0000</pubDate>
		<dc:creator><![CDATA[Amardeep Rawat]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=12321</guid>
		<description><![CDATA[RCS file: header.h,v Working file: header.h head: 1.2 branch: locks: strict root: 1.2 access list: symbolic names: keyword substitution: kv total revisions: 2; selected revisions: 2 description: This is header file include stdio.h stdlib.h sys/types.h unistd.h &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.2 locked &#8230; <a href="https://www.emblogic.com/blog/02/inter-process-communication-using-pipe-successfully-done/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.2<br />
branch:<br />
locks: strict<br />
	root: 1.2<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 2;	selected revisions: 2<br />
description:<br />
This is header file<br />
include stdio.h stdlib.h sys/types.h unistd.h<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2	locked by: root;<br />
date: 2015/02/27 10:26:23;  author: root;  state: Exp;  lines: +5 -1<br />
define struct message<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/27 09:26:47;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>RCS file: adder.c,v<br />
Working file: adder.c<br />
head: 1.4<br />
branch:<br />
locks: strict<br />
	root: 1.4<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 4;	selected revisions: 4<br />
description:<br />
this is adder.c file<br />
execl will run this process<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4	locked by: root;<br />
date: 2015/02/27 10:53:04;  author: root;  state: Exp;  lines: +12 -5<br />
write sum into pipe through wfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2015/02/27 10:27:33;  author: root;  state: Exp;  lines: +5 -0<br />
read struct message m through rfd.<br />
print each element of m<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2015/02/27 09:55:22;  author: root;  state: Exp;  lines: +4 -2<br />
pass rfd to execl<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/27 09:46:47;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>RCS file: main.c,v<br />
Working file: main.c<br />
head: 1.8<br />
branch:<br />
locks: strict<br />
	root: 1.8<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 8;	selected revisions: 8<br />
description:<br />
This is main.c<br />
child process is created using fork<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8	locked by: root;<br />
date: 2015/02/27 10:54:13;  author: root;  state: Exp;  lines: +2 -0<br />
close rfd and wfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2015/02/27 10:52:25;  author: root;  state: Exp;  lines: +6 -4<br />
read pipe through rfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2015/02/27 10:26:56;  author: root;  state: Exp;  lines: +9 -2<br />
write struct message m to wfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2015/02/27 09:55:15;  author: root;  state: Exp;  lines: +3 -1<br />
print rfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2015/02/27 09:46:33;  author: root;  state: Exp;  lines: +1 -1<br />
print hello.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2015/02/27 09:30:46;  author: root;  state: Exp;  lines: +4 -3<br />
print the rfd and wfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2015/02/27 09:27:38;  author: root;  state: Exp;  lines: +2 -1<br />
create a pipe<br />
print rfd and wfd<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/27 09:22:38;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/02/inter-process-communication-using-pipe-successfully-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>inter process communication using file successfully done.</title>
		<link>https://www.emblogic.com/blog/02/inter-process-communication-is-successfully-done/</link>
		<comments>https://www.emblogic.com/blog/02/inter-process-communication-is-successfully-done/#comments</comments>
		<pubDate>Thu, 26 Feb 2015 15:01:43 +0000</pubDate>
		<dc:creator><![CDATA[Amardeep Rawat]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=12313</guid>
		<description><![CDATA[RCS file: header.h,v Working file: header.h head: 1.2 branch: locks: strict root: 1.2 access list: symbolic names: keyword substitution: kv total revisions: 2; selected revisions: 2 description: Header file &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.2 locked by: root; date: 2015/02/26 14:25:18; author: root; &#8230; <a href="https://www.emblogic.com/blog/02/inter-process-communication-is-successfully-done/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.2<br />
branch:<br />
locks: strict<br />
	root: 1.2<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 2;	selected revisions: 2<br />
description:<br />
Header file<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2	locked by: root;<br />
date: 2015/02/26 14:25:18;  author: root;  state: Exp;  lines: +2 -2<br />
include  </p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/26 14:24:00;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>RCS file: replace.c,v<br />
Working file: replace.c<br />
head: 1.5<br />
branch:<br />
locks: strict<br />
	root: 1.5<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 5;	selected revisions: 5<br />
description:<br />
replace file<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5	locked by: root;<br />
date: 2015/02/26 14:50:03;  author: root;  state: Exp;  lines: +1 -1<br />
read from file<br />
print file content<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2015/02/26 14:45:12;  author: root;  state: Exp;  lines: +18 -18<br />
open a file<br />
pas file discriptor to execl() process<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2015/02/26 14:35:06;  author: root;  state: Exp;  lines: +1 -1<br />
new process is created in child using execl()<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2015/02/26 14:30:28;  author: root;  state: Exp;  lines: +19 -19<br />
new process is created using fork()<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/26 14:24:00;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>RCS file: new.c,v<br />
Working file: new.c<br />
head: 1.3<br />
branch:<br />
locks: strict<br />
	root: 1.3<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 3;	selected revisions: 3<br />
description:<br />
new process file<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3	locked by: root;<br />
date: 2015/02/26 14:47:43;  author: root;  state: Exp;  lines: +13 -13<br />
lseek file discriptor<br />
read file<br />
write into file<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2015/02/26 14:45:50;  author: root;  state: Exp;  lines: +13 -13<br />
print hello<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2015/02/26 14:24:00;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/02/inter-process-communication-is-successfully-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CREATING STATIC LIBRARY</title>
		<link>https://www.emblogic.com/blog/11/creating-static-library/</link>
		<comments>https://www.emblogic.com/blog/11/creating-static-library/#comments</comments>
		<pubDate>Mon, 10 Nov 2014 17:32:00 +0000</pubDate>
		<dc:creator><![CDATA[Pooja Gaur]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=11753</guid>
		<description><![CDATA[Static libraries are collection of ordinary object files. For a static library, the actual code is extracted from the library by the linker and used to build the final executable at the point you compile/build your application. Steps: 1.Creates .c &#8230; <a href="https://www.emblogic.com/blog/11/creating-static-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Static libraries are collection of ordinary object files. For a static library, the actual code is extracted from the library by the linker and used to build the final executable at the point you compile/build your application.<br />
Steps:<br />
1.Creates .c file, that contains functions in your library and application.<br />
2.Create object file.eg<br />
    gcc -c add.c -o add.o<br />
                  //-c means to create an intermediary object file, rather than an executable.<br />
3.Create static library.This step is to bundle multiple object files in one static library.<br />
    ar rcs libststlib.a add.o sub.o<br />
                 //r means to insert with replacement, c means to create a new archive,<br />
                                           and s means to write an index.<br />
NOTE: A static library must start with &#8216;lib&#8217; and have the suffix &#8216;.a&#8217;.<br />
4.Making Executable and linking with library.<br />
    gcc -o operation operation.o -L. -lststlib<br />
Note: -L. is used to tell that the static library is in current folder or you can provide the path too.<br />
      -l searches for the library named <em>library</em> at the time of linking. Linker searches and processes libraries and object files in the order they are specified.<br />
5. Run the program.</p>
<p>Note:<br />
1.You can see the list of object files in your library using<br />
    ar -t libststlib.a<br />
2.ar is archive is single file holding a collection of other files.<br />
<a href="http://www.emblogic.com/blog/wp-content/uploads/2014/11/Screenshot-from-2014-11-11-04_20_321.png"><img src="http://www.emblogic.com/blog/wp-content/uploads/2014/11/Screenshot-from-2014-11-11-04_20_321-300x169.png" alt="Screenshot from 2014-11-11 04_20_32" width="300" height="169" class="alignnone size-medium wp-image-11755" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/11/creating-static-library/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></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>
		<item>
		<title>memory management concept</title>
		<link>https://www.emblogic.com/blog/03/memory-management-concept/</link>
		<comments>https://www.emblogic.com/blog/03/memory-management-concept/#comments</comments>
		<pubDate>Fri, 21 Mar 2014 06:46:13 +0000</pubDate>
		<dc:creator><![CDATA[amit.dalal]]></dc:creator>
				<category><![CDATA[Linux Internals and System Programming]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9199</guid>
		<description><![CDATA[Memory Management The memory management subsystem is one of the most important parts of the operating system. Since the early days of computing, there has been a need for more memory than exists physically in a system. Strategies have been &#8230; <a href="https://www.emblogic.com/blog/03/memory-management-concept/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Memory Management</p>
<p>The memory management subsystem is one of the most important parts of the operating system. Since the early days of computing, there has been a need for more memory than exists physically in a system. Strategies have been developed to overcome this limitation and the most successful of these is virtual memory. Virtual memory makes the system appear to have more memory than is physically present by sharing it among competing processes as they need it.</p>
<p>Virtual memory does more than just make your computer&#8217;s memory go farther. The memory management subsystem provides:</p>
<p>&nbsp;</p>
<dl>
<dt><strong>Large Address Spaces</strong></dt>
<dd>The operating system makes the system appear as if it has a larger amount of memory than it actually has. The virtual memory can be many times larger than the physical memory in the system.&nbsp;</p>
</dd>
<dt><strong>Protection</strong></dt>
<dd>Each process in the system has its own virtual address space. These virtual address spaces are completely separate from each other and so a process running one application cannot affect another. Also, the hardware virtual memory mechanisms allow areas of memory to be protected against writing. This protects code and data from being overwritten by rogue applications.&nbsp;</p>
</dd>
<dt><strong>Memory Mapping</strong></dt>
<dd>Memory mapping is used to map image and data files into a process&#8217; address space. In memory mapping, the contents of a file are linked directly into the virtual address space of a process.&nbsp;</p>
</dd>
<dt><strong>Fair Physical Memory Allocation</strong></dt>
<dd>The memory management subsystem allows each running process in the system a fair share of the physical memory of the system.&nbsp;</p>
</dd>
<dt><strong>Shared Virtual Memory</strong></dt>
<dd>Although virtual memory allows processes to have separate (virtual) address spaces, there are times when you need processes to share memory. For example there could be several processes in the system running the <span>bash</span> command shell. Rather than have several copies of <span>bash</span>, one in each process&#8217;s virtual address space, it is better to have only one copy in physical memory and all of the processes running <span>bash</span> share it. Dynamic libraries are another common example of executing code shared between several processes.Shared memory can also be used as an Inter Process Communication (IPC) mechanism, with two or more processes exchanging information via memory common to all of them. Linux supports the Unix System V shared memory IPC.</p>
<p>Virtual Memory</p>
<p>&nbsp;</p>
<h3>An Abstract Model of Virtual Memory</h3>
<p>&nbsp;</p>
<p><img src="http://linuxtutorial.info/Linux_Tutorial/The_Operating_System/The_Kernel/Memory_Management/vm.gif" alt="" />s</p>
<p>Figure: Abstract model of Virtual to Physical address mapping</p>
<p>&nbsp;</p>
<p>Before considering the methods that Linux uses to support virtual memory it is useful to consider an abstract model that is not cluttered by too much detail.</p>
<p>As the processor executes a program it reads an instruction from memory and decodes it. In decoding the instruction, the processor may need to fetch or store the contents of a location in memory. The processor then executes the instruction and moves on to the next instruction in the program. In this way the processor is always accessing memory either to fetch instructions or to fetch and store data.</p>
<p>In a virtual memory system all of these addresses are virtual addresses and not physical addresses. These virtual addresses are converted into physical addresses by the processor based on information held in a set of tables maintained by the operating system.</p>
<p>To make this translation easier, virtual and physical memory are divided into handy sized chunks called <em>pages</em>. These pages are all the same size. They need not be but if they were not, the system would be very hard to administer. Linux on Alpha AXP systems uses 8 Kbyte pages and on Intel x86 systems it uses 4 Kbyte pages. Each of these pages is given a unique number: the page frame number (PFN).</p>
<p>In this paged model, a virtual address is composed of two parts: an offset and a virtual page frame number. If the page size is 4 Kbytes, bits 1-10 of the virtual address contain the offset and bits 12 and above are the virtual page frame number. The processor extracts the virtual page frame number and offset from a virtual address every time it encounters one. Then it matches the virtual page frame number to a physical page and uses the offset to specify how far to go into the page. The processor uses <em>page tables</em> to match the virtual page frame number to the physical page.</p>
<p>The figure above shows the virtual address spaces of two processes, process <em>X</em> and process <em>Y</em>, each with their own page tables. These page tables map each process&#8217; virtual pages into physical pages in memory. This shows that process <em>X&#8217;s</em> virtual page frame number 0 is mapped into memory in physical page frame number 1 and that process <em>Y&#8217;s</em> virtual page frame number 1 is mapped into physical page frame number 4. Each entry in the page table contains the following information:</p>
<p>&nbsp;</p>
<ul>
<li>Valid flag. This indicates if this page table entry (PTE) is valid,</li>
<li>The physical page frame number that this entry describes</li>
<li>Access control information. This describes how the page may be used. Can it be written to? Does it contain executable code?</li>
</ul>
<p>The page table is accessed using the virtual page frame number as an offset. Virtual page frame 5 would be the 6th element of the table (0 is the first element).</p>
<p>To translate a virtual address into a physical one, the processor must first work out the virtual address&#8217; page frame number and the offset within that virtual page. By making the page size a power of 2 this can be easily done by masking and shifting. Looking again at the figures and assuming a page size of <em>0&#215;2000</em> bytes (which is decimal 8192) and an address of <em>0&#215;2194</em> in process <em>Y&#8217;s</em> virtual address space then the processor would translate that address into offset <em>0&#215;194</em> into virtual page frame number 1.</p>
<p>The processor uses the virtual page frame number as an index into the process&#8217; page table to retrieve its page table entry. If the page table entry at that offset is valid, the processor takes the physical page frame number from this entry. If the entry is invalid, the process has accessed a non-existent area of its virtual memory. In this case, the processor cannot resolve the address and must pass control to the operating system so that it can fix things up.</p>
<p>Just how the processor notifies the operating system that the correct process has attempted to access a virtual address for which there is no valid translation is specific to the processor. However the processor delivers it, this is known as a <em>page fault</em> and the operating system is notified of the faulting virtual address and the reason for the page fault.</p>
<p>For a valid page table entry, the processor takes that physical page frame number and multiplies it by the page size to get the address of the base of the page in physical memory. Finally, the processor adds in the offset to the instruction or data that it needs.</p>
<p>Using the above example again, process <em>Y&#8217;s</em> virtual page frame number 1 is mapped to physical page frame number 4 which starts at<em>0&#215;8000</em> (4 x <em>0&#215;2000</em>). Adding in the <em>0&#215;194</em> byte offset gives us a final physical address of <em>0&#215;8194</em>.</p>
<p>By mapping virtual to physical addresses this way, the virtual memory can be mapped into the system&#8217;s physical pages in any order. In the figure above, process <em>X&#8217;s</em> virtual page frame number 0 is mapped to physical page frame number 1, whereas virtual page frame number 7 is mapped to physical page frame number 0 although it is higher in virtual memory than virtual page frame number 0. This demonstrates an interesting byproduct of virtual memory; the pages of virtual memory do not have to be present in physical memory in any particular order.</p>
<p>&nbsp;</p>
<h3>Shared Virtual Memory</h3>
<p>Virtual memory makes it easy for several processes to share memory. All memory access are made via page tables and each process has its own separate page table. For two processes sharing a physical page of memory, its physical page frame number must appear in a page table entry in both of their page tables.</p>
<p>The figure above shows two processes that each share physical page frame number 4. For process <em>X</em> this is virtual page frame number 4 whereas for process <em>Y</em> this is virtual page frame number 6. This illustrates an interesting point about sharing pages: the shared physical page does not have to exist at the same place in virtual memory for any or all of the processes sharing it.</p>
<p>&nbsp;</p>
<h3>Physical and Virtual Addressing Modes</h3>
<p>It does not make much sense for the operating system itself to run in virtual memory. This would be a nightmare situation where the operating system must maintain page tables for itself. Most multi-purpose processors support the notion of a physical address mode as well as a virtual address mode. Physical addressing mode requires no page tables and the processor does not attempt to perform any address translations in this mode. The Linux kernel is linked to run in physical address space.</p>
<p>The Alpha AXP processor does not have a special physical addressing mode. Instead, it divides up the memory space into several areas and designates two of them as physically mapped addresses. This kernel address space is known as KSEG address space and it encompasses all addresses upwards from <em>0xfffffc0000000000</em>. In order to execute from code linked in KSEG (by definition, kernel code) or access data there, the code must be executing in kernel mode. The Linux kernel on Alpha is linked to execute from address<em>0xfffffc0000310000</em>.</p>
<p>&nbsp;</p>
<h3>Access Control</h3>
<p>The page table entries also contain access control information. As the processor is already using the page table entry to map a process&#8217; virtual address to a physical one, it can easily use the access control information to check that the process is not accessing memory in a way that it should not.</p>
<p>There are many reasons why you would want to restrict access to areas of memory. Some memory, such as that containing executable code, is naturally read only memory; the operating system should not allow a process to write data over its executable code. By contrast, pages containing data can be written to, but attempts to execute that memory as instructions should fail. Most processors have at least two modes of execution: <em>kernel</em> and <em>user</em>. This adds a level of security to your operating system. Because it is the core of the operating system and therefore can do most anything, kernel code is only run when the CPU is in kernel mode. You would not want kernel code executed by a user or kernel data structures to be accessible except when the processor is running in kernel mode.</p>
<p>1. What is the difference between Swapping and Paging?</p>
<div>
<p>&nbsp;</p>
<p><strong>Swapping</strong>: Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.</p>
<p><strong>Paging</strong>: Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.</p>
<div>
<p><strong> 3.What is the main goal of the Memory Management?</strong></p>
<div>
<p>&nbsp;</p>
<ol>
<li>It decides which process should reside in the main memory,</li>
<li>Manages the parts of the virtual address space of a process which is non-core resident,</li>
<li>Monitors the available main memory and periodically write the processes into the swap device to provide more processes fit in the main memory simultaneously.</li>
</ol>
<p>&nbsp;</p>
</div>
</div>
<div>
<p>4. What is a Map?</p>
<div>
<p>&nbsp;</p>
<p>A Map is an Array, which contains the addresses of the free space in the swap device that are allocatable resources, and the number of the resource units available there.</p>
<p>Address Units<br />
1     10,000</p>
<p>This allows First-Fit allocation of contiguous blocks of a resource. Initially the Map contains one entry &#8211; address (block offset from the starting of the swap area) and the total number of resources.</p>
<p>Kernel treats each unit of Map as a group of disk blocks. On the allocation and freeing of the resources Kernel updates the Map for accurate information.</p>
<p><strong>5. What is a Region?</strong></p>
<div>
<p>A Region is a continuous area of a process&#8217;s address space (such as text, data and stack). The kernel in a &#8220;Region Table&#8221; that is local to the process maintains region. Regions are sharable among the process.</p>
<p><strong> What is Fork swap?</strong></p>
<div>
<p>&#8220;fork()&#8221; is a system call to create a child process. When the parent process calls &#8220;fork()&#8221; system call, the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. When the memory will be available the child process will be swapped into the main memory.</p>
</div>
</div>
</div>
</div>
</div>
</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/memory-management-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
