clock() call returning zero always


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers clock() call returning zero always
# 1  
Old 05-21-2007
clock() call returning zero always

Hi,

Is there a chance that the clock() call returns 0 eternally???
Using BSD. My RTOS application freezes inconsistently only on particular hosts. When debugging it, I came to see that the RTOS timer does not tick at times. The underlying system call is clock() & it always returns zero when the problem under question occurs. Consequently the RTOS timer does not tick or go further in time.

Is it possible that some patches are missing on the hosts where my RTOS applications freeze?

If so, how do I find out which patches are missing based on the given info?

I guess clock() call does wrap after certain time (36 minutes approx). But I do not think it will return 0 for a long time...
# 2  
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().
# 3  
Old 05-21-2007
If you are strictly interested in cpu time in user mode and/or kernel mode, consider times().
# 4  
Old 05-22-2007
I actually use the RTOS timer already written by a third party. clock() is used by them & it has been in use for five years now, no problems for long. Only recently the RTOS applications started freezing inconsistently when run on certain Faster Hosts with SunFire V215, 2 CPU.

The chances that I can modify the timer functionality immediately is low.
I want to check if it's clock that is faulty or something else?
And if it clock() that is faulty, do you have any hint of suitable patch that can correct it?
# 5  
Old 05-22-2007
clock() is probably working correctly. Your third party assumed that some code would consume enough cpu time to register as non-zero when measured by clock(). You now have a CPU where this is not true. Induce the third party to fix the app or get some slower CPU's. Be warned though, the day will come when there are no CPU's available that are slow enough to run your app.

Wow, though! You are running BSD on a SunFire V215! That's pretty awesome. What version of BSD?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question