All about programming in GNU/LINUX

Illustration of sleep system systm call in GNU/LINUX using a simple program

//download link for the file: http://www.slideshare.net/hackintoshrao/time2c-10761496
/* Hackintosh Rao , Codes for GNU/LINUX \m/ */
/*system calls used :sleep(int sec)         */
/*Sleep system call pauses the execution of instructions for specified no.of.seconds*/
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int i;
    for(i=0;i<10;i++)
      printf(“\n\t\tWithout time delay”);
      sleep(2);
    printf(“\nWait and watch how the execution halts for 2 seconds each time when SLEEP is called”);
    sleep(2);
    printf(“\nLOADING”);
    for(i=0;i<10;i++)
     {
         printf(“\n# “);
         sleep(2) ;/*the argument for sleep system call is an integer duration in sec for which
                      you want the exection of the instructions to be put to pause */

     }
     exit(0);
}

Advertisements

2 responses

  1. What happens If I give negative number to the sleep command ?

    January 5, 2012 at 12:20 am

  2. There will no error or a warning ….. the program just sleeps and never wakes up 🙂

    January 5, 2012 at 2:53 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s