{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 7 - Timers and Signals

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

This preview shows pages 1–17. 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 ctime() Functions all take an argument of data type time_t Equivalent to asctime(localtime(t)) It converts the calendar time_t into a string of the form "Wed Jun 30 21:49:08 1993\n" Uses a static variable to store converted time in string format

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

View Full Document
16 ctime() #include <stdio.h> #include <time.h> int main ( void ) { time_t t0; t0 = time (NULL); printf ( "%s" ,ctime( & t0)); /* Mon Aug 4 13:20:25 2008 */ return 0 ; }
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern