Tuesday, March 16, 2010

Virtual Memory

Hi again. In this post Im gonna discuss about virtual memory.Yes... youll find loads of material on virtual memory on the web.For all those preparing for interviews, its a sure shot question. Its kinda interviewers favorite question... So lets hit it....

Virtual Memory:
When we open some applications on our computer like an internet browser,mp3 player,text editors etc all at the same time, the pages of these applications are brought into RAM by computer. Now lets say, there is only 64MB of RAM in your computer and lets forget the concept of virtual memory. If there was no thing called virtual memory then this would mean that when your applications occupied 64MB in your RAM, then your computer would stop obeying your orders of opening new applications. Wont that be unfair to you, u spent lotsa money on that box and it defies you....

Here comes the role of virtual memory.....
This concept is based on the fact that when you run an application, not all the pages of the application are needed at once and also that about 10-20% of the pages are required to keep the application running...
Virtual memory lets you to bring the pages required at a particular instant into RAM and swap out those which are not being used.
These swapped out pages are kept on the hard disk. In linux, we have the swap filesystem whereas in windows we have pagefile.sys for this purpose.
The user is unaware of this whole mechanism and gets an illusion that there is indefinite amount of RAM at his disposal for him to open several applicatoins.

Let me also discuss now how the various memories are organized.

CACHE-------RAM------VIRTUAL MEMORY | HARD DISK

When a page is needed, the CPU first checks the page in cache memory. If the page is not found in cache, then cpu looks up for it in RAM. If found in RAM, the CPU keeps a copy of the page in cache so that, it is available for next demand from the cache itself.
If the page is neither found in RAM nor in the Cache, then the page is loaded from the virtual memory, which resides on the hard disk, into the RAM

Wednesday, March 10, 2010

Linux - .profile file

Hey, ur all back...once again !!!
Ive been working on Linux for quite long, but with lot of discontinuities. But this time, while working I thought of learning about .profile and writing one for myself.. Better late than never suits me, isn't it... Ok, enuf talking...Lets get on, like always with BASICS!!!

What is .profile ?
This file is the first file which gets executed when you login to a shell. It has some initializations, aliases, exports etc to make you go easy while working on command line. It is present in the user's home directory and its a hidden file as it begins with a dot(.). So use ls -a.

What do we usually put in .profile ?
Lets say you have a directory /home/mydir/mydir1/ with a lot of files. Now every time you want to do some file manipulation, you obviously wouldn't want to enter the whole path again and again.So we can create an alias and put it in .profile.
alias myd= cd /home/mydir/mydir1/

Functions:
You can also create functions with arguments to simplify ur task. Lets write a function for displaying your file (using cat)
show ()
{
cat /home/mydir/mydir1/$1
}
Now if you write "show abc" from any folder, the file content will be viewed.

set -o vi
This is another command that I always put in my .profile. It enables us to use history.
You can do this by pressing Esc key and then using "k" and "j" to move backward and forward in history. Its useful, believe me...

set -o noclobber
This is again a useful command. It helps us from accidently over writing an existing file.
Lets say you have a file abc.
Now if you write ls -l > abc
You will get an error saying that abc cannot be overwritten.

export HISTSIZE=100
This enables 100 commands to be kept in history.

These are some of things that you can do.You can write if statements and write any kind of shell scripting that you wanna perform at login...

Saturday, March 6, 2010

Copying files in binary mode

Long time guys.... Yes, m really writing after a long time..i guess after 2 months...
There hasn't been learning on my side on the technical front, but a lot on the domain side..
Copying files :
Many of us would be using tools like winscp, which uses SSH for transferring files between Linux and Windows..even I use it... SSH basically does encryption and decryption before sending and receiving data respectively.It does so for secure transmission.

Now when you copy files between Windows and Linux, you should preferably use bin or binary mode.
Now comes a big "WHY" ???
I prefer it because in "text" mode, WINSCP does some conversion between end of line characters (Windows uses CR+LF(\r\n) as EOL whereas Linux uses LF(\n))
CR and LF represents bytes used to denote EOL.
Enter key generates LF.
CR is denoted by \r.

So to avoid this conversion, its better to use bin mode when you copy dumps or some other type of files which dont deal with just characters.

Ill now come up wid details on these in my next post... Thanks...

Saturday, January 9, 2010

SMTP and MIME

Hi,
Im writing after a long time.Y? Its just because i didn't learn anything new or found anything interesting to write. So , today while browsing I can across an interesting topic..

People studying engineering would know what is SMTP. But, few people know about MIME.As a student, I only knew MIME had something related to email header. So here we go.

SMTP or Simple Mail Transfer Protocol is used to send emails.These emails contain plain text and nothing else( It is because when SMTP was formulated in 1982, it had support only for US-ASCII characters).Now, when we send an email, we know that MIME adds a header to email, divides email into parts and does other technical stuff. But what if your email contains a binary file attachment? How will SMTP send the email since it contains binary information????

Now this is resolved by MIME. MIME( Multipurpose Internet Mail Extension) uses an algorithm "Base64" which does this encoding. This algorithm encodes the information, whether image,media or whatever into a form which can be understood by decoding at the recipient's end.