Lecture 7 - Timers and Signals

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

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

1 Time, Timers and Signals Intro to function pointers

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

View Full Document
2 Applications of Times and Timers Process scheduling Timeouts network protocols User input Periodic updates and system statistics Event management
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)

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

View Full Document
4 POSIX Extensions POSIX:XSI Extension microseconds resolution POSIX:TMR nanoseconds resolution
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

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

View Full Document
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
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);

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

View Full Document
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 ; }
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);

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

View Full Document
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 */ };
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.

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

View Full Document
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 ; }
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

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

View Full Document
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 ; }
15 Date and Time

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

View Full Document
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
Ask a homework question - tutors are online