PoiNtEr->: March 2012

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Tuesday, March 27, 2012

install Conky on Ubuntu (11.04,11.10 &12.04)


Conky is a free, light-weight system monitor for X, that displays any information on your desktop. There are many nice themes available for conky that can display clock, CPU usage, ram usage, swap,disk, net and more, one of these nice themes is Conky-Lua, this theme (See screenshots bellow) allow you to display nice rings for Clock,and cpu. This  theme is available for Ubuntu.
Install it using following command:


sudo apt-get install conky-all

Conky Bar
Now to get this theme follow these steps:

1:Download this file and extract it.There are three files in it.

2:copy .conkyrc to your home directory.

3:make a folder .conky in your home directory.
mkdir /home/vishal/.conky
copy other 2 files in this directory.

4:Now to get temperature of your zone open .conkyrc
and search for word "VILK".
Now goto http://weather.noaa.gov and find weather of your region...
there you will get a code similar to "VILK".Now just replace your region code with "VILK" and you are good to go...

5:To start conky at every system  startup make a shell file named conky.sh

add following lines in  it:
#!/bin/sh
sleep 20
conky

save it.
Now goto SYSTEM =>PREFERENCE=>STARTUP APPLICATIONS
And add an new entry as shown below (remember in Command attribute add location where you have stored your conky.sh file):

Monday, March 26, 2012

How To Use Grep Command In Ubuntu(Linux)

Grep Command(linux)
                                                              


The grep command is one of the most useful in Linux. It may not seem that exciting at first, but once you learn about pipes you'll begin to see why it's so indispensable.Put simply, grep searches through one or more text files for a specific word or phrase. For any lines it finds which include the specified word or phrase, it will display them on the screen. It will also work with standard output , when combined with pipes.
Simple example: Your name is vishal and you know that somewhere in your /home directory is a file you've written for work. Let's say you know that it has the word vishalmishra in it. So you can instruct grep to search through all the files in your home directory like this:
grep -r vishalmishra /home/vishal/*


if you wanted to make it include results in both upper and lower case, then use the -i option:
grep -ir vishalmishra /home/vishal/*



Suppose you want to see n lines after the match has found then use -A:
grep -A 3 -ir vishalmishra /home/vishal/*

Now above command will show you next 3 lines after the match word.


Suppose you want to see n lines before the match has found then use -B:
grep -B 3 -ir vishalmishra /home/vishal/*

Now above command will show you  3 lines before the match word.


Use -C option to Display N lines around the match:
 grep -C 3 -ir vishalmishra /home/vishal/*


Use -v option for invert match:
grep -v -r vishalmishra /home/vishal/*


If You want to count the number of matches then use -c option:
grep -c -r vishalmishra /home/vishal/*


If you want to known only file names that contain a specific match then use -l:
grep -l -r vishalmishra /home/vishal/*




Friday, March 9, 2012

Linux Signals – Example C Program to Catch Signal (SIGINT)


What is a signal? Signals are software interrupts.
A robust program need to handle signals. This is because signals are a way to deliver asynchronous events to the application.A user hitting ctrl+c, a process sending a signal to kill another process etc are all such cases where a process needs to do signal handling.
Linux Signals
In Linux, every signal has a name that begins with characters SIG. For example 
 * +--------------------+------------------+
 * |  POSIX signal      |  default action  |
 * +--------------------+------------------+
 * |  SIGHUP               |  terminate |
 * |  SIGINT                  | terminate |
 * |  SIGQUIT                | coredump |
 * |  SIGILL                     | coredump |
 * |  SIGTRAP                | coredump |
 * |  SIGABRT/SIGIOT    | coredump |
 * |  SIGBUS            | coredump |
 * |  SIGFPE            | coredump |
 * |  SIGKILL           | terminate(+) |
 * |  SIGUSR1           | terminate |
 * |  SIGSEGV           | coredump |
 * |  SIGUSR2           | terminate |
 * |  SIGPIPE           | terminate |
 * |  SIGALRM           | terminate |
 * |  SIGTERM           | terminate |
 * |  SIGCHLD           | ignore   |
 * |  SIGCONT           | ignore(*) |
 * |  SIGSTOP           | stop(*)(+)   |
 * |  SIGTSTP           | stop(*)   |
 * |  SIGTTIN           | stop(*)   |
 * |  SIGTTOU           | stop(*)   |
 * |  SIGURG            | ignore   |
 * |  SIGXCPU           | coredump |
 * |  SIGXFSZ           | coredump |
 * |  SIGVTALRM         | terminate |
 * |  SIGPROF           | terminate |
 * |  SIGPOLL/SIGIO     | terminate |
 * |  SIGSYS/SIGUNUSED  | coredump |
 * |  SIGSTKFLT         | terminate |
 * |  SIGWINCH          | ignore   |
 * |  SIGPWR            | terminate |
 * |  SIGRTMIN-SIGRTMAX | terminate       |
 * +--------------------+------------------+
 * |  non-POSIX signal  |  default action  |
 * +--------------------+------------------+
 * |  SIGEMT            |  coredump |
 * +--------------------+------------------+

Example C Program to Catch Signal "SIGINT"
//sigint.c
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
void sig_handler(int signo)
{
  if (signo == SIGINT)
    printf("received SIGINT\n");
}
int main(void)
{
  if (signal(SIGINT, sig_handler) == SIG_ERR)
  printf("\ncan't catch SIGINT\n");
  // A long long wait so that we can easily issue a signal to this process
  while(1) 
    sleep(1);
  return 0;
}


gcc -o sigint sigint.c
Output:



Friday, March 2, 2012

BSS Section in Process Structure

Global variable's life time is until the completion of the program. But what is the point of having two sections for global variables based on initialized and uninitialized. The point is to reduce the executable size of the program before going to discuss about the BSS section we need to understand what process structure, and how the structure looks in the memory (RAM) at the time of execution.


Program Memory Layout

If we are not initialized the global variables the loader will take care to initialize all global variables to zero (0). The loader is designed in such a way to initialize the global to zero while loading the process into RAM. If we are keeping initialized and uninitialized variable in the same block loader will initialize to zero for all the initialized variables too. Compiler developer decided to divide the global sectioninto two parts

1. DATA
2. .BSS

All initialized variable will go to DATA section, this will be decided in compilation time itself. But uninitialized variable will go into BSS section. This block will be created at the time of loading so it reduces the executable size of the program.


Now lets try out some example to proof how bss is effective save memory....

#include<stdio.h>
int a[10000000];
main()
{
long i;
for(i=0;i<10000000;i++)
printf("%d",a[i]);
}
//save it as bss.c
compile above program
>gcc -o bss bss.c
>ls -l bss
output:
-rwxr-xr-x 1 vishal vishal 7149 2012-03-02 19:44 bss
so size of this executable is 7149= around 7KB



#include<stdio.h>
int a[10000000]={1};
main()
{
long i;
for(i=0;i<10000000;i++)
printf("%d",a[i]);
}
//save it as ubss.c
>gcc -o ubss ubss.c
>ls -l ubss
output:-rwxr-xr-x 1 vishal vishal 40007193 2012-03-02 19:50 ubss
size of this executable is :40MB
because here a[] is initialized and memory is already allotted to it...

Thursday, March 1, 2012

How To Make A Operating System

                                                                                                  Eva Operating System                             




http://eva-os.blogspot.com/2012/03/how-to-make-operating-system.html