Social Icons

Sunday, September 29, 2013

UNDERSTANDING THE GCC COMPILER.............ARTICLE 10

GCC COMPILER:

If you want to learn the Linux kernel source code its very much important that you understand the GNU/C compiler called the GCC. We will be using this compiler throughout the course. I will be using this GCC compiler to compile the programs in Linux. The reason why I am using this particular compiler is because this compiler is specifically used to compile the kernel source code. The Linux kernel is simply the source code which is in the c-syntax. All the source code is arranged into a set of .c files. If you want to compile this source code the compiler you ned to pick up is GCC.

WHY GCC???

The source code of Linux kernel is specific to the gcc i.e we cannot use any other compiler other than the gcc compiler which is also called the GNU/C compiler developed during the GNU project. Although the Linux kernel source code is  c-syntax, the reason why require specifically the gcc compiler is because the source code of Linux is not completely ANSI-C. Linux source code is gcc extensions. So, there is no other way than using the gcc compiler as long as you are using the Linux kernel source code.

                                                            Most of the developers also prefer the gcc compiler. Now days what's happening in the open-source especially with regard to the embedded systems and desktop applications is that almost all the distributions are combing the Linux kernel source code along with the core applications and releasing there own distribution. The distributors will download the Linux kernel source code and compile it using the gcc compiler and acquire the open-source packages and compile them and integrate them into one system. What I mean by open source packages are the core applications like gcc compiler, Libre office, LibreOffice Impress, LibreOffice Writer, LibreOffice calc etc. All these are open-source independent packages or open-source projects. You can find LibreOffice, LIbreOffice Impress etc  on the launcher bar in Ubuntu.


These icons are LibreOffice Writer, Calc, Impress. As Linux kernel source code is free open-source even these softwares are free open source projects. Now the distributor have to simply download the source code and these packages and compile them and integrate it to one system.
 
   It means a distribution is a KERNEL  + CORE APPLICATION SET.



Almost of all the open-source implementations of applications which uses c-syntax or c++ syntax  uses gcc and g++ compilers to compile the source code. So, whenever we download an open-source framework the only way to compile it is using the gcc or g++ compiler.

                                                 The gcc is the only tool chain that had been very widely used throughout the world. Gcc has the ability to compile C, Objective-C, Fortran, and also contains added libraries to compile the C++ source code as well. Hence I will be using this compiler tool chain to compile the programs and explain the concepts of kernel programming.

Any compiler distribution, when I say distribution its a set of tools we use to compile, debug, test, execute and verify an application. As a programmer what we require first is an interface to type and edit our programs, second we need a tool to compile or translate the program from any high level language to machine code, and third we require a method to test or execute and validate the application or program we wrote. Providing all these tools as a part of the framework is what we call as a distribution. In Windows terminology and most of the Windows developer community we call this as a Development Kit. So, when we say distribution it is synonymous to the development kits in Windows.


WAYS TO USE THE COMPILER DISTRIBUTION:

There are particularly two ways to use the compiler distribution.

FIRST OPTION:
You can have a GUI interface, an IDE(integrated development environment) is always a method of integrating all these tools into one application and use these tools through an IDE's  GUI interface.
IDE is like TURBO-C , ECLIPSE, FRAMA-C etc.. IDE's can simply speed up the process as there are many shortcuts we can use for debugging, compilation, execution and editing.

SECOND OPTION:
The other way is you can always use a command to invoke these tools, i.e invoke them through the command line. We don't require a unique IDE for this. So, Gcc can be used through an IDE or through and also can be used through the command line. If we need to access any tool we need to command it to access it.


                                                 When ever you are learning a new tool I advise you to always prefer to use a command to access it because IDE's often hide all this process. Proprietary tools like TURBO-C will hide the entire process where as in Linux you can view the entire process and learn more about it. There will be alot of flags and different implementations of a single tool which you cannot know if you are using an IDE. An other problem with using an IDE is that when you use an IDE persistently to compile programs and other purposes you get bound to that particular IDE, you become specific to that IDE and it becomes difficult for  you to switch to another IDE or any different environment. If you are using a command line to access it, there is always more scope that you will learn more about the use of a particular tool. So, initially I will be using Gcc on the command line to compile the programs. Our objective is to learn as much as we can. Once you are good with the command line you can always shift to an IDE. IDE is only an option. Its to speed up the process but if you want to learn its always recommended you use command line.

