Monday, March 23, 2009

GRUB recovery after installing Windows XP

If any one use dual boot system then after installing windows again we lost GRUB loader. It can recover in various method. Here i discuss GRUB recovery using Live cd. For this we have to boot our system by Live cd.

Follow the step to recover grub bootloader:
1. Boot with Fedora Live CD
2. Open shell
3. mount the linux partition using the command
example: mkdir /mnt/tmp
mount /dev/hda3 /mnt/tmp
3.Type the commands:
grub
4.Then it shows grub> like this
grub>find /boot/grub/stage1
5.It will give a output like this (hd0,7) 7 is here for example, it will be number of ur partition.
grub>root (hd0,7)
grub>setup (hd0)
grub>quit

Then reboot your machine from the hard disk.
Note: For hda1,sda1 it will be (hd0,0),hda2,sda2 it’ll be (hd0,1),hdb1,sdb1 it’ll be (hd1,0)

Read more...

Tuesday, February 10, 2009

C Programs

Contents
========

================
Average of n numbers
================
/*Sum of n numbers */
/*It take the value for num*/
/*it adds the number upto that number and find out the average*/
#include
int main()
{
float num, sum, i;
num=0;
sum=0;
i=0;
float Average;
Average=0;

printf (" Enter the number =");
scanf("%f",&num);
for(i=1;i<=num;i++) { sum=sum+i; } Average=(sum/num); printf("%f\n",Average); return 0; }
============
Prime number
============
/*Program for the prime number*/
/*Input the number*/
/*If the number is 1, print PRIME*/
/*Check wheather the number is greater than zero*/
/*Devide the number from 2 to number-1*/
/*If once the reminder came to 0, Print the number is not prime and break the prgram*/
/*Otherwise print the NUMBER IS PRIME */

#include
int main()
{
int num,i;
printf("Enter the number=");
scanf("%d",&num);
if(num==1)
printf ("1 is a prime number \n");
else if (num<=0) printf ("The input should be greater than 0 \n"); else { i=2; while(i<=num-1) { if(num%i==0) { printf("%d is not a Prime number\n",num); break; } i=i++; } if(i==num) printf("%d is a prime number\n",num); } } ================
Fibonacci series

================
#include
int fibo(int num) /*Recursion function for fibonacci series*/
{
int static i, x=-1, y=1, temp=0;
if(num==0)
return 0;
else {
temp=x+y;
x=y;
y=temp;
printf("%d\n", temp);
fibo(num-1);
}
return x;
}
int main()
{
int fib, no;
printf("Enter the no of fibonacci series to be printed =");
scanf("%d", &no);
if(no<=0) { printf("No is not valid. Enter the No greater than 0\n"); } else { fib=fibo(no); } return 0; } =================== Multiplication Table
===================
/*Enter the number whose table is going to print*/
/*Enter the depth of the table*/
/*print the table by using the while loop*/
#include
int main()
{
int a,b,c,i;
i=1;
printf ("Enter the number = ");
scanf ("%d",&b);
printf ("Enter the depth of the table = ");
scanf ("%d",&a);
printf ("The mutiplication Table of %d\n",b);
printf ("------------------------------\n");
while (i<=a) { c=i*b; ("%d\t*%d\t=%d\n",i,b,c); i=i++; } } ============================= Printing a matrix by using function
==============================

/*Get the number of rows and column*/
/*create a function matrix */
/*Input the matrix by using the for loop*/
/*print the matrix by using the for loop*/
/*call the matrix function from the main function*/
/*End the program*/

#include
matrix()
{
int A[10][10];
int i=0, j=0, row=0, col=0;
printf ("ROW = ");
scanf ("%d",&row);
printf ("COLUMN = ");
scanf ("%d",&col);
A[10][10]=0;
/*Inputing the matrix*/
for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("Enter the number at %d%d =",i,j); scanf("%d",&A[i][j]); } } /*Printing the matrix*/ printf("The given Matrix is \n"); for(i=1; i<=row; i++) { (j=1; j<=col; j++) { printf("%d\t",A[i][j]); } printf("\n"); } } int main() { matrix(); return 0; } ===============
Matrix addition

===============
/*---Program for matrix addition---*/
#include
int main()
{
int A[10][10];
int B[10][10];
int SUM[10][10];
int i=0, j=0, row=0, col=0;
/*input the values for the Rows and column for both Matrices*/
printf ("ROW = ");
scanf ("%d",&row);
printf ("COLUMN = ");
scanf ("%d",&col);
A[10][10]=0;
B[10][10]=0;
SUM[10][10]=0;

/*Inputing the matrix*/
printf("Enter the values for the matrix A\n");
for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("Enter the number at %d%d =",i,j); scanf("%d",&A[i][j]); } } /*Inputing the matrix B*/ printf("Enter the values for the matrix B\n"); for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("Enter the number at %d%d =",i,j); scanf("%d",&B[i][j]); } } /*Summming operation */ for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { SUM[i][j]=A[i][j]+B[i][j]; } } /*Printing the matrix A*/ printf("The Matrix A is \n"); for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("%d\t",A[i][j]); } printf("\n"); } /*Printing the matrix B*/ printf("The Matrix B is \n"); for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("%d\t",B[i][j]); } printf("\n"); } /*Printing the matrix SUM */ printf("The sum of the Matrix is \n"); for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("%d\t",SUM[i][j]); } printf("\n"); } return 0; } =====================
Matrix multiplication

=====================
/*Input the Values for the rows and columns for both matrices*/
/*Check wheather the column of first and row of the second is equal*/
/*If NO Print the NOTE and terminate the program*/
/*If YES Input the matrices*/
/*multiply the matrices*/
/*Print the Output matrix*/

#include
#include
int main()
{
int i,j,k;
int a,b,c,d; /*three variables to get the row and colum of the two matrix*/
int sum;
int m[10][10],n[10][10],l[10][10];
printf("Note: For matrix multiplication the number of columns in the first matrix should be equal to the number of rows in the second matrix\n");
printf("The first matrix:\n");
printf("Enter the number of rows for the first matrix : ");
scanf("%d",&a);
printf("Enter the number of columns for the first matrix : ");
scanf("%d",&b);
printf("The Second matrix:\n");
printf("Enter the number of rows of the second matrix : ");
scanf("%d",&d);
printf("Enter the number of columns of the second matrix : ");
scanf("%d",&c);

if(b==d)
{
printf("Enter the values of the first matrix:\n");
for(i=0;i
Transpose of Matrix

===================
/*input the rows and column values*/
/*Input the matrix */
/*Interchange the row and column values*/
/*Perform the transpose operation by using the for loop*/
/*print the the output matrix*/

#include
int main()
{
int A[10][10];
int B[10][10];
int i=0, j=0, row=0, col=0;
printf ("ROW = ");
scanf ("%d",&row);
printf ("COLUMN = ");
scanf ("%d",&col);
A[10][10]=0;
B[10][10]=0;
/*Inputing the matrix*/
for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("Enter the number at %d%d =",i,j); scanf("%d",&A[i][j]); } } /*Printing the matrix*/ printf("The given Matrix is \n"); for(i=1; i<=row; i++) { for(j=1; j<=col; j++) { printf("%d\t",A[i][j]); } printf("\n"); } for(i=1; i<=col; i++) for(j=1; j<=row; j++) B[i][j]=A[j][i]; /*Printing the out put matrix*/ printf ("The Transpose of the matrix is\n"); for (i=1; i<=col; i++) { for (j=1; j<=row; j++) { printf("%d\t",B[i][j]); } printf("\n"); } return 0; } ====================================

Read more...

Friday, February 6, 2009

Linux Process management

Introduction
Now we are going to discuss the basics of process management in Linux. This topic is of particular importance if you are responsible for administering a system which has not yet been proven stable, that is not fully tested in its configuration. You may find that as you run software, raised problems requiring administrator intervention. This is the world of process management

Contents
1. Process Management
2. Multitasking
3. Types of Processes
4. Input, Output, and Error Redirection
5. Managing Running Processes
6. Killing Stalled Processes
7. Understanding the init Processes
8. Parent Processes

1. Process Management
Any application that runs on a Linux system is assigned a process ID or PID. This is a numerical representation of the instance of the application on the system. In most situations this information is only relevant to the system administrator who may have to debug or terminate processes by referencing the PID. Process Management is the series of tasks a System Administrator completes to monitor, manage, and maintain instances of running applications.
2. Multitasking
Process Management beings with an understanding concept of Multitasking. Linux is what is referred to as a preemptive multitasking operating system. Preemptive multitasking systems rely on a scheduler. The function of the scheduler is to control the process that is currently using the CPU. In contrast, symmetric multitasking systems such as Windows 3.1 relied on each running process to voluntary relinquish control of the processor. If an application in this system hung or stalled, the entire computer system stalled. By making use of an additional component to pre-empt each process when its “turn” is up, stalled programs do not affect the overall flow of the operating system.

Each “turn” is called a time slice, and each time slice is only a fraction of a second long. It is this rapid switching from process to process that allows a computer to “appear’ to be doing two things at once, in much the same way a movie “appears” to be a continuous picture.
3. Types of Processes
There are generally two types of processes that run on Linux. Interactive processes are those processes that are invoked by a user and can interact with the user. VI is an example of an interactive process. Interactive processes can be classified into foreground and background processes. The foreground process is the process that you are currently interacting with, and is using the terminal as its stdin (standard input) and stdout (standard output). A background process is not interacting with the user and can be in one of two states – paused or running.

The following exercise will illustrate foreground and background processes.
1. Logon as root.
2. Run [cd \]
3. Run [vi]
4. Press [ctrl + z]. This will pause vi
5. Type [jobs]
6. Notice vi is running in the background
7. Type [fg %1]. This will bring the first background process to the foreground.
8. Close vi.

The second general type of process that runs on Linux is a system process or Daemon (day-mon). Daemon is the term used to refer to process’ that are running on the computer and provide services but do not interact with the console. Most server software is implemented as a daemon. Apache, Samba, and inn are all examples of daemons.

Any process can become a daemon as long as it is run in the background, and does not interact with the user. A simple example of this can be achieved using the [ls –R] command. This will list all subdirectories on the computer, and is similar to the [dir /s] command on Windows. This command can be set to run in the background by typing [ls –R &], and although technically you have control over the shell prompt, you will be able to do little work as the screen displays the output of the process that you have running in the background. You will also notice that the standard pause (ctrl+z) and kill (ctrl+c) commands do little to help you.
4. Input, Output, and Error Redirection
In order to work with processes on Linux, you must understand the role of redirection. A process that is set to run in the background will continue to display information on the console until it is told otherwise. Changing where a program sends its output is known as redirection.

Standard Output, Standard Input, and Standard Error are the three items that can be redirected. These items are represented by the files /dev/stdin, /dev/stdout, and /dev/stderr. All interactive process’ are programmed to write to these three files for errors, output and input. By default all three of these files are symlinked to through the /proc directory to the terminal the user is currently using. In the case of an interactive user, the flow is as follows.

/dev/stdout -> /proc/self/fd/1 -> /dev/tty1

The /proc directory is a virtual directory that contains information used to construct the users interactive environment and is thus different for each user. In this case you can see that it provides a layer of abstraction and acts as a link between the stdout file, and the file representing the users console device.

Redirection involves using special characters to tell the shell to send input, output, and errors to files other than the defaults. The following table lists these symbols.

Symbol, Meaning

> Redirect stdout

>> Redirect and append stdout

2> Redirect stderr

2>> Redirect and append stderr

<>

In order for a background process to truly run 100% in the background, you must suppress display of all errors. The following example uses redirection to produce a file listing of the entire file system as a background process.
5. Managing Running Processes
The [ps] command is the command used to manage running processes and can be used for many things including viewing the status of your computer and getting a quick idea of how well the computer is performing.

Here are some common ps commands.

Command, Usefulness

ps View current interactive processes on this terminal.

ps –a All current processes on this terminal, by all users.

ps –x All processes not assigned to a terminal (daemons).

ps –aux Output all process running and include resource utilization information.

The man page for ps contains extensive documentation on how to modify and interpret the output of ps.

Top is a utility that can be used to display a live dataset of the currently running processes. Activate it by typing [top].
6. Killing Stalled Processes
Processes that have stalled or frozen can sometimes cause problems. One of the jobs of a Linux administrator is to identify and resolve stalled processes. The clues that a process has stalled can range from an unresponsive GUI to a noted decrease in system performance. Either way, once you have identified that a processes has stalled you can terminate that process using the [kill] command. The syntax is fairly simple. You kill process by referencing its process ID or PID. This information can be seen in the output of just about any iteration of the ps command. To kill a process you pass a signal to that process. The default signal tells the process to perform a clean shutdown. Here are a few examples.

To kill a single process:

ps

PID TT STAT TIME COMMAND

9408 p9 S 0:00 ue temp2.xdh

9450 pa S 0:01 -Tcsh (Tcsh)

9501 pa T 0:00 less csh.1

9503 pa R 0:00 ps

kill 9501

This kills process number 9501. Notice that the ps command which is entered to check on the process ID’s has the latest process number.

To kill a process that refuses to die:

kill -9 9352

This makes a certain kill of process number 9352.

To kill a background job:

jobs

[1] + Running xterm -g 70x55

kill %1

[1] Done xterm -g 70x55

This kills job number 1 (one); the only job that is currently running.

To kill more than one process:

kill 8939 9543

This kills processes 8939 and 9543.

It is important to note that the kill command does not perform only negative actions. It can also be used to restart processes, and to keep processes running, even after a logout.
7. Understanding the init Processes
[init] is the most important process in Linux. All processes are derived from the init process and can trace their roots back to init. [init] always has a PID of 1 and is owned by root. The [init] process is used to start other processes and must be running for the system to operate. In a later article we will examine the boot process. Here [init] will be discussed in much more detail.
8. Parent Processes
Every process has a parent process, with the exception of [init], whose parent process ID (PPID) is 0. It is important to understand the effects of killing a process, especially if that process has spawned child processes.

Sidebar…for all you parent process’s out there

When you kill a parent process, without first killing the child procesi, then you have created orphans. Orphans will generally cause performance decreases as they are taking up resources, but not doing anything. Additionally, they usually do not self terminate, as that task can often be left up the parent. To ensure that you do not create orphans, make sure that no child processes exist when you kill the parent. This can be determined by reviewing the output of the –l switch of the ps command. Compare the PID and PPID columns.


Read more...

Sunday, January 11, 2009

switch case


switch ( ) {
case this-value:
Code to execute if == this-value
break;
case that-value:
Code to execute if == that-value
break;
...
default:
Code to execute if does not equal the value following any of the cases
break;
}

Read more...

Thursday, January 8, 2009

Booting android file system from SD card







1.Find device node for the SD card
2.Unmount it first, if it mounted automatically..
3.Format it by using mke2fs command
4.Create the partition table by using fdisk command
5.Use mkfs.ext2 for that partition
6.Load the file system to SD card after mounting it in the host system
7.Unmount the card.
8.The card is ready for booting


Read more...

Wednesday, January 7, 2009

Formatting USB pen drive in Linux using Terminal /shell


Insert your USB pen drive. Let it get detected and mounted. Open Terminal. Type The Following commands
1. dmesg |tail –> here the ‘|’ key is the pipe
You’ll get something like

root@computer_world:~$ dmesg |tail

[ 9921.681164] sda: Write Protect is off
[ 9921.681174] sda: Mode Sense: 23 00 00 00
[ 9921.681178] sda: assuming drive cache: write through
[ 9921.709138] SCSI device sda: 4030464 512-byte hdwr sectors (2064 MB)
[ 9921.720951] sda: Write Protect is off
[ 9921.720963] sda: Mode Sense: 23 00 00 00
[ 9921.720967] sda: assuming drive cache: write through
[ 9921.721225] sda:
[ 9921.727896] sd 0:0:0:0: Attached scsi removable disk sda
[ 9921.744187] sd 0:0:0:0: Attached scsi generic sg0 type 0
Note the terms in bold. In your system it will be different, maybe sdb or something. Whatever it may be, make sure to substitute it in the commands below, else your hard disk may get formatted.

2. Unmount your pen drive by using
sudo umount /dev/sda (In your case, please substitute sda with the appropriate device, listed above.

3. use the mkfs.vfat command to format to FAT32 filesystem, or mkfs.ext3 to format to ext3 filesystem
sudo mkfs.vfat -n ‘Label’ -I /dev/sda Replace Label with the name you want the pen drive to have.

4. That’s it! When done formatting, you’ll be returned to the prompt
root@computer_world:~$ mkfs.vfat -n ’root’ -I /dev/sda
mkfs.vfat 2.11 (3 Jan 2009
root@computer_world:~$

Remove and insert the pen drive to have mounted again!

Read more...

Linux file system layout


A simple description of the UNIX system, also applicable to Linux, is this: "On a UNIX system, everything is a file; if something is not a file, it is a process."

This statement is true because there are special files that are more than just files (named pipes and sockets, for instance), but to keep things simple, saying that everything is a file is an acceptable generalization. A Linux ystem, just like UNIX, makes no difference between a file and a directory, since a directory is just a file containing names of other files. Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.

In order to manage all those files in an orderly fashion, man likes to think of them in an ordered tree-like structure on the hard disk, as we know from MS-DOS (Disk Operating System) for instance. The large branches contain more branches, and the branches at the end contain the tree's leaves or normal files. For now we will use this image of the tree.




Read more...

Tuesday, January 6, 2009

Linux file system



The first thing that most new users shifting from Windows will find
confusing is navigating the Linux filesystem. The Linux filesystem
does things a lot more differently than the Windows filesystem.
This article explains the differences and takes you through the
layout of the Linux filesystem.

For starters, there is only a single hierarchal directory structure.
Everything starts from the root directory, represented by '/', and then
expands into sub-directories. Where DOS/Windows had various partitions and
then directories under those partitions, Linux places all the partitions
under the root directory by 'mounting' them under specific directories.
Closest to root under Windows would be c:.

Under Windows, the various partitions are detected at boot and assigned a
drive letter. Under Linux, unless you mount a partition or a device, the
system does not know of the existence of that partition or device. This
might not seem to be the easiest way to provide access to your partitions
or devices but it offers great flexibility.

This kind of layout, known as the unified filesystem, does offer several
advantages over the approach that Windows uses. Let's take the example of
the /usr directory. This directory off the root directory contains most of
the system executables. With the Linux filesystem, you can choose to mount
it off another partition or even off another machine over the network. The
underlying system will not know the difference because /usr appears to be
a local directory that is part of the local directory structure! How many
times have you wished to move around executables and data under Windows,
only to run into registry and system errors? Try moving c:windowssystem
to another partition or drive.

Another point likely to confuse newbies is the use of the frontslash '/'
instead of the backslash '' as in DOS/Windows. So c:windowssystem would
be /c/windows/system. Well, Linux is not going against convention here.
Unix has been around a lot longer than Windows and was the standard a lot
before Windows was. Rather, DOS took the different path, using '/' for
command-line options and '' as the directory separator.

To liven up matters even more, Linux also chooses to be case sensitive.
What this means that the case, whether in capitals or not, of the
characters becomes very important. So this is not the same as THIS or ThIs
for that matter. This one feature probably causes the most problems for
newbies.

We now move on to the layout or the directory structure of the Linux
filesystem. Given below is the result of a 'ls -p' in the root directory.

bin/ dev/ home/ lost+found/ proc/ sbin/ usr/
boot/ etc/ lib/ mnt/ root/ tmp/ var/

/sbin - This directory contains all the binaries that are essential to the
working of the system. These include system administration as well as
maintenance and hardware configuration programs. Find lilo, fdisk, init,
ifconfig etc here. These are the essential programs that are required by
all the users. Another directory that contains system binaries is /usr/sbin.
This directory contains other binaries of use to the system administrator.
This is where you will find the network daemons for your system along with
other binaries that only the system administrator has access to, but which are
not required for system maintenance, repair etc.

/bin - In contrast to /sbin, the bin directory contains several useful
commands that are used by both the system administrator as well as
non-privileged users. This directory usually contains the shells like
bash, csh etc. as well as much used commands like cp, mv, rm, cat, ls.
There also is /usr/bin, which contains other user binaries. These binaries
on the other hand are not essential for the user. The binaries in /bin
however, a user cannot do without.

/boot - This directory contains the system.map file as well as the Linux
kernel. Lilo places the boot sector backups in this directory.

/dev - This is a very interesting directory that highlights one important
characteristic of the Linux filesystem - everything is a file or a
directory. Look through this directory and you should see hda1, hda2 etc,
which represent the various partitions on the first master drive of the
system. /dev/cdrom and /dev/fd0 represent your CDROM drive and your floppy
drive. This may seem strange but it will make sense if you compare the
characteristics of files to that of your hardware. Both can be read from
and written to. Take /dev/dsp, for instance. This file represents your
speaker device. So any data written to this file will be re-directed to
your speaker. Try 'cat /etc/lilo.conf > /dev/dsp' and you should hear some
sound on the speaker. That's the sound of your lilo.conf file! Similarly,
sending data to and reading from /dev/ttyS0 ( COM 1 ) will allow you to
communicate with a device attached there - your modem.

/etc - This directory contains all the configuration files for your system.
Your lilo.conf file lies in this directory as does hosts, resolv.conf and
fstab. Under this directory will be X11 sub-directory which contains the
configuration files for X. More importantly, the /etc/rc.d directory
contains the system startup scripts. This is a good directory to backup
often. It will definitely save you a lot of re-configuration later if you
re-install or lose your current installation.

/home - Linux is a multi-user environment so each user is also assigned a
specific directory which is accessible only to them and the system
administrator. These are the user home directories, which can be found
under /home/username. This directory also contains the user specific
settings for programs like IRC, X etc.

/lib - This contains all the shared libraries that are required by system
programs. Windows equivalent to a shared library would be a DLL file.

/lost+found - Linux should always go through a proper shutdown. Sometimes
your system might crash or a power failure might take the machine down.
Either way, at the next boot, a lengthy filesystem check using fsck will
be done. Fsck will go through the system and try to recover any corrupt
files that it finds. The result of this recovery operation will be placed
in this directory. The files recovered are not likely to be complete or
make much sense but there always is a chance that something worthwhile is
recovered.

/mnt - This is a generic mount point under which you mount your filesystems
or devices. Mounting is the process by which you make a filesystem
available to the system. After mounting your files will be accessible
under the mount-point. This directory usually contains mount points or
sub-directories where you mount your floppy and your CD. You can also
create additional mount-points here if you want. There is no limitation to
creating a mount-point anywhere on your system but convention says that
you do not litter your file system with mount-points.

/opt - This directory contains all the software and add-on packages that
are not part of the default installation. Generally you will find KDE and
StarOffice here. Again, this directory is not used very often as it's
mostly a standard in Unix installations.

/proc - This is a special directory on your system.

/root - We talked about user home directories earlier and well this one is
the home directory of the user root. This is not to be confused with the
system root, which is directory at the highest level in the filesystem.

/tmp - This directory contains mostly files that are required temporarily.
Many programs use this to create lock files and for temporary storage of
data. On some systems, this directory is cleared out at boot or at
shutdown.

/usr - This is one of the most important directories in the system as it
contains all the user binaries. X and its supporting libraries can be
found here. User programs like telnet, ftp etc are also placed here.
/usr/doc contains useful system documentation. /usr/src/linux contains the
source code for the Linux kernel.

/var - This directory contains spooling data like mail and also the output
from the printer daemon. The system logs are also kept here in
/var/log/messages. You will also find the database for BIND in /var/named
and for NIS in /var/yp.

This was a short and basic look at the Linux filesystem. You do need to
have at least this basic knowledge of the layout of the filesystem to
fully utilize its potential. One good place to read about the filesystem
is this detailed document at www.pathname.com/fhs/1.2/fsstnd-toc.html that
specifies the standard structure of the Linux filesystem.

Read more...

  © PC Template PC by PC 2008

Back to TOP