Social Icons

Thursday, November 28, 2013

UNDERSTAND PRE-PROCESSOR.............ARTICLE 13

  PRE PROCESSOR

We have already seen how to compile a program using a gcc compiler and each step involved in the process of compilation. The gcc is a compiler tool chain, i.e its a set of tools or a collection of tools. Gcc acts as a wrapper for all these tools. In the process of compilation we came across 4 steps on how gcc compiles a program into an executable binary output file. (refer my old article stages of compilation)

                                                       The first phase of the compilation process is the pre-processing phase where the given input program will pre-processed to generate a specific output which will be taken as input by the other tools involved in the compilation process. Lets now study about the pre-processor and learn how it processes the .c file.

WHAT IS MEANT BY PRE-PROCESSING???

Pre-processing can be generally as a process where we prepare any entity for some specific application so that it produces a better outcome. In relevance to computer science, pre-processing can be explained as a process where we take an input data or program make certain optimizations and  modifications
and produce an output which will be used by an other application.

PRE-PROCESSING IN GCC

The pre-processing phase is the first and foremost step in the stages of compilation. The pre-processor will process all the " # " derivatives in the program like #include, #define, #ifdef, #endif etc and substitute them with the necessary code. This is the general functionality of the pre-processor. 

 TOOL USED FOR PRE-PROCESSING

The tool used by the gcc to perform the pre-processing operation is called as pre-processor. When we give a program as input to the gcc it will straight away convert the program into an binary executable but, if we can also instruct the gcc to stop after performing the first phase of compilation. 

                                                      Consider the below C program add.c. Its a very simple program for addition of two number.
The above program is a very simple program which will take two numbers a and b,  add the values and store the output in the variable c. The program has only a single print statement. If we are to compile this program normally we use the command gcc <<filename.c>>  and an executable binary file a.out will be a created.

                                           Let us perform only the first stage of compilation by instructing the gcc to perform only the pre-processing. Now the gcc invokes the pre-processor and then it stops. Now what we are going to do is simply type the following command below

command:   gcc <<filename.c>>   -E  -o  <<outputfilename.i>>.

Here the gcc is provided with a special flag " -E "  after the filename. This flag will instruct the gcc to invoke the pre-processor and create an outputfile with a " .i " extension. This extension specifies that its a pre-processed file.

Lets pre-process the code for adding the two numbers.

Here what I have done above is I pre-processed the file add.c and pushed the output into a file add1.i.
If you observe carefully the above screen-shot its clear that when I did an ls command its displaying a file called add.i in green font which is the pre-processed file.
                                                             The is a command called " file " which will take the file name as input and display the file type as the output.
Lets check the filetype of add1.i

 Here its showing that add1.i is  an ASCII text file, which means it can be opened using a regular text editor. 
lets open the  add1.i  pre-processes file using the vim text editor. The command to open add1.i is 
vim add1.i
cd temp



The above screen-shot displays only a small part of the entire file. I have scrolled down about 19% of the entire file which is shown at the below right end of the screen-shot. Check out the below video.

In this video I am showing you the entire pre-processed output of the add.c program. The pre-processor processed all the " # " derivatives i.e in this context the # include <stdio.h> line was processed by the pre-processor. At the end of the below clip I will clearly show you that only the # derivatives were only processed by the pre-processor and the rest of the code is completely untouched by the pre-processor.




 Hence we can conclude that pre-processor will only understand the # derivatives and it will process all the lines which starts with " # ". The contents of the header file stdio.h was replaced into the program as the compilers cant understand the header files. So, the pre-processor processes the macros for the compiler for compilation.
  

HOW PRE-PROCESSORS LOOKS FOR THE FILE AND PROCESSES

Well by now you might have understood what is the functionality of the pre-processor. Let us now learn how the pre-processor looks for the file and what are conditions are evaluated by the pre-processor.
There is a flag called " -v " called verbose. Most of the commands  can work with this flag. This will give us the verbose output along with the output of the command. The verbose output means the compiler will give comments regarding what all operations it performed while generating the output.
                                                            By using this -v flag we can check what the pre-processor is actually doing while generating the pre-processed file.

command:     gcc add.c -E -v -o add1.i


 The output generated by the above command will look like this.

  This is what the pre-processor does while building the pre-processed output of a c program. Now I know its looking very messy and difficult to follow. The first operation the pre-processor does is, it reads a file called  " SPECS ". 
  It is the specifications file which will tell the pre-processor what tasks to perform. The next step gcc does it will look for the target platform i.e for which platform and processor it should start building the iouput. Here in my system its showing i686-linux-gnu, which is my architecture. I hope I don't have to place a screen-shot of that line. Its specified in the fourth line. The next few lines indicate that the machine is verifying all the system dependent components and libraries required. Now when all the verifications and validations are over it will invoke the pre-processor tool called " CC1 ". 
                                                                 CC1 is the pre-processor tool which will convert all the macros and replace the content of the header files into the add1.i file. In the below screen shot I have highlighted the CC1 tool.

The gcc will take the flags specified by us manually and the rest of the flags will be passed by the gcc implicitly. If you carefully look, you can find the compiler path which indicated where the compiler will search for the libraries. I will highlight some of the predefined library paths which is displayed in the output.

I hope I completed all the major topics related to the pre-processor. If I happen to learn anything new about the pre-processor then, I will surely add that to this article and will notify everyone about it.

Saturday, November 23, 2013

STAGES OF COMPILATION.............ARTICLE 12

GENERAL COMPILER

(You are free to skip this paragraph if you know general compilation process
The above picture shows how the steps involved in the compilation. These are the steps followed by every compiler. The first step is taking the file which contains the valid C-syntax and performing an operation  called pre-processing. After this step the output will be taken by a tool called the compiler and it will generate an assembly code. The assembly code is read by the assembler and it converts it into an object-code. The linker steps in and makes necessary modifications and converts the object code into an executable binary file or .exe file. I just went through the stages of compilation very briefly. This is the steps involved with every compiler which converts the high level language written by the user into machine instructions or the target code depending on the compiler. 

GCC COMPILER:

Lets see how the Gcc compiler works and stages involved in the compilation.

 As you observed the picture you might have got a pretty good idea that all the compilers are pretty much  similar, all of them work in a similar fashion. Our objective is to understand in detail how the Gcc works, what goes into that and what components it uses. As Linux is an OpenSource we can see each and every detail as its all open unlike the proprietary software like Turbo-C and others which hides all these steps.
                          
                                                       Whenever you present a  '.C ' file to compile and build an executable it carries out the following process of compilation in various steps. When I am mentioning the term compiler its not a single tool that I are referring, its a collection of tools. The compiler distribution called Gcc is a set of tools.

Lets take a simple C-program as an example: program which adds two numbers
 

Step 1: 

             
   The first stage of compilation in Gcc (even in any other compiler) is, when we give the .C file to the Gcc, what Gcc does is it first invokes a tool called the pre-processor. The pre-processor tool looks into the code and identifies all those line which start with   
" # "
                         
                              The syntax which are  ' # ' derivatives like  #include,  #define,  #ifdef,  #ifndef  etc, are resolved by the pre-processor. The pre-processor tries to make sense out of these lines, it tries to process and compile those ' # ' lines . Only these preprocessor directives which start with the ' # ' are resolved, rest of the source-code will remain untouched. Generally these pre-processing directives contains function prototypes which will be replaced by the compiler at the time of pre-processing phase of the compilation process.  The significance of this step will become more clear as you progress towards my future posts.

Step 2:

In the second stage of compilation Gcc uses a tool called as compiler. The input for the compiler is the output generated by the pre-processor in the first stage of compilation. The compiler takes in the pre-processed code and converts it into an assembly instruction set. It does not generate the machine code straight away. It generates the assembly instructions for the architecture we are compiling the code. This is because the assembly instructions are architecture specific. It means that that different architecture's like X86, ARM uses and understands only specific assembly code. Below is a screen shot of an assembly code in case you are not familiar with assembly.
  
                        
  Here this is an assembly instructions which my Gcc compiler generated for my X86 architecture.


Don't get confused looking at all those code. It will be pretty confusing for a beginner to understand it. As you progress through the process of learning you will slowly understand. The %eax, %edx, %ecx,... etc you are seeing are all in-fact registers we use to store the values.

                        All these instructions will be executed in a stack.


Note:-
The term compilation and compiler are totally different terms. Compiler is a tool and compilation is the whole process which is required to convert a C-program to an executable output.








Step 3:

In the third stage of compilation we will use a tool called assembler. This tool takes the output generated by the compiler as the input. The assembler takes in the assembly code and converts it into machine instructions. These machine instructions are for the C.P.U. The processor will understand only machine instructions and its the job of the assembler to generate the machine instructions. The output generated by the assembler is the object code.
                                         
                                                 Generally the machine instructions are kinda difficult to understand, but if you want to have a look on how these machine instructions look like, I have placed a screen shot below.


What you are seeing above is not the exactly the way it will be stored. What I mean to say is there wont be any push, pop, add, inc ,..... etc instructions that you are seeing at the extreme left in the original object code. The tool called " objdump " which I used to open this object file which is in ELF format will convert add these extra code for the users understanding only. The actual machine instructions are on the extreme right of the screen shot above. Well in case you did not understand just look the below screen shots.
This is the machine instructions which I mentioned above. Now you must be thinking that why are the machine instructions are not in 1's and 0's.

We have learned that the processor does not understand any  format except 0's and 1's. Well thats true but the tool called objdump which I used to open the object file will convert the machine instructions to Hex format for us to understand.
 The numbers you are seeing is actually the opcode or operational code which the processor will understand. the processor cannot understand human language so opcode is used.... for example for some processors 58 number means add or subtract or multiply or some other operation. It all varies between processors. Check out your processor manual for your processor specific opcode instruction set.



These instructions you are seeing in the screen shot  are also added by the objdump tool for the user to get a better understanding of the machine instructions. 
Lets get back to the stages of compilation.









 Step 4:

In this step a tool called linker steps in takes the object code and converts in into binary executable file. It has much more functions than just creating an executable file but all that we will see soon in the future.

The above steps are same for all the compilers in the market. The proprietary compilers  like Turbo-c and other compilers which is not free unlike Gcc do not show all these steps. That's the beauty of Linux.
 

Sunday, October 6, 2013

HOW TO COMPILE USING GCC.............ARTICLE 11

HOW TO COMPILE

We have already discussed about what is GNU/C compiler. Lets see how to actually compile a program using the Gcc compiler. So, what we are looking at is to understand how to use this compiler tool chain called as Gcc. Here I am using the phrase "compiler tool -chain", because Gcc is a compiler distribution and its not just a single tool, its a combination of tools, its a collection of different tools all under a single name called Gcc. 

TYPES OF COMPILERS:

There are two different types of compilers. 
1. Host compiler.
2. Cross compiler.

  Host compiler: 

Host compiler is the compiler which will compile the source-code and build an executable for the present architecture i.e the architecture of the system on which the Gcc is presently installed.
  

Cross compiler: 

Cross compiler is used to compile the source-code and build an executable for any specific architecture.

Architecture:

When I am using the word  architecture, I am actually referring to the arrangement of the registers, accumulator, number of registers, the data buses used in the architecture and the different components present and how they interact with the processor and each other  etc.. 

Speaking about the computer architecture,  I am using  Intel'sX86 architecture. There are many different architectures like X86, ARM etc.. The compiler we use to compile and build differ for different architectures. 
(You will understand why do we require different compilers for different architecture in my future posts).
  

How to compile:

Lets now see how to compile and build a binary-executable file for a simple C- program. Here our objective is to understand how to compile a program using the Gcc compiler distribution.

Here I am going to write a simple C-program using the Vim-editor. (If you are new to Vim-editor please check out my older posts on HOW TO USE VIM EDITOR)
Here I am inside a directory called temp. I am creating a file called firstprogram.c. This will open a new file called firstprogram.c. If a file already exists with the same name in the present directory it will open that particular file. 
 This is a very simple C-program. I am printing "MY NAME IS AKHIL ASHOKAN". I am saving it as firstprogram.c The " .c " extension is very important for the compiler to recognise it as a file with a valid C-code inside it.


 









Now I have saved this file with the above mentioned syntax displayed, and the directory temp contains a file called as firstprogram.c 

To compile the program the syntax is  gcc <<filename.c>>  -o  <<binary-executable filename>>.
Here my input filename will be firstprogram.c  and the binary-executable filename could be anything of your choice. Look at my screen-shot.

Open the screen-shot and observe carefully the syntax. 
                firstprogram.c is the file we have created just a moment ago and I am passing that file containing the C-code to the Gcc compiler.











Here the executable binary file which contains the binary code which can be executed can be given anyname of our choice. I have given the name as "anyname". 

                  Here in the syntax " -o " means that whatever executable output  the Gcc will generate is to be pushed into the file called  anyname. Now the file anyname contains the compiled output of the program firstprogram.c

                            " -o " is a flag whic I used to instruct the Gcc to push the compiled output into the file anyname. These are also called as switches. Different developer's use different name. Here the executable file called anyname is used as a container to contain the result of the compilation process.
(note: Its the alphabet " o " and not the number " 0 "just in case you get confused).












Here you can clearly observe that now there are two files in the directory temp. One is the firstprogram.c which contains the C-sourcecode and the other file is the binary-executable file called anyname which is in green colour. The colour indicates it contains binary machine instructions.

Now the first step i.e the compilation is completed. The second step is to execute the binary-executable file. To execute the executable file the synatx is as follows
syntax:  ./ <<executable filename>> 

 Here we are executing it by mentioning the path where the executable file exists. Here the dot 
" . " means the present working directory. You can see that I executed the program by giving the command " . / anyname " and the output is displayed on the console or the terminal. Here as I am in the present working directory I mentioned the dot " . " to specify that the file anyname is in the present working directory.

As I have mentioned in my older posts there is a command called pwd to know the present working directory i.e where exactly in the file system we are currently standing. 
 Here my present working directory is /home/akhil/temp.
When I mention dot " . " it simply relates to this path. This means if we know the path where the executable exists we execute the file from anywhere by simply specifying the path and the executable filename. 

Here observe carefully what I am doing is I once executed the executable-file " anyname " standing in the present directory by mentioning " ./ anyname " and we get the output.
Now I leave the directory temp using the command " cd .. " and this time I mention the path of the executable-file where exactly it is located in the file system and execute it, we got the same output. 

                                                                 This demonstration is to clarify the significance of dot " . " and what is the need of mentioning it. 

(Note:  As I have started everything from the scratch please refer older posts in case you get any queries or you can always send me your doubt through " ASKME " in the home page. 






























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  ).