Note:
   Linux kernel source-code is completely c-syntax. There have always been speculation about why it is not C++. C++ is all about object orientation and Linux kernel is completely 100% object oriented. We do not need an object oriented syntax to implement object orientation and Linux source code is one of the best examples for C-syntax with complete object orientation. 0

Wednesday, September 25, 2013

HOW TO USE VIM EDITOR.............ARTICLE 9

NOTE:
              I have already installed vim editor into my machine hence I wont be talking about any steps on how to install the vim editor. If anyone needs any assistance regarding the installation please refer to my previous posts.

THE VIM EDITOR

The vim editor is a text editor written by Bram Moolenaar and was first released publicly in 1991. We will be using this text editor to write our Linux programs which I will be discussing with you. The reason why I am writing an article on how to use the vim is because this editor initially feels very confusing and irritating until you get used to it. 

                                                               There are many features present in the vim editor but I will only discuss with you only a few of the necessary operations you need to know in order to write a program, a text document, or almost anything that is related to text editing and how to save the file we edited etc....

HOW TO OPEN A VIM EDITOR:

To open the vim editor first you need to open the terminal and just type vim.
vim -> This command will open the vim editor.

TO OPEN/CREATE A FILE:

In vim we do not have separate commands for creating and opening the file. We can create a file by using the following command vim <<filename.type>> . The ".type" is nothing but the extension i.e if you are going to write a c-program give filename.c or if you are going to edit a text file write filename.txt, or if you are going to edit an .c file you will give filename.c .

for example : you cannot compile a c program if the file has no .c extension as the compiler will not recognise the format. (in my future posts I will give you more clarity as few more concepts are need to be covered to understand it if its confusing for you.) 
                                      
                                                        If you want to open an existing file just use the same command vim <<existing filename>>. If the file exists in the present working directory it will open the file and display its content , else if the file is not present it will open a new file with the name we mentioned and display it to you as an empty file. 

Look I am opening a file with my own name akhil.
Now the vim will check if a file with name akhil is present in the current working directory or not.
If its present in my current working directory it will open the file and display it to me , else it will just open a new empty file and display it to you. If you want to open a file which is already saved in the disk first we have to move to that directory and then specify the command vim <<existing file name>>, and it will open and display the file to you.
                                                    Once the file is opened it will look something like this.

 Because this is a new file and I don't have any file with the name akhil previously stored in my disk its showing a blank window. The above screen shot shows what your screen looks like. The tilde (~) lines indicate lines not in the file. In other words, when Vim runs out of file to display i.e if there is no file with the file name I have specified it displays the tilde lines. At the bottom of a screen, a message line indicates the file is named "akhil" [new file] and shows that you are creating a file. The message information is temporary and the other message overwrites it when you type the first character.

Now look carefully I have opened a new file i.e it was not existing in my disk previously hence its displaying  "akhil" [new file].


 

 

Now I will save the file with the name akhil and will type the command vim akhil. This time it will open the existing file as I just saved. It will show something like this.

 

 

Here it shows only "akhil" 0L, 0C. It means zero lines and zero columns.
   
INSERT MODE:
This is one of the  modes in the vim editor. We use this mode to enter the text into the file. Open a file using the editor and now press the letter " i "  in the keyboard. This will initiate the insert mode and it will be displayed at the end of the screen. 
 Now you can enter what ever text you want to enter and save it inside that file.




Once you are done entering the text into the file you should press the ESC key to exit from the insert mode. After you have exit from the insert mode you can do the following 

1:  :q-> this is called quit. If we have not done any specific changes and just wanted to view the file and close it you can use " q " to quit from the vim editor window.
This is only applicable if you have not made any changes to the file from the time you have opened it using the vim editor.

If we make any changes in the file after we have opened it we have to instruct the vim editor to either save the changes or to discard the changes.

