SwamiSathappan's Blog...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

March 11, 2010

Money, Time and Energy

==When you are a kid, you will have energy and time, but no money
==When you are an adult, you will have energy and money, but no time
==When you are old, you may have both time and money, but no energy to enjoy the life.
Guess these words holds good for anyone.. :)

February 26, 2010

Writing a Daemon in Linux

Here is the sample C code on how to create a Daemon and play around with the PIDs. I am also a starter; comment if there is anything wrong!!! Let me know if you have any questions..

#include
#include
#include
#include
#include
#include
#include
#include
#include

int main(void) {
      
    /* Our process ID and Session ID */
    pid_t pid, sid;
    int seconds=0;
      
    /* Fork off the parent process */
    printf("Creating Child Process:\n ");
    pid = fork();
    printf("fork completed: pid = %d\n ", pid);
    if (pid < 0) {
        exit(EXIT_FAILURE);
    }
    /* If we got a good PID, then
    *  we can exit the parent process. */
    if (pid > 0) {
        exit(EXIT_SUCCESS);
    }

    printf("Creating child process success\n ");
    /* Change the file mode mask */
    umask(0);
              
    /* Open any logs here */      
              
    /* Create a new SID for the child process */
    sid = setsid();
    printf("Set Session ID = %d\n", sid);
    if (sid < 0) {
        /* Log the failure */
        exit(EXIT_FAILURE);
    }
      

    printf("Session ID creation success, now changing dir\n");
      
    /* Change the current working directory */
    if ((chdir("/")) < 0) {
        /* Log the failure */
        exit(EXIT_FAILURE);
    }
     
    /* Daemon-specific initialization goes here */
      
    /* The Big Loop */
    printf("$$$Daemon Started running$$$ \n");
    while (1) {
        /* Do some task here ... */
        /* Insert your task HERE.... which need to run in this process */
        printf("Daemon running at second-%d !!!!\n", seconds++);
        sleep(1); /* wait 1 second(s) */

        /* Daemon will be running for 100seconds */
        if (seconds == 100){
            printf("Daemon terminating at %d seconds!!!!\n", seconds);
            /* Close out the standard file descriptors */
            close(STDIN_FILENO);
            close(STDOUT_FILENO);
            close(STDERR_FILENO);
            break;     
        }      
    }
    exit(EXIT_SUCCESS);
}

November 13, 2009

INDIA - Google Doodle Contest Winner


INDIA - Google Doodle Contest Winner. Yeah, this is Google's home page Image which got first prize in India's Google Doodle Contest. It was created by young boy, "Puru Pratap Singh" from Gurgoan. Description given for painting was: "India is a country which has a blend of thousands of traditions and all religions like Hinduism, Christianity, Sikhism and Islam. It has developed a lot in the past few years. The discovery of water on the moon by the Indian scientists is a proof to this fact. The Indian culture is as vibrant as the colours of the peacock. Kashmir, the crown of India, is as serene as the peace bird and as pure as the lotus. We, the Indian citizens are also trying to fulfill Mahatma Gandhi’s dream of educating each and every Indian child."  Wow, what an art in the age of 9 itself. Yes, he is studying only Class IV. He is the first among 4,000 other participants. Nice theme. If you want to see it live, just open Google India's HomePage and you can see the Doodle. http://www.google.co.in/. For the list of other arts/paintings participated, visit: http://www.google.co.in/intl/en/doodle4google/vote.html#d=d2-8

Search SwamiSathappan's Blog

Currency Converter

About Me