Timesleep

1

Click here to load reader

description

Illustration of sleep , difftime and time system call in GNU/LINUX

Transcript of Timesleep

Page 1: Timesleep

/* HACKINTOSHRAO , CODES FOR GNU/LINUX \m/ simple illustration of time and difftime system call in GNU/LINUX system calls used: 1)time_t time(time *) ;go to /usr/include and use "grep time_t *" 2)double difftime(time2,time1);go to /usr/include and use "grep -l difftime *" 3)void sleep(int sec); */

#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<time.h>

int main(){ time_t time_1970,time2_1970;//time_t is a built in data type and is used to store very large numbers int i; double timedifference; for(i=0;i<10;i++) {

time_1970=time((time_t *)0); /*time system call takes in a NULL argument and returns no.of.seconds eclapsed since 1970*/

printf("\nThe no.of.seconds passed from 1970 is:%ld ",time_1970); sleep(3); /*sleep system call halts or pauses the execution for no.of.seconds mentioned as arguments to the call*/ time2_1970=time((time_t *)0); timedifference=difftime(time2_1970,time_1970); /*difftime is a system call which returns back the time difference in seconds as a double b/w its 1st and 2nd argument of type time_t*/ printf("\n\nHey !! The program was paused for %f seconds",timedifference);

} exit(0);}