If we made any specific changes in the file even if we add a space into the file (adding a space is also a specific change we make in the file as space will also be counted.) and try to quit by pressing " :q " it will display an error message as follows.

 Its showing no write is performed since the last change i.e the changes we made has not yet been written into the disc.
note: " : " the colon must be added before " q "
step1:   ESC
step2:   press " :q "
step3:  press enter key.

2:  :q! ->  after pressing ESC key if you want to perform a quit without saving any changes you can do it by adding an " ! " after " q " (quit).

3:  :wq -> after pressing ESC key to escape from the insert maode you can perform a save and quit operation by pressing " :wq ", which says write and quit.

NOTE: If you create a file with the name " akhil " and another file with the name " akhil.txt " and yet an other file with the name " akhil.c ", all three of them are different files though they have same name with different extension vim will treat them as three distinct files.

These are the few very basic operations you need to know. There are many more features in VIM that I am not discussing here as its not necessary for time being..
                                                         Any doubts please feel free to ask me.You can drop your query in the " ASK ME " section of my home page.

Monday, September 23, 2013

UNDERSTANDING MAN PAGES.............ARTICLE 8

WHAT IS A MAN PAGE???

A Manual page shortly called as Man page is a software  documentation found on all the UNIX and LINUX operating systems by default. All the commands, library calls, system calls etc.. can be found inside Man pages.

WHY TO USE MAN PAGES??

 Man page is one of the best facility a LINIX/UNIX system provides us. One of the best ways to learn Linux is through the man pages.
It is basically divided into 9 sections. We will use mostly use the first seven sections of the man pages.
Each section of Man page is like a category. 
                            
The sections of Man pages are as follows:-
  1.  Executable programs or shell commands.
  2. System calls (functions provided by the kernel).
  3. Library calls (functions within program libraries).
  4. Special files (usually found in /dev(dev is a operating system file which contain info about devices)).
  5. File formats and conventions eg /etc/passwd.
  6. Games.
  7. Miscellaneous (including macro packages and conventions).
  8. System administration commands (usually only for root).
  9. Kernel routines.   
    All the books which contains information or data about the Linux commands and functions are taken from the Man pages itself. Any book you find in the market are simply a re-write of Man pages. 

                                        Man pages conveys the information directly to the user. When we read from the books the authors of the books write about the commands and functions in the way they understood and implemented it. It cab be accurate or not accurate
    I am not writing against any author, what I want to say is learning through the Man pages is one of the best way you can learn LINUX. You do not have to memorize the syntax which can be a very tedious job. All you need to do is just remember the name of the function or at-least know a function exists for a specific purpose. The syntax, implementation, return value, errors that could occur etc can be viewed in the man page.
      
    HOW TO OPEN A MAN PAGE??

    Opening a man page is very simple . Open a terminal bt pressing ATL+CTRL+T  and type this man <<command  or library function or system calls  or tool name etc..>>
    for example: If I need to find out about a function printf(). I guess we are pretty familiar wit the printf() function which is used to print the output on the screen. To open he man page for print just open the terminal and type man printf  and you will get the documentation of printf().
    Have a look at my screen shot.

      
 Look I have opened my terminal and typed the command to open the man page for printf().
The output we get here is as shown below
 Here i would like to discuss a few pints and tips i know about using a man page.
As you open a man page you can see a number referring to the section. Here in printf() function 1 is present, that mean it belongs to the first section of the man page.

 Here this 1 tells that its a part of the first section. S ometimes a single command can be in the multiple sections, its because one command can be used for different purpose it can act both as a command as well as a library call or a system call hence it will belong to both the sections.
For example : Let me open a man page on signals. syntax is man signal.



The section number its referring to is 2 that means its the manual page of signal is from the second section of the man page.


Now look at this carefully, I am opening a man page on signal which belongs to section 7.


It will be a different man page with only a little similarity although the functionality is same. Try it for yourself.


DIFFERENT SECTIONS INSIDE A MAN PAGE: 
 When you open a man page of any command or a tool or a system call , the description about that particular function will be described in the following order 
