Sponsored Content
Full Discussion: the problem of gettimeofday
Top Forums Programming the problem of gettimeofday Post 302220150 by dophine on Thursday 31st of July 2008 02:43:08 AM
Old 07-31-2008
the problem of gettimeofday

Hi all,

I just wrote a small problem to check gettimeofday in a multi-cores environment.

Code:
int timediff(double fTimeQvs, double fTimeTcp)
{
        int iTimeDiff;
        iTimeDiff = (((((int)fTimeQvs)/10000) - (((int)fTimeTcp)/10000)) * 3600) * 1000000;
        iTimeDiff += ((((((int)fTimeQvs)/100)%100) - ((((int)fTimeTcp)/100)%100)) * 60) * 1000000;
        iTimeDiff += ((((int)fTimeQvs)%100) - (((int)fTimeTcp)%100)) * 1000000;
        iTimeDiff += (((long long)(fTimeQvs*1000000))%1000000) - (((long long)(fTimeTcp*1000000))%1000000);

    return iTimeDiff;
}

int main()
{
        struct timeval cur;
        gettimeofday(&cur, 0);

        for(;;)
        {
                struct timeval new_time;
                gettimeofday(&new_time, 0);

                double diff = difftime(new_time.tv_sec,cur.tv_sec);
                if(diff > 1.0)
                        printf("Big:%ld.%ld,%ld.%ld,%lf\n",new_time.tv_sec,new_time.tv_sec, cur.tv_sec,cur.tv_usec,diff);
                else if(diff < 0.0)
                        printf("Small::%ld.%ld,%ld.%ld,%lf\n",new_time.tv_sec,new_time.tv_usec, cur.tv_sec,cur.tv_usec,diff);
                cur.tv_sec = new_time.tv_sec;
        }
        return 0;
}

Here is the result:
Small::1217485404.98014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.99014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.100014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.101013,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.102014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.103014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.104014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.105014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.106014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.107013,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.108013,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.109013,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.110014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.111014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.112014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.113014,1217489802.813903,-4398.000000
Big:1217489802.1217489802,1217485404.813903,4398.000000
Small::1217485404.114014,1217489802.813903,-4398.000000

so is there any way to overcome it?
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

SSH Problem auth problem

Hi, Just recently we seem to be getting the following error message relating to SSH when we run the UNIX script in background mode: warning: You have no controlling tty. Cannot read confirmation.^M warning: Authentication failed.^M Disconnected; key exchange or algorithm negotiation... (1 Reply)
Discussion started by: budrito
1 Replies

2. Shell Programming and Scripting

problem with dd command or maybe AFS problem

Hi, folks. Sorry for bothering, but maybe someone could help me please. The problem is the following: there is some script that copies files from local file system to AFS. The copying is performed with dd command. The script copies data into some AFS volumes. The problem appeared with one... (0 Replies)
Discussion started by: Anta
0 Replies

3. Solaris

problem in finding a hardware problem

Hi I am right now facing a strange hardware problem. System get booted with the following error: Fatal Error Reset CPU 0000.0000.0000.0003 AFSR 0100.0000.0000.0000 SCE AFAR 0000.07c6.0000.1000 SC Alert: Host System has Reset It happen 4 or 5 times and get the same error every time.I... (8 Replies)
Discussion started by: girish.batra
8 Replies

4. Programming

Gettimeofday problem

i have written the code in which i want to calculate timedifference of request sent time and response receive time from device in second and microsecond. but when i executes the binary i get the response receive time earlier than request sent time which in turn returns the negative time difference.... (3 Replies)
Discussion started by: kailas.awchar
3 Replies

5. AIX

user login problem & Files listing problem.

1) when user login to the server the session got colosed. How will resolve? 2) While firing the command ls -l we are not able to see the any files in the director. but over all view the file system using the command df -g it is showing 91% used. what will be the problem? Thanks in advance. (1 Reply)
Discussion started by: pernasivam
1 Replies

6. Programming

smallest resolution using gettimeofday() in C

Hello ... Can somebody help telling me how smallest clock resolution on ones sytem can be in obtained in C using gettimeofday() . Thankz in advance... (4 Replies)
Discussion started by: harsha10
4 Replies

7. UNIX for Dummies Questions & Answers

DHCP problem and eth1 problem

At work I am trying to get this one Linux machine (let's call it ctesgm07) to behave like another Linux machine that we have (let's call it test007). test007 returns the following version info: cat /etc/debian_version: lenny/sid uname -a: Linux test007 2.6.27-7-generic #1 SMP Tue Nov 4... (0 Replies)
Discussion started by: sllinux
0 Replies

8. IP Networking

Problem with forwarding emails (SPF problem)

Hi, This is rather a question from a "user" than from a sys admin, but I think this forum is apropriate for the question. I have an adress with automatic email forwarding and for some senders (two hietherto), emails are bouncing. This has really created a lot of problems those two time so I... (0 Replies)
Discussion started by: carwe
0 Replies

9. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

10. IP Networking

Router problem or ISP problem ?

Hi everyone, I am experiencing discontinuity of Internet service, this started 1 month ago. Everything worked very well for 1 year of intensive use, but now, I have problems reaching my gateway. The gateway is not my router but a node belonging to my ISP and I share the same public IP with... (3 Replies)
Discussion started by: remic
3 Replies
RSS Other Screensaver(1)				      General Commands Manual					  RSS Other Screensaver(1)

NAME
sundancer2 - rotating stack of quads. SYNOPSIS
sundancer2 [--root/-r] [--maxfps/-x number] [--vsync/-y number] [--dpms/-M number] [--quad_count/-q number] [--speed/-s number] [--trans- parency/-t number] [--foreground/-f number] [--background/-b number] [--reverse/-e] [--no-reverse/-E] DESCRIPTION
Neat rotation effects from rotation and skewing stack of transparent squares. Ported to Linux by Tugrul Galatali. OPTIONS
--root Draw on the root window. --maxfps number Set maximum frame rate. --vsync number Limit redraws to specified number of vertical refreshes. 0 - 100. Default: 1 --dpms number Stop rendering new frames if the display is not on. 0 - 1. Default: 1 --quad_count number Set number of stacked quads. 1 - 300. Default: 150 --speed number Rotational speed. 1 - 40. Default: 20 --transparency number Percentage of transparency. 1 - 100. Default: 75 --foreground number Color for the top of the heap using hex color codes. 000000 - ffffff. Default: ffff00 --background number Color for the bottom of the heap using hex color codes. 000000 - ffffff. Default: ff0000 --reverse Reverse rotation occasionally. Default: False ENVIRONMENT
DISPLAY to get the default host and display number. SEE ALSO
X(1), COPYRIGHT
Copyright (C) 2002 by Dirk Songuer and Tugrul Galatali. Sundancer2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as pub- lished by the Free Software Foundation. Sundancer2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL- ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. AUTHOR
Dirk Songuer <delax@sundancerinc.de> and Tugrul Galatali <tugrul@galatali.com> X Version 11 RSS Other Screensaver(1)
All times are GMT -4. The time now is 05:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy