Wednesday, March 28, 2012

About SWAP in linux

what is swap?
swap space is the area on a HD which is part of the VM of your machine.
swap space temporarily hold a memory pages that are inactive.

why do i need swap?
  1. Memory consuming programs Sometimes, a large program (like OpenOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory.
  2. Hibernation (suspend-to-disk) The hibernation feature (suspend-to-disk) writes out the contents of RAM to the swap partition before turning off the machine.
  3. Optimizing memory usage
  4. Optimizing Swap performance

How much swap do i need?
As a base minimum, it's highly recommended that the swap space should be equal to the amount of physical memory (RAM).

Example Scenarios:
  • Low RAM and low disk space With 512 MiB RAM and 30 GB hard disk, use  512 MiB for swap since RAM is very low.
  • Low RAM and high disk space With 512 MiB RAM and 100 GB hard disk, use 1 GiB for swap since RAM is very low and hard disk space is plentiful.
  • High RAM and low disk space With 2 GiB RAM and 30 GB hard disk, use 1 GiB for swap since hard disk space is very low.
  • High RAM and high disk space With 2 GiB RAM and 100 GB hard disk, use 2 GiB for swap since hard disk space is plentiful.

Thursday, March 22, 2012

Program to find factorial using recursion in c

//1st way
#include <stdio.h>
#include <conio.h>

int fact(int);

int main()
{
    int num, f;
    printf ("\n Enter a number: ");
    scanf ("%d", &num);
    f = fact(num);
    printf (" \n Factorial of %d is: %d ", num, f);
}

int fact(int n)
{
    if(n == 1)
    {
        return 1;
    }
   
    else
    {
        return (n*fact(n-1));
    }

}

____________________________________________________________________
//2nd way
#include <stdio.h>
#include <conio.h>

int getFactorial(int n)
{
    int local;
    if (n > 1)
    {
        local = n * getFactorial(n-1);
        return local;
    }

    else
        return 1;
}

int main()
{
    int num, f;
    printf ( "\n Enter a number: " );
    scanf ("%d", &num);
    f = getFactorial(num);
    printf ( "\n Factorial of %d is: %d ", num, f);
}

Tuesday, March 20, 2012

What is kernel

What is linux -- it is a kernel.
What is GNU\Linux -- linux operating system.

Linux is the name of the kernel. The kernel is the core part of an operating system that keeps track of everything. The kernel is both a fence and a gate. As a gate, it allows programs to access hardware in a uniform way. Without the kernel, you would have to write programs to deal with every device model ever made. The kernel handles all device-specific interactions so you don't have to. It also handles file access and interaction between processes.

The kernel also controls the flow of information between programs. The kernel is a program's gate to the world around it. Every time that data moves between processes, the kernel controls the messaging.

As a fence
, the kernel prevents programs from accidentally overwriting each other's data and from accessing files and devices that they don't have permission to. It limits the amount of damage a poorly-written program can do to other running programs.

In our case, the kernel is Linux. Now, the kernel all by itself won't do anything. You can't even boot up a computer with just a kernel. Think of the kernel as the water pipes for a house. Without the pipes, the faucets won't work, but the pipes are pretty useless if there are no faucets. Together, the user applications (from the GNU project and other places) and the kernel (Linux) make up the entire operating system, GNU/Linux.

Sum of number divisible by 7 between 100 and 200

#include <iostream>
using namespace std;

int main()
{
    int i, count = 0, sum = 0;
   
    for (i=101; i<200; i++)
    {
        if(i%7 == 0)
        {
            count = count++;
            sum = sum + i;
        }
    }
   
    cout << "\n Total no of integer div by 7 is: " << count << endl;
    cout << "\n sum of these number: " << sum << endl;
   
    return 0;
}


OUTPUT: