Tuesday, 12 August 2014

top and htop commands in Linux

        Linux provides utilities called top and htop to monitor the real time processes. They displays the dynamic real-time view of the running system. But, both the command are quite different in action.
Top command displays the Linux processes. It can display system summary information and processes or threads currently managed by the kernel.  When we type top in terminal we get the currently running process as shown in Fig 1.

                                              Fig 1:top  displaying running processes

Even though htop is quite similar to top there are some extra features that makes htop better command utility than top. The htop utility is not already built in Linux, it should be downloaded and installed. Once it is installed  it can be run through command line by just typing 'htop' (We can install it by just typing sudo apt-get install htop)

The Fig 2 shows the htop window look like,

                                                          Fig 2 :htop window

Now let's see what htop displays,

The top left corner:
The numbers 1,2,3 and 4 represents the number of cores in the system. The bars next to these numbers shows the loads on the cores. The colour difference in the bars represent different information. Below that lies memory and swap information.

The top right corner:
Here information related to  loads, threads, load average and up time are displayed. Load average is the amount of work that system does. Here in my system load average is 0.34 which means very less load on CPU. If it goes up to 2 it means that system is making use of CPU 100%.

Process related information:
The information about each process is divided into columns. The explanation of each column is as follows:

     PID: Process ID of a process
    USER: User owning the process
    PR: Priority of the process.
    NI: The nice value for a process.
    VIRT: Virtual memory consumption.
    RES: Physical RAM consumption in kilobytes.
    SHR: Shared memory consumption.
    S: Process status (sleeping, running etc).
    CPU%: CPU consumption
    MEM%: Physical RAM consumption.
    TIME+: Processor time used by the process.
    COMMAND: Command that started the process.

Htop provides many features to customize it according to user's taste. At the bottom of the htop window we can see F-keys and its function written next to them.

Saturday, 2 August 2014

Installing MariaDB

You can know what is MariaDB from my previous blog http://amruthasangeeth.blogspot.in/2014/06/mariadb_17.html

Now let’s see the installation of MariaDB
Step 1
First make sure that required packages are installed and  add apt-get key for Mariadb repository using following command
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

Add apt-get repository as per your Ubuntu version
For Ubuntu 13.10
$ sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/5.5/ubuntu saucy main'
For Ubuntu 13.04
$ sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/5.5/ubuntu raring main'
For Ubuntu 12.10
$ sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/5.5/ubuntu quantal main'
For Ubuntu 12.04 LTS
$ sudo add-apt-repository 'deb http://ftp.kaist.ac.kr/mariadb/repo/5.5/ubuntu precise main'

Step 2
Install MariaDB using the following commands
$ sudo apt-get update
$ sudo apt-get install mariadb-server

Provide the root account password as given below

Step 3

Login to MariaDB using the following command after installation
mysql -u root -p

Creating a database in MariaDB
Entering the account administrator password set up during installation you will be given a MariaDB prompt.

We will create a database to learn on called students using the following command
We will switch to the new database
USE  students;
Now the database is created and we can create a table.
CREATE TABLE details(student_id int(5) NOT NULL AUTO_INCREMENT,
                        name varchar(20) DEFAULT NULL,
                        age int(3) DEFAULT NULL,
                        marks int(5) DEFAULT NULL,
                        PRIMARY KEY(student_i)d
To accomplish what we have done, use the following command,
show columns in details;

Each column in table creation command is separated by comma and follows this fashion,
Column_Name Data_Type[(size_of_data)] [NULL or NOT NULL] [DEFAULT default_value]

The values of each column definition are,
* Column Name: Describes the attribute being assigned.
* Data Type: Specifies the type of data in the column.
* Null: Defines whether null is a valid value for that field. Can be "null" or "not null".
* Default Value: Sets the initial value of all newly created records that do not specify a value.
* auto_increment: MySQL will handle the sequential numbering internally of any column marked with this   option, in order to provide a unique value for each record.

Ultimately before closing the table definition we need to use primary key by typing PRIMARY KEY(column name).It guarantees that , this column will serve as a unique field.

Inserting data into MariaDB table
INSERT INTO details(name,age,marks) values ("anu",15,450);

INSERT INTO details(name,age,marks) VALUES("Bob",15,400);

We need not add values in student_id.It is automatically incremented.All other values are given in quotes.

Deleting a table
To delete a table, type the following command
DROP TABLE table_name;
Once the table is deleted, the data inside it cannot be recovered.

Now we can view the current table using “show tables” command. This command gives all the tables inside the database.
SHOW tables;
Then, after deleting the table.
DROP TABLE details;
Query OK, 0 rows affected (0.02 sec)

SHOW tables;