1:  NAME
2:  SYNOPSIS
3:  DESCRIPTION 
4:  RETURN VALUE
5:  ERRORS
6:  CONFORMING TO
7:  NOTES
8:  BUGS 
9:  SEE ALSO
10:  COLOPHON

Every man page will have the following I mentioned above. It will give you a complete information about the function.

HOW TO USE THE MAN PAGE:

Once you have a man page on your screen, you'll want to know the information listed below.

If you need help while looking at the man page, you can type a ? to get more information.
If the man page is more than one page long, you'll need to press the space bar to see the next and all subsequent pages.
                           If you're looking for something specific in the man page (for example, the description of a particular option), you can have man find a particular word (say, that option name) by typing the following: /pattern . The man command will go to where it first finds the word you typed in place of pattern. 
                             To get man to look for the next occurrence of that word, simply type a slash (/) by itself.  If you don't want to look at the entire man page, you can quit by typing ctrl-c or, if the : prompt is on your screen, by typing q.  If you don't know the exact name of the UNIX command you're looking for, you can use: man -k something man -k responds by printing on the screen a list of all the commands it finds that are similar to the word you typed in place of something or that contain that word in the description of the command. You can then use the man command to get information about the command you're interested in. 


Its not important you read an entire Man page as sometimes man pages can turn very exhaustive. If you know how to use a particular function, what is its functionality its more than enough. As you keep using the tools, as you become familiar with these flags and functions etc usage will also become easy eventually. You don't have to memorize the functions and commands , as we can always refer into the man pages.

IF YOU WANT TO CHECK OUT ALL THE COMMANDS GOTO WWW.LINUXMANPAGES.COM.
THERE YOU WILL FIND THE ENTIRE LIST ( ACTUALLY A VERY LONG LIST , MORE THAN 3000 APPROXIMATELY  ). 

Friday, September 20, 2013

BASIC COMMANDS.............ARTICLE 7

BASIC COMMANDS YOU SHOULD KNOW:

Use Atl+Ctrl+T shortcut keys to open the vim-editor. I have placed a screen-shot of my own vim-editor.
               
                    It will show you something like this  "<<name>>@<<company name>>-System-Product-Name:~$ "
As my name and company name both are "akhil" shows this.
You can edit text document, write c programs etc.. using this vim-editor.
vi editor also provides these functionalities but additional functionalities are added into vim-editor.

BASIC COMMANDS YOU SHOULD KNOW:

1: pwd  -> this will return the present directory you are working i.e if you edit any document, save the document what ever is the manipulation you perform will be done in this directory. 






2: LS -> this command will return you the list of file present in the present working directory.


3: cd -> this command is used to change the directory from one directory to another.
syntax is  cd <<directory name>> ..

For example : you can see the files i have in my home directory. Its showing coursematerial, documents music, public etc ... To enter into coursematerial all i have to do is  "cd coursematerial" and i will be in course material directory.. view my screen shot
  1.  first i gave an ls command to see the list of files
  2. then i did a cd <<filename>>(here my filename is coursematerial).
  3. now its showing that i am in coursematerial directory observe :~/coursematerial.
  4. i again did a ls and it returned me the list of files inside coursematerial. Here i have two files kernelprogramming and userprogramming.

4: cd .. -> this command will come out of the present directory. cd followed by a space and two dots(..) i.e cd .. see the screen-shot it is clearly showing i exited from coursematerial directory.

5: mkdir -> this is quite a simple command to make a new directory. Its like creating a folder in windows.
syntax: mkdir  <<directory name>>
here i am creating a directory with directory name as "www.kernelarmy.blogspot.in"
 you can clearly see the command i am using here. Initially when i do ls there is no directory with the name www.kernelarmy.blogspot.in. After i made a directory using the command mkdir and i again did a ls .Now you will find a diectory with the name "www.kernelarmy.blogspot.in"



6: rmdir -> this command is use to remove any directory i.e delete any directory provided the directory must be empty.
syntax: rmdir <<directoryname>> 
now i will delete the directory i have created just now using rmdir www.kernelarmy.blogspot.in
  
7: rm -> this command can be used to remove any file you have created..
syntax: rm <<filename>>


 NOTE:These commands are the very basic commands required for you to know through out the course. There are thousands of commands in LINUX i have only discussed a few which are presently required. I will discuss more commands when we come across them.
   

