How to see if less than x seconds have passed?

How to see if less than x seconds have passed?

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?

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

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";

- If I send "bloubloum  cat"

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