Lecture 7 - Timers and Signals

Lecture 7 - Timers and Signals - Time, Timers and Signals...

Info iconThis preview shows pages 1–16. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Time, Timers and Signals Intro to function pointers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Applications of Times and Timers Process scheduling Timeouts network protocols User input Periodic updates and system statistics Event management
Background image of page 2
3 POSIX Time POSIX specification Time in terms of seconds since Epoch 1 day = 86,400 secs Epoch 00:00 (midnight), January 1, 1970 Coordinated Universal Time (UTC or Greenwich Mean Time GMT)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 POSIX Extensions POSIX:XSI Extension microseconds resolution POSIX:TMR nanoseconds resolution
Background image of page 4
5 Time Since Epoch NAME time - get time in seconds RETURN time in seconds since epoch SYNOPSIS #include <time.h> time_t time(time_t *t); PARAMETER time is also stored in *t if t is not NULL
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Notes on time time_t time resolution in seconds usually as big as long data type How long does it take for time_t to overflow? 32-bit => Signed = 2 billion seconds from 1970 ( 2038 ) Unsigned = 4 billion seconds from 1970 ( 2100 ) 64-bit => much much longer
Background image of page 6
7 Time Difference NAME difftime - calculate time difference RETURN time difference in seconds SYNOPSIS #include <time.h> double difftime(time_t time1, time_t time0);
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 difftime() sample #include <stdio.h> #include <time.h> int main ( void ) { time_t t0; int i = 7 ; int y; t0 = time(NULL); while (i > 0 ) { i -- ; y = 0xFFFFFFF ; while (y > 0 ) y -- ; } printf( "Executed in %lf seconds.\n" , difftime(time(NULL), t0)); return 0 ; }
Background image of page 8
9 Date and Time NAME ctime, gmtime, localtime, mktime, asctime transform date and time to broken-down time or ASCII SYNOPSIS #include <time.h> char *ctime(const time_t *timep); struct tm *gmtime(const time_t *timep); struct tm *localtime(const time_t *timep); char *asctime(const struct tm *tm); time_t mktime(struct tm *tm);
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 struct tm struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ };
Background image of page 10
11 Date and Time gmtime() converts the calendar time timep to broken-down time representation, expressed in Coordinated Universal Time (UTC) localtime() converts the calendar time timep to broken-time representation expressed relative to the user's specified time zone.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 localtime() #include <stdio.h> #include <time.h> int main ( void ) { struct tm * current; time_t t = time(NULL); current = localtime( t); printf ( "%d days before Xmas\n" , 359 - current -> tm_yday); return 0 ; }
Background image of page 12
13 Date and Time asctime() Converts broken-down time into string It converts the calendar time_t into a string of the form "Wed Jun 30 21:49:08 1993\n" mktime() Converts broken-down time into time_t
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 asctime() #include <stdio.h> #include <time.h> int main ( void ) { time_t t0; t0 = time (NULL); printf ( "%s" , asctime(localtime( t0))); /* Mon Aug 4 13:20:25 2008 */ return 0 ; }
Background image of page 14
15 Date and Time
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2011 for the course EEEI 13 taught by Professor Ramos during the Winter '10 term at University of the Philippines Diliman.

Page1 / 67

Lecture 7 - Timers and Signals - Time, Timers and Signals...

This preview shows document pages 1 - 16. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online