VIM EDITOR: INSTALLATION.............ARTICLE 6

INSTALLING VIM EDITOR:

VIM EDITOR:

UBUNTU 12.04 comes in default with many features. There is an in-built editor called vi editor. I would recommend you to install the VIM EDITOR as its much more easier to use and comes with many added features when compared to the VI-EDITOR which comes as a default editor in most of the LINUX and UNIX systems.
                                               Both VIM and VI supports all the POSIX standards(posix is a standard followed by many for program  portability across different machines.) 

HOW TO INSTALL VIM EDITOR:

Installation of vim editor is a very simple process. Just follow the below steps (Internet required)....

STEP 1:    open a terminal from dash home menu by typing terminal in the search box or by pressing   the short cut keys Alt+Ctrl+T which directly opens a terminal.


STEP 2: after opening the terminal type the following commands
               "sudo apt- get update"   and "sudo apt-get install vim" .It will install packages from the Internet.

STEP 3: just go with the flow. It will ask you for permission to continue, something like Y/N ?(yes or no) will be displayed, type the letter Y and enter, VIM-editor will be installed succesfully into your machine.

ALTERNATE METHOD:

STEP 1:  from the launcher in the left you will find an icon with name Ubuntu software center or you can open it from DASH HOME which is a white icon on the top and type Ubuntu software center.

 
STEP 2:  you will get a window as shown below. In the search bar type Gvim. It will search for the software and will give you the result. Select gvim and install. In case installation fails update your Ubuntu using the command sudo apt-get update and try again. 

NOTE: AS I HAVE ALREADY INSTALLED VIM ITS GIVING ME A REMOVE OPTION. IF YOU HAVE NOT INSTALLED VIM-EDITOR IT WILL GIVE YOU AN INSTALL OPTION.

LINUS BENEDICT TORVALDS.............ARTICLE 5

LINUX/GNU OPERATING SYSTEM:

Linus Benedict Torvalds was born on December 28  1969. He is Finnish American Software Engineer who was the principle force behind the development the development of Linux Kernel.

In 1987 Torvalds used his savings to buy his first computer, a Sinclair QL. This was one of the world's first 32-bit computers for home use. With its Motorola 68008 processor (the part of the computer that performs logic operations and also referred to as a central processing unit or CPU) running at 7.5MHz (megahertz) and 128KB (kilobytes) of RAM (random access memory), this was a big step up from his grandfather's Commodore Vic 20. However, he soon became unhappy with it because of it could not be reprogrammed due to the operating system residing in ROM (read-only memory).
In 1988 Torvalds followed in the footsteps of his parents and enrolled in the University of Helsinki, the premier institution of higher education in Finland. By that time he was already an accomplished programmer, and, naturally, he majored in computer science. In 1990 he took his first class in the C programming language, the language that he would soon use to write the Linux Kernel (i.e., the core of the operating system).
In early 1991 he purchased an IBM-compatible personal computer with a 33MHz Intel 386 processor and a huge 4MB of memory. This processor greatly appealed to him because it represented a tremendous improvement over earlier Intel chips. As intrigued as he was with the hardware, however, Torvalds was disappointed with the MS-DOS operating system that came with it. That operating system had not advanced sufficiently to even begin to take advantage of the vastly improved capabilities of the 386 chip, and he thus strongly preferred the much more powerful and stable UNIX operating system that he had become accustomed to using on the university's computers.

                                                            Consequently, Torvalds attempted to obtain a version of UNIX for his new computer. Fortunately (for the world), he could not find even a basic system for less than US$5,000. He also considered MINIX, a small clone of UNIX that was created by operating systems expert Andrew Tanenbaum in the Netherlands to teach UNIX to university students. However, although much more powerful than MS-DOS and designed to run on Intel x86 processors, MINIX still had some serious disadvantages. They included the facts that not all of the source code was made public, it lacked some of the features and performance of UNIX and there was a not-insignificant (although cheaper than for many other operating systems) licensing fee.

                                                        Source code is the version of software (e.g., an operating system or an application) as it is originally written (i.e., typed into a computer) by a human using a programming language (such as assembly, BASIC, C or Java) and before it is compiled (i.e., converted by a compiler) into machine language, which the processor (but not humans) can understand directly. Having the source code is necessary in order to study or improve software. A highly skilled programmer such as Torvalds can easily become bored and frustrated with software for which the source code is not available.
