| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
|
Guest
Posts: n/a
|
Hi All,
I am getting this strange error on Intel MAC OS whereever i use times(NULL) function. I am using the following piece of code: #include <time.h> int main() { 1 clock_t myTime; 2 myTime = times(NULL); 3 return(0); } The progarm compiles sucessfully, but on running the application, it throws the following error at line 2: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000 0x900a3fb2 in times () Can anybody help me out with this problem. This seems to be Intel MAC specific. I dont face any issue with this piece of code on any other unix based system. Thanks a lot in advance |
| QUOTE Thanks | |
|
Guest
Posts: n/a
|
I Also understand that this function is obselete since 10.4.x MAC and has been replaced by gettimeofday and getrusage. However, gettimeofday returns the time in seconds, whereas i need the output of current time in clock ticks as given by times() function.
I really need an answer to this one soon. All help is highly appreciated. Thanks in advance -Sachin |
| QUOTE Thanks | |
![]() Member Since: Jun 06, 2006
Posts: 1,153
![]() ![]() ![]() ![]() ![]() ![]() Mac Specs: MacBook 2.0GHz White, 512MB RAM, 60GB HDD
|
|
| QUOTE Thanks | |
|
Guest
Posts: n/a
|
Thanks for the response Cazabam.
However, I did exactly the same before seeking help in this forum. But i have one issue regarding it. Kindly do correct if i am wrong in my assumption. I tried the following on linux where i have times function running fine: gettimeofday(&tp, NULL); clocks_per_second = sysconf(_SC_CLK_TCK); cpu_time = (tp.tv_sec * CLOCKS_PER_SEC); tm = times(NULL); However the output of cpu_time and tm is not the same. Isnt it supposed to be same if even times function does the same. The 2 values are coming out to be quite different, which made me dubious if this is the right way of calculating the value of time in clock ticks. Hoping for a quick early response. Thanks -Sachin |
| QUOTE Thanks | |
![]() Member Since: Sep 21, 2004
Posts: 199
![]() ![]() ![]() Mac Specs: MacBook Pro 15" 2.16Ghz Core Duo 1GB Ram 80GB
|
|
| QUOTE Thanks | |
![]() Member Since: Jun 06, 2006
Posts: 1,153
![]() ![]() ![]() ![]() ![]() ![]() Mac Specs: MacBook 2.0GHz White, 512MB RAM, 60GB HDD
|
avcabob has a point, that the two are several clock ticks apart (possibly several hundred, depending on what comes back from sysconf. How different are the two numbers that are being returned?
However, the immediate problem I see with your implementation is that you have not taken into account the microsecond count. This can account for a difference of up to 1 second of clock ticks. Try this instead: Code:
// Get the output from the times() function for comparison
clock_t clk;
struct tms tm;
clk = times(&tm);
printf("Output from times(): %u\n", clk);
// Get the time in seconds
struct timeval tv;
gettimeofday(&tv, NULL);
// ... and the ticks per sec
long ticks_per_sec = sysconf(_SC_CLK_TCK);
// The whole seconds ...
unsigned long ticks = tv.tv_sec * ticks_per_sec;
printf("Exclude usec portion: %u\n", ticks);
// ... and the microsecond portion
ticks += (ticks_per_sec * tv.tv_usec) / 1000000;
printf("Include usec portion: %u\n", ticks);
Code:
Output from times(): 3764629764 Exclude usec portion: 3764629704 Include usec portion: 3764629764 |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Hacker Upgraded Intel Mac Mini with Merom/Core 2 Duo Chip | techster82 | Apple Rumors and Reports | 16 | 06-15-2006 07:40 PM |
| Intel Mac Mini in for service | bowadoyle | Apple Desktops | 7 | 06-10-2006 10:10 PM |
| Mac Mini - Is it worth waiting for Intel? | y2kt | Apple Desktops | 2 | 02-13-2006 02:39 PM |
| To Swich or Not To Swich, That is the Question | EDIT-XTREEM | Switcher Hangout | 5 | 01-26-2006 04:28 PM |
| Mac Users Get More ISP Choices | schweb | Apple Rumors and Reports | 1 | 03-06-2003 10:57 AM |
All times are GMT -4. The time now is 03:55 AM.
Powered by vBulletin