LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2004, 06:57 AM   #1
Whitman
LQ Newbie
 
Registered: Jun 2003
Location: England
Distribution: Debian Sarge
Posts: 17

Rep: Reputation: 0
w32 GetTickCount equivalent on linux


Hi, I'm having a slight problem with uptime...

I'm running two servers, one running Slackware Linux 9 and the other running Windows 2000 server. During some maintenance both servers were shutdown. When power was back I started up the two machines at roughly the same time.
I have a couple of php scripts on each machine which report the uptime. The Windows uptime is a result of calling GetTickCount() from the Windows API. The Linux uptime is a result of parsing /proc/uptime.

Initially, after both machines had booted, the difference in uptimes between the two machines was around 6 seconds. Somehow this difference has slowly been drifting. Now after 3 days(ish) the difference is now about 23 seconds. Obviously there is something wrong here and I'm going to attempt to find out what it is.

Anyway, back to the main question. Is there a function call I can make in c under Linux which is the equivalent of the Windows GetTickCount() function? I've read that /proc/uptime sometimes reports the wrong uptime and so I'd like to check if it is the cause of the problem.

Thanks in advance.
 
Old 01-02-2004, 09:49 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
clock() returns a clock_t value (usually unsigned long) that is the number of
CLOCKS_PER_SEC or CLK_TCK per second.

Note -- this value rolls over on 32 bit systems after a while, so you need to do something to keep track of the number of times the value rolls over.

Plus, if uptime is wrong, you may have internal clock problems. A lot of systems have to have a daemon running to correct time constantly or have used date to correct time periodically. There are other methods to alter the clock as well.
 
Old 01-02-2004, 10:04 AM   #3
Whitman
LQ Newbie
 
Registered: Jun 2003
Location: England
Distribution: Debian Sarge
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks, I'll take a look at clock().

On the Linux machine I've got ntpd running which should be keeping the clock correct and I have a program synchronising the Windows machine's clock every 24 hours. Thinking about it, the Windows machine might be the cause of the problem if the clock is deviating too much in the 24 hours between synchronisation.
 
Old 01-02-2004, 01:11 PM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
w32 codecs gone from apt irish rebel Ubuntu 1 09-22-2005 05:58 AM
W32.Sober Running Free on Kubuntu?? webterractive Ubuntu 2 05-05-2005 03:49 PM
linux w32 codecs? claybub Linux - Software 1 06-19-2004 12:26 AM
W32/Sober-B worm snort rule????? netmon Linux - Security 1 12-19-2003 06:17 AM
Anybody else hit by the W32/Lovsan.worm. itsjustme General 20 08-15-2003 04:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration