Tuesday, February 9, 2010

Deamonous Indeed - > Linux Deamons

What is a Deamon ??
A deamon, in a multiprogrammed environement  is a process running in the background and not under the direct supervision of the user.

They are usually initialised , by the init process ( pid =1 ) . They are usually forked , by the parent process and are dropped by the parent process , causing init to take over the process . They are not attached to any terminals ,ie standard input devices.
They are , used for handling tasks , such as auditing kernel messages and handling network requests.

Examples:
1) auditd -> which facilitates , the kernel auditing facilities.
2) initd -> Which is the initialisation demon.
3) avahi deamon -> Which is the deamon , for handling network requests (DHCP).


Feel free to Comment.


Wednesday, February 3, 2010

Mirroring MySQL database



As I was learning Data Mining , where we study the importance of commercial data , and mirroring as a backup measure , I thought of "googling" for a simple application , which could mirror my database onto another host on the network . The below given example , can transfer a complete database to another , within any host. My next post shall help mirroring data to another network host.

The code is in PHP:

$adminc=@mysql_connect("localhost","admin","pesit123") OR die('Couldn\'t connect to MySql:'.mysql_error());


$result = mysql_list_tables ("admin");

while ($table_row = mysql_fetch_row($result)) {

$table = $table_row[0];
$qry="drop table if exists adminmirror".$table;
mysql_query($qry)or die("Failed to delete:".mysql_error());

$query= "create table adminmirror.".$table." LIKE admin.".$table;
mysql_query($query)or die("Table create failed:".mysql_error());
$query="Insert INTO adminmirror.".$table." SELECT * FROM admin.".$table;
mysql_query($query)or die("Table copy failed:".mysql_error());
echo "$table copy done...";
}
? >

Please incorporate the required changes in the database names , so as to mirror the database.

Please feel free to Comment .

Wednesday, January 27, 2010

Think Parallel With Open MP

Ya pretty significant article this , due to the rapid development of MultiCore technologies , to take advantage of the multithreaded aspects of processes.

Open MP is a platform for writing parallel programs in C , C++ or Fortran in the form of library routines and environment variables.

The main advantage is the conversion of existing serialised code , into parallel codes. So , if we would like to use the multicore aspect of our processors , this platform is the place to start.

This platform is maintained by market leaders , such as AMD,Cray,HP,IBM,INTEL,Microsoft etc..

To find a list of supported compilers visit:

SUPPORTED COMPILERS

and for more info on the platform ,visit

http://openmp.org/

You can try this Simple Code Snippet :


// A program to test the working of open MP platform on fedora 12 (TRIED BY ME ELSE INSTALL IT ON YOUR PLATFORM)
// Author : Prashanth R
include omp.h and stdio.h
 

int main(){
int nthreads,tid;
omp_set_num_threads(3);
/*parallel code here*/

#pragma omp parallel
{
tid = omp_get_thread_num();
printf("Called by thread %d \n",tid);

if(tid==0){
nthreads = omp_get_num_threads();
printf("The number of threads is %d \n",nthreads);
}
}
return 0;
}


compile the following code as :
gcc -fopenmp filename.c

As usual feel free to comment .

Wednesday, January 20, 2010

VLC media player installation in Fedora 12

This article of mine is conceptually unique , in the aspect that I am not focussing on any conceptual view , by theory . Let's try to understand package management in RPM based Linux installations, to get an overview and understanding of package management in LINUX.

Let me also try to simplify the process to remove the myth about the difficulty in LINUX application installation procedure .

Y package management ?
Package management is basically used to customise an installation , after it has been installed . Administrators and users , always get a basic system installed and customise it as per their requirement. 

Anectode : We have a cup of black tea with us . It is our choice to either add milk or any other flavour of our choice. This adds flexibility to the OS installation.

What is RPM package manager ?

 RPM - RedHat Package Manager, is the environment , which provides safe installation of LINUX applications , in the form of packages , which can be easily added , created or upgraded . Today, if we are easily , able to install packages without manually resolving dependencies ,we must be thanking the developers of such package management utilities.


Today RPM is also called as "RPM package manager" as a recursive acronym.


The local RPM database (1)
 

Working behind the scenes of the package manager is the RPM database, stored in /var/lib/rpm. It uses Berkeley DB as its back-end. It consists of a single database (Packages) containing all of the meta information of the installed rpms. Multiple databases are created for indexing purposes, replicating data to speed up queries. The database is used to keep track of all files that are changed and created when a user (using RPM) installs a package, thus enabling the user (via RPM) to reverse the changes and remove the package later. If the database gets corrupted (which is possible if the RPM client is killed), the index databases can be recreated with the rpm --rebuilddb command.




What is a package ?


A package is an archive of related files to any application or program. These also include special metadata , to support the installation of the application  , along with the installation binaries (like RPM files) .

Let us consider , a simple example of installing vlc media player for FEDORA 12 . Installing any other package , follows a very similar suite.

1) su root
2) rpm -ivh http://download1.rpmfusion.org/free/fedora/
                           rpmfusion-free-release-stable.noarch.rpm
3) yum install vlc
 
The first command is to run the session as a previledged user , to administer the 
installations on the machine. 
The second command , installs the specified RPM (in this case a URL) , and displays 
the progress of installations , which  we can observe .
The third command adds some flavour , to install dependencies associated with the related package.
Easy is'nt it ? 
Spread the LINUX flavour by exploring various installations. 
As usual feel free to comment.













Intelligent Compiling Utility for Linux - make

This post is basically to introduce a simple introduction to the make utility of UNIX.


The make utility is a software engineering tool for managing and maintaining computer programs. Make provides most help when the program consists of many component files. As the number of files in the program increases so to does the compile time, complexity of compilation command and the likelihood of human error when entering command lines, i.e. typos and missing file names.

By creating a descriptor file containing dependency rules, macros and suffix rules, you can instruct make to automatically rebuild your program whenever one of the program's component files is modified. Make is smart enough to only recompile the files that were affected by changes thus saving compile time.



For complete documentation , refer :

Monday, January 18, 2010

Oopc a great misconception to be solved ->> C it!!!!!!

All of us are hell-bent on the fact that C is a procedure - oriented language . But , that happens to be a misconception , to be solved . ANSI-C is said to be a fully fledged Object Oriented Language.

For a complete reference guide for Object Oriented Programming in C :
http://www.planetpdf.com/codecuts/pdfs/ooc.pdf

Hope this removes a big misconception.

Saturday, January 16, 2010

Anaconda Linux Installer Brrrrrrr it's scary indeed ........

What is Anaconda ?

Anaconda is the installer for many Linux packages .

Examples of Operating systems which use Anaconda :

1) Red Hat
2)Fedora
3)CentOS
4) Sabayon

and many more in the Red Hat bandwagon .

It is developed using C and python,with the graphical front end developed using PyGtk and text front end using newt .

Sample Installer picture :




Useful Links :
1) http://fedoraproject.org/wiki/Anaconda ,for the fedora implementation .

Hope this helped you. You are welcome to comment.

Friday, January 15, 2010

dmesg Command in Linux

This article serves as an introduction , to one of the rarely known UNIX commands to general under-graduate students , the "dmesg" command .


Definition :
dmesg - print or control the kernel ring buffer  .


What do we mean by the term Kernel Ring Buffer ?


In simplest terms it is a log which contains messages from the kernel .


For example we can try a simple command :


[root@localhost]#dmesg | grep Memory 
[    0.000000] Memory: 371348k/393152k available (4565k kernel code, 21120k reserved, 2143k data, 540k init, 0k highmem) 


This command gives certain information about the memory reserved by the kernel at boot time .


Uses of dmesg command:


1) Useful to extract information , about the functioning of various kernel modules basically the device drivers.


Therefore , this message was  logged in by the kernel at the time of file system mounting and can be extracted using the dmesg utility .


Useful Links :
1 ) http://ftp-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.2/suselinux-adminguide_en/ch29s09.html 
Offers a simple and an effective example .



2) For more advanced usage of dmesg command refer :
http://www.linfo.org/dmesg.html
 The link mentioned , also provides the answer to the general query of what is a Ring Buffer.




 For those interested to see the file from which we can see the input file to the dmesg command ,
open the file /var/log/dmesg with any standard text editor.




Hope this solves some of your queries.




WAKING UP LINUX : An introduction to the LINUX boot sequence .

The article is intended at understanding one of the basic concepts of LINUX, it's boot sequence .

A very important note is that the boot sequence is system architecture dependent .

To simplify things let us get an overview in terms of a simple diagram :



Reference : http://www.ibm.com/developerworks/linux/library/l-linuxboot/fig1.gif

Let us handle the issue in terms of the various stages mentioned in the figure above :

Step1 ) Loading up the BIOS :

This is an OS independent process (Quite inferable) .

1) Even though we hardly deal with switches and cables to boot a system these days , the process is still the same and to make a computer enthusiast's job simple , the boot process is identical on all processor architectures .

2) The BIOS is first program plugged in from a fixed location of the firmware ( the motherboard ) .This fixed location could be a flash memory / the ROM itself.
The BIOS , these days have so many options to allow us to boot into the system . We could set the boot from the DVD/USB and various  other options seen at the system startup .

A sample can be seen as depicted in the figure below :


The BIOS , later boots the stage 1 boot loader whose basic function , is to locate a more advanced boot loader also called as the Stage 2 boot loader .

So let's skip the functions of the 1st stage boot loader and move on to the next one i.e the Stage 2 boot loader .

Step 2) Functions of the Stage 2 boot loader :
As a first step for all who wish to know more about LINUX kernel images visit ,
LINUX Kernel Image , to get  a very brief  and a handy introduction .

The Stage 2 boot loader loads both the LINUX kernel image and the initial file system . At this point , the Stage 2 boot loader verifies the device attached to the system and interfaces them for the OS to get ready to use them.

At this stage , the kernel is decompressed and the root file system is mounted . Along with this the Stage 2 boot loader initialises the basic kernel modules into functioning before it hands control to the Kernel .

Stage 3) The LINUX kernel:

The Linux kernel , initialises the first user process i.e init and then the high-level initialiasation is performed to complete the process of booting .