How to see if less than x seconds have passed?

How to see if less than x seconds have passed?

Post by Joel M. Hoffm » Thu, 10 Jun 1993 06:53:57



Part of a program I'm writing has to see if two events happen less
than 30 seconds apart.  What's the best way to do this?

Is there something already in the time library that will let me, e.g.,
say:

        first_time = currenttime();
        ...
        second_time = currenttime();
        if (time_diff(second_time,first_time) < 30) {
          ... }

If so, what are the procedure names for currenttime(), etc.?  BTW, I'm
running on Linux.  

Thanks.

-Joel

--
-----------------------------------------------------------------------------
|_|~~ Germany, 1943.   ``A little garden, fragrant and full of roses.
__|~| 16 Million DEAD.   The path is narrow, and a little boy walks along it.
                         A little boy, a sweet boy, like that growing blossom,
 cnc  Bosnia, 1993.      When the blossom comes to bloom,
 cnc  HOW MANY MORE?     The little boy will be no more.''

                                        - Franta Bass,
                                          killed at age 14 by the Nazis
-----------------------------------------------------------------------------

 
 
 

How to see if less than x seconds have passed?

Post by Robert Martin-Lege » Thu, 10 Jun 1993 23:30:49



>Part of a program I'm writing has to see if two events happen less
>than 30 seconds apart.  What's the best way to do this?

>Is there something already in the time library that will let me, e.g.,
>say:

>    first_time = currenttime();
>    ...
>    second_time = currenttime();
>    if (time_diff(second_time,first_time) < 30) {
>      ... }

>If so, what are the procedure names for currenttime(), etc.?  BTW, I'm
>running on Linux.  

>Thanks.

>-Joel


I think you're looking for the system call time(2) (man 2 time). This tells
you how many seconds that have passed since 1/1-1970. You could do it like
this (much like your own method, just shorter):

        first_time = time((time_t*)NULL);
        ...
        if (time((time_t*)NULL) - first_time < 30) {
          ...
        }

-----------------------------------------------------------------------------

       Robert Martin-Legene        |    University of Copenhagen,  Denmark
-----------------------------------------------------------------------------

 
 
 

1. Passing a String with an IFS without truncating

Could somobody help me ?!!!!
I have big troubles with IFS, and I can't get it.
IFS are the Internal Fields Separators, that are <space>, <tab.>, and <CR>
for the POSIX-tively correct Unix shells.
But my probems do not come from command-lines shell, but from the buffers
that I'm trying to manipulate through the different stream classes under
DEC/C++.
For example :
-I've created my QueueInterfaceClass which allows me to make different
processes communicate. But when I send a message ( which is in char *
buffer ) which contains an IFS, all the characters behind the IFS one are
blasted.

        i.e.:
        - If I send : "The cat is in the maze";
        - I will receive :"The"

        - If I send "bloubloum  cat"
        - I will receive :"bloumbloum"

-I've created an Serial_Line_InterfaceClass to communicate with a P.C. with
a RS232 chip. From the P.C. to my AlphaStation, the messages are not
truncated, even if they contain an IFS character. But if there is one in a
message from the station to the P.C., it is skipped with all the afterward
characters.

        i.e:
        - Same examples that with the QueueInterfaceClass.

        And this, even if I send characters one by one on the serial_line
!!!
        And yet, I use only asynchronous buffers in my stream classes !!!

Well, this is in fact a problem on which I've spent hours and hours, trying
many iostreams class configurations, without resolving just once the
problem.

And as the just-passed week-end has tired me a lot ( seems that me and my
friends are the alive prooves that Paris is not a undeads-museum !!!), it's
very hard to purchase the problem with a dbx debugger.
So, if you have any suggestion, it will be welcomed.

thanks a lot for finding time to answer me,
sorry for my english ( but still try'ing to improve it.)

2. Domain Hijacked

3. ld: Principles of one-pass vs. two-pass

4. Problems with Aic 7xxx

5. Having two separate networks connect using two Linux routers and ISDN

6. 96 Mb DRAM problem

7. How to connect two Linux boxes via Com ports having two wires only

8. Looking for nroff for Linux

9. One Process on the machine having two IP address and two ethernet interface.

10. Networking between two PC with both having two Ethernet port

11. Q: Two-sided, two-pass printing to laserjet

12. Question regarding IFS and set -- : Why does it take two iterations?

13. Linux sees less RAM then really exists. Why???