Torvalds thus decided to create a new operating system from scratch that was based on both MINIX and UNIX. It is unlikely that he was fully aware of the tremendous amount of work that would be necessary, and it is even far less likely that he could have envisioned the effects that his decision would have both on his life and on the rest of the world. Because university education in Finland is free and there was little pressure to graduate within four years, Torvalds decided to take a break and devote his full attention to his project.
On August 25, 1991, he announced his initial creation on the MINIX newsgroup comp.os.minix  and took suggestions as well as he also uploaded his source code and names int linux(Linus + MINIX) .

The code was released  under the GPL(General Public License) and anyone who whishes to add their own suggestions and modify to optimize the code were welcomed. 
Linux/GNU together were combined to create a full fledged free open source operating system.

Thursday, September 19, 2013

FSF........ARTICLE 4

FREE SOFTWARE FOUNDATION:

The free software foundation was started by Stallman as more and more people were starting to get involved in the GNU project  by making their contributions. This forced Stallman to look for some funding so, in 1985 he started FREE SOFTWARE FOUNDATION which was a tax exempt society for free software development. Gradually more and more programs were added and some of the notable ones are the C-library and the SHELL. 

                                                 By 1990 the GNU project was almost completed. All the major packages and applications were added but the heart of the operating system was missing thats the Kernel. Without the Kernel it was not possible to manage resources.The decision was to implement the Kernel as a collection of server processes and was nearly equal to UNIX kernel. A microkernel was developed and was named GNU HURD which meant the heard of gnus.

GNU PROJECT........ ARTICLE 3

GNU PROJECT:

For Stallman the idea was pretty clear. All he required is to make an operating system which is UNIX compatible so that it must be easily portable. the word GNU was chosen following a hacker tradition, as a recursive acronym for  "GNU' s NOT UNIX".
  The GNU project started with an objective to create free software society. Here the term "free" is often misunderstood for the price of the software. It has nothing to do with the price, its about the freedom. Its defined as:
  •  you have the freedom to run the program for any purpose.
  • you have the freedom to modify your programs as it suits your need. (for this you need to have access to the source code).
  • you have the freedom to redistribute the copies either for a fee or gratis.
  • you have the freedom to redistribute modified versions of program, so that the community will benefit from your improvements.
So Stallman quitting his job from MIT in 1984 started designing a compiler for the operating system which is popularly known as GCC. GCC compiler has been universally accepted and widely used till date. Compiler is one of the core application in an operating system.

Wednesday, September 18, 2013

LINUX :THE BEGINNING..... ARTICLE 2

HOW LINUX CAME INTO EXISTENCE....

Richard Stallman is an American born on March16, 1953. He is a Software Freedom Activist and a Software Engineer.

The invention and evolution of LINUX operating system dates back to 80's and 90's. He worked at MIT's Artificial Intelligence lab and things started to look bad for him with the collapse of free software community with was existent during that period. With the modern era operating systems on a raise there were no free software's. All software's' came with
a non-disclosure agreement which said, you are not allowed to share or change the software, if a change is required prior permission from the company is mandatory and the changes will be done by the company itself. This sounded very antisocial for Stallman and the free software community who enjoyed sharing there programs and source-code with universities and companies. With the collapse of his community he always had a choice of joining proprietary software world which means to make software's under non-disclosure agreement which was against his morals. He chose to quit which was rather an pleasant thing to do as it was a waste of his skills as a operating system developer. He wanted to build that community back which encouraged free software.

INSTALLATION ASSISTANCE

If anyone needs installation assistance click on this hypelink


GETTING STARTED......ARTICLE 1

To start with Linux kernel programming i would recommend you to have UBUNTU 12.04 installed in your
its absolutely free version......
The black arrow pointing to "download now". download and install..