Thursday, September 13, 2012

Duplicating databases

Duplicating the databases

- Create a new database, db2
- Run this command:
mysqldump -h [server] -u [user] -p[password] db1 | mysql -h [server] -u [user] -p[password] db2


Wednesday, June 27, 2012

linux commands (for my use)

Executing a shell script 

chmod +x 
Renaming the folder

mv "Folder1" "Folder2"
sudo mv "Tinyos" "TinyOS"
Finding files in USB in ubuntu : /media/<usbdrive>

Thursday, June 21, 2012

First Kernel Programming

In this blog i use 'kernal' instead of 'kernel' intentionally to identify my files.

In computing, the kernel is the main component of most computer operating systems; it is a bridge between applications and the actual data processing done at the hardware level. The kernel's responsibilities include managing the system's resources (the communication between hardware and software components). Usually as a basic component of an operating system, a kernel can provide the lowest-level abstraction layer for the resources (especially processors and I/O devices) that application software must control to perform its function. It typically makes these facilities available to application processes through inter-process communication mechanisms and system calls. (source : Wikipedia)

There are numerous materials available on linux kernel.

In general we insert and remove the module from a kernel in order to avoid recompiling the whole kernel from the scratch. Here in this blog we will get to know how to write a first linux kernel programming module from the basic. 

  Step 1 : Creating a folder kernalprogramming

    Step 2 : Create a file called firstkernal.c

Step 3 : Write the first kernel program

 #include <linux/init.h>
#include <linux/module.h>

// To start the module

static int hello_init(void) {
    printk(KERN_ALERT "TEST : Hello world. this is jithu");  
    return 0;

// To end the module

static void hello_exit(void) {
    printk(KERN_ALERT "TEST : Hello world. good bye");  

// To call the start and end modules


In the above program, linux/init.h and linux/module.h are the header files located in /usr/src/

This location is important to provide in the Makefile which will be discussed soon.

Next hello_init is a function which prints "TEST : Hello world. this is jithu"
Kernel programs do not call conventional c libraries such as "printf" "scanf" etc.. 

So we are using "printk" which will output into the screen

Another function is hello_exit, is a function which prints "TEST : Hello world. good bye"


This line is the starting point. The parameter is the function and the function is called when we run/ insert the program into the kernel. (like a main in conventional programming)


This line is the ending point. The parameter is the function and the function is called when we run/ remove the program from the kernel. 

Step 4 : Creating a Makefile

#obj-m += filename.o

obj-m += firstkernal.o

#linux header files
#we can check using the command 'uname -r'

KDIR = /usr/src/linux-headers-3.2.0-23-generic

    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

    rm -rf *.o *.ko *.mod.* *.symvers *.order

first line says obj-m += firstkernal.o
It means build driver calling firstkernal.o
obj = object  m = module 

KDIR is the directory where the linux headers are located

we can find the version using the command uname -r

Step 5 : Executing a make file

Just type 'make'

compiled files are created

Step 6 : Inserting the module into the kernel

sudo insmod firstkernal.ko 
and type
dmesg  : 

dmesg (for "display message" or "driver message" ) is a command on most Linux and Unix based operating systems that prints the message buffer of the kernel. 

 The output is 

Here I already I ran 3 times. The screen shot is for 4th time running "TEST : Hello world. this is jithu" is the output for the inserting a module

 Step 7 and final step : Removing the module from the kernel

sudo rmmod firstkernal.ko 

and type dmesg

 "TEST : Hello world. good bye" is the output for the removing a module 

That is the end of first basic kernel programming to print hello !! 


Wednesday, June 20, 2012

Server side installation in Ubuntu

Installation of PHP, MySQL and Apache in Ubuntu

step 1 :  sudo apt-get update
step 2 :  sudo apt-get install php5
step 3 :  sudo apt-get install apache2
step 4 :  sudo apt-get install mysql-server
step 5 :  sudo apt-get install php5-mysql

once the above steps are done we need to check

in ubutu

to check apache server

cd /var/www/

../var/www> ls

<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>

Go to web browser and type

to check php 

write a small php script 


echo "myFirst Php Script";

Go to web browser and type

to check mysql connection with php

write a small php script for connecting to mySql 


ini_set('display_errors', 1);
mysql_connect("localhost", "root", "jithu") or die(mysql_error());
echo "Connected to MySQL<br />";

Go to web browser and type

Thats the end of checking the working of apache, php and mysql

Next blog we will write small application !!

Apache php and MySQL

We need the following tools for creating and writing a server program.

picture :

1. PhP

PHP is a general-purpose server side scripting language originally designed for  web development to produce dynamic web pages. It is one of the first developed server-side scripting languages to be embedded into an HTML source document rather than calling an external file to process data.

This is quite simple and if you know the basics of programming languages, writing programs/ scripts in php is not a problem.

 2. Apache server

Apache is generally recognized as the world's most popular Web server (http server). Originally designed for Unix environments, the Apache Web server has been ported to Windows and other network operating systems.

As I mentioned in the earlier blog, it is widely used server and occupies almost 65 % market share.

3. MySQL
MySQL  is the world's most used open source relational database management systems. There are many advantages of using MySQL and PHP together

Benefits of MySQL:

Very low licensing cost
Low hardware consumption
Execute anything from data houses holding terabytes of data
Ultra-fast loading
Table and Index partitioning
Master/Slave replication with high speed reconfiguration utility
Multi-version Transaction support
Highly robust
Efficient query engine
Secure encryption decryption functions
Open source freedom

Benefits of PHP:

Easy to use
Simplified task handling in heavy traffic sites
Open source
Low cost
Being open source new functionality have been added consistently
Simple coding style

Ref :