Sponsored Content
Top Forums UNIX for Dummies Questions & Answers clock() call returning zero always Post 302118392 by Perderabo on Monday 21st of May 2007 08:23:10 PM
Old 05-21-2007
clock() is subroutine, not a system call on FreeBSD. And the man page says:
Quote:
Do not use clock(3) in new programs under FreeBSD. It is feeble compared with getrusage(2). It is provided for ANSI conformance. It is implemented by calling getrusage(2) and throwing away information and resolution.
So while it is possible that clock() is misbehaving, I have to think that you aren't looking at the man pages very closely. You could be invoking clock() wrong or be expecting it to report elasped time rather than cpu utilization. And yes, it would not surprise me too much if several consecutive calls to clock() returned zero provided that the program was using very little cpu. I would follow the man page's advice and switch to getrusage().
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Clock Trouble

Hey ppl, i was wonddering, in mandrake, how to get the clok to display the time in non-military format....hehe thank you im just tired of looking at 18:00 hehe thank you (2 Replies)
Discussion started by: LolapaloL
2 Replies

2. Programming

clock() function

Hey all, i need a program to get the CPU ticks at certain points of my program. So, i thought about using the clock function, but i'm having a hard time figuring out how it really works. I wrote this simple program to try to understand it but it made me feel more confused: #include <stdio.h>... (5 Replies)
Discussion started by: kastrup_carioca
5 Replies

3. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

4. UNIX for Advanced & Expert Users

clock change

Hi We had a AIX box built last year but was set to the correct GMT time, but using DST time zone. In march this year the clocks went forward without issues. (if I remember a couple of weeks early due to the DST zone) This year we decided to change the clock to the correct time zone before... (0 Replies)
Discussion started by: markab2
0 Replies

5. Solaris

Bugs with clock()

Hi there!!! Need your help in solving some tricky problems. Since clock() as such is buggy on SUN OS 5 we have started using gettimeofday() in our RTOS applications based on Solaris 9. The problems we actually encountered previously were - the applications kind of freeze/hang eternally on... (1 Reply)
Discussion started by: smanu
1 Replies

6. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

7. Programming

problem with clock()

#include<iostream> #include<time.h> using namespace std; int main() { system("date"); clock_t start = clock(); int i=9*8; while(i--) { int j=9999999; while(j--); } clock_t end = clock(); double elapsed =... (4 Replies)
Discussion started by: johnbach
4 Replies

8. UNIX for Dummies Questions & Answers

Showing Clock

Is it possible to display the clock (timing) on the screen all the time. (3 Replies)
Discussion started by: vino.paal
3 Replies

9. UNIX for Advanced & Expert Users

Xt timer call, XtAppAddTimeout, hangs on system clock jump backwards

Hi, I've got an issue which I've been 'google-fu'ing without much luck. We have a legacy program which has been plagued by an issue for a long time and I've been tasked to investigate/fix. The program uses XMotif2.1 (required due to dependency on an old GUI designer) and runs on a RHEL7... (4 Replies)
Discussion started by: altrefrain
4 Replies
CLOCKS(7)					       BSD Miscellaneous Information Manual						 CLOCKS(7)

NAME
clocks -- various system timers SYNOPSIS
#include <time.h> DESCRIPTION
HZ is not part of the application interface in BSD. There are many different real and virtual (timekeeping) clocks with different frequencies: o The scheduling clock. This is a real clock with frequency that happens to be 100. It is not available to applications. o The statistics clock. This is a real clock with frequency that happens to be 128. It is not directly available to applications. o The clock reported by clock(3). This is a virtual clock with a frequency that happens to be 128. Its actual frequency is given by the macro CLOCKS_PER_SEC. Note that CLOCKS_PER_SEC may be floating point. Do not use clock(3) in new programs under FreeBSD. It is feeble compared with getrusage(2). It is provided for ANSI conformance. It is implemented by calling getrusage(2) and throwing away informa- tion and resolution. o The clock reported by times(3). This is a virtual clock with a frequency that happens to be 128. Its actual frequency is given by the macro CLK_TCK (deprecated; do not use) and by sysconf(_SC_CLK_TCK) and by sysctl(3). Note that its frequency may be different from CLOCKS_PER_SEC. Do not use times(3) in new programs under FreeBSD. It is feeble compared with gettimeofday(2) together with getrusage(2). It is provided for POSIX conformance. It is implemented by calling gettimeofday(2) and getrusage(2) and throwing away information and resolution. o The profiling clock. This is a real clock with frequency 1024. It is used mainly by moncontrol(3), kgmon(8) and gprof(1). Applications should determine its actual frequency using sysctl(3) or by reading it from the header in the profiling data file. o The mc146818a clock. This is a real clock with a nominal frequency of 32768. It is divided down to give the statistic clock and the profiling clock. It is not available to applications. o The microseconds clock. This is a virtual clock with frequency 1000000. It is used for most timekeeping in BSD and is exported to applications in getrusage(2), gettimeofday(2), select(2), getitimer(2), etc. This is the clock that should normally be used by BSD applications. o The i8254 clock. This is a real clock/timer with a nominal frequency of 1193182. It has three independent time counters to be used. It is divided down to give the scheduling clock. It is not available to applications. o The TSC clock (64-bit register) on fifth-generation or later x86 systems. This is a real clock with a frequency that is equivalent to the number of cycles per second of the CPU(s). Its frequency can be found using the machdep.tsc_freq sysctl, if it is available. It is used to interpolate between values of the scheduling clock. It can be accessed using the PMIOTSTAMP request of perfmon(4). o The ACPI clock. This is a real clock/timer with a nominal frequency of 3579545. It is accessed via a 24 or 32 bit register. Unlike the TSC clock, it maintains a constant tick rate even when the CPU sleeps or its clock rate changes. It is not available to applications. Summary: if HZ is not 1000000 then the application is probably using the wrong clock. SEE ALSO
gprof(1), clock_gettime(2), getitimer(2), getrusage(2), gettimeofday(2), select(2), clock(3), moncontrol(3), times(3) AUTHORS
This manual page was written by Jorg Wunsch after a description posted by Bruce Evans. BSD
January 18, 2008 BSD
All times are GMT -4. The time now is 08:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy