×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

## Operating Systems

by: Mireya Heidenreich

10

0

3

# Operating Systems CS 3733

Mireya Heidenreich
UTSA
GPA 3.55

Steven Robbins

These notes were just uploaded, and will be ready to view shortly.

Either way, we'll remind you when they're ready :)

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

COURSE
PROF.
Steven Robbins
TYPE
Class Notes
PAGES
3
WORDS
KARMA
25 ?

## Popular in ComputerScienence

This 3 page Class Notes was uploaded by Mireya Heidenreich on Thursday October 29, 2015. The Class Notes belongs to CS 3733 at University of Texas at San Antonio taught by Steven Robbins in Fall. Since its upload, it has received 10 views. For similar materials see /class/231380/cs-3733-university-of-texas-at-san-antonio in ComputerScienence at University of Texas at San Antonio.

×

## Reviews for Operating Systems

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/29/15
91 302 Chapter 9 Times and Timers POSIX Times POSIX speci es that systems should keep time in terms of seconds since the Epoch and that each day be accounted for by exactly 86400 seconds The Epoch is de ned as 0000 midnight January 1 1970 Coordinated Universal Time also called UTC Greenwich Mean Time or GMT POSIX does not specify how an implementation should align its system time with the actual time and date Most operations need to be measured with timers with greater than onesecond resolu tion Two POSIX extensions the POSIXXSI Extension and the POSIXTMR Extension de ne time 39 39 of 39 39 and 39 39 39 r Expressing time in seconds since the Epoch The POSIX base standard supports only a time resolution of seconds and expresses time since the Epoch using a timeit type which is usually implemented as a long A program can access the system time expressed in seconds since the Epoch by calling the time function If tloc is not NULL the time function also stores the time in thC SYIVOPSIS include lttime hgt timeit timetime7t tloc POSIX CX If successful t ime returns the number of seconds since the Epoch If unsuccessful t ime returns timeit 71 POSIX does not de ne any mandatory errors for time D Exercise 91 The timeit type is usually implemented as a long Ifa long is 32 bits at ap proximately what date would timeit over ow Remember that one bit is used for the sign What date would cause an over ow if an unsigned long were used What date would cause an over ow if a 64bit data type were used Answer For a 32bit long time would over ow in approximately 68 years from January 1 1970 so the system would not have a Y2K problem until the year 2038 For a timeit value that is an unsigned long the over ow would occur in the year 2106 but this would not allow time to return an error For a 64bit data type the over ow would not occur for another 292 billion years long after the sun has died The diff t ime function computes the difference between two calendar times of type timeit making it convenient for calculations involving time The difftime function 91 POSIX Times 303 has two timeit parameters and returns a double containing the rst parameter minus the second SYIVOPSIS include lttime hgt double difftimekimeit timel timeit timeO POSIX CX No errors are de ned for difftime I Example 92 The following program calculates the wallclock time that it takes to execute functionitoitime include ltstdiohgt include lttimehgt void functionitoitime void int mainvoid timeit tstart tstart timeN ULL functionitoitime U printfquotfunctionitoitime took at seconds of elapsed timenquot difftime time NULL tstart return 0 simpletiming c Example 92 uses a time resolution of one second which may not be accurate enough unless f unctionitoitime involves substantial computation or waiting Also the time function measures wallclock or elapsed time which may not meaningfully re ect the amount of CPU time used Section 915 presents alternative methods of timing code Displaying date and time The timeit type is convenient for calculations requiring the difference between times but it is cumbersome for printing dates Also a program should adjust dates and times to account for factors such as time zone daylightsaving time and leap seconds The localtime function takes a parameter specifying the seconds since the Epoch and returns a structure with the components of the time such as day month and year adjusted for local requirements The asctime function converts the structure returned by localtime to a string The Ctime function is equivalent to asctime localtime clock The gmtime function takes a parameter representing seconds since the Epoch and returns a structure with the components of time eXpressed as Coordinated Universal Time UTC 304 Chapter 9 Times and Timers SYIVOPSIS include lttime hgt char asctimeconst struct tm timeptr char ctimeconst timeit clock struct tm gmtimeconst timeit timer struct tm localtimeconst timeit timer POSIX CX No errors are de ned for these functions The Ctime function takes one parameter a pointer to a variable of type timeit and returns a pointer to a 26character Englishlanguage string The Ctime function takes into account both the time zone and daylight saving time Each of the elds in the string has a constant width The string might be stored as follows Sun Oct 06 022135 1986n0 I Example 93 The following program prints the date and time The printf format did not include n39 because Ctime returns a string that ends in a newline include ltstdiohgt include lttimehgt int mainVoid i it tcurrent tcurrent time NULL printfquotThe current time is as ctimeamptcurrent return 0 Exercise 94 What is wrong with the following program that prints the time before and after the function funct i omit oft ime executes include ltstdiohgt include lttime hgt Void functionitoitime Void int mainVoid t meit tend tstart tstart timeN39ULL tend time NULL printfquotThe time before was sThe time after was as ctime amptstart ctime amptend return 0

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Janice Dongeun University of Washington

#### "I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

Steve Martinelli UC Los Angeles

Forbes

#### "Their 'Elite Notetakers' are making over \$1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com