473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to "sleep" or "delay"?

Hi all:

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

Thanks
Nov 14 '05 #1
8 14703

As far as I remember: There is one, but I don't remember its name.
It might be wait(\\).
Any reference on C should list it in one of the libraries possibly.

amit.

John wrote:
Hi all:

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

Thanks


Nov 14 '05 #2
On 2 Mar 2004 22:32:34 -0800, jo*********@yahoo.com (John) wrote in
comp.lang.c:
Hi all:

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

Thanks


There is no such function in standard C.

For Linux questions, news:comp.os.linux.development.apps.

Or news:comp.unix.programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
John wrote:
Hi all:

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

Thanks


You can use the localtime() function combined with the time() function
to get the current time. You can poll on those until the delay is up.

Be aware that both those functions are allowed to fail.

--
Pull out a splinter to reply.
Nov 14 '05 #4
Amit Bhatia <bh*****@nospam.co> writes:
John wrote:
Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

As far as I remember: There is one, but I don't remember its name.
It might be wait(\\).


Misleading and incorrect answers like this are an excellent
reason not to post off-topic questions.
Nov 14 '05 #5
Thanks.

Peter Ammon <ge******@splintermac.com> wrote in message news:<9y******************@newssvr29.news.prodigy. com>...
John wrote:
Hi all:

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?

Thanks


You can use the localtime() function combined with the time() function
to get the current time. You can poll on those until the delay is up.

Be aware that both those functions are allowed to fail.

Nov 14 '05 #6
My sincere apologies for the same.

--A.
As far as I remember: There is one, but I don't remember its name.
It might be wait(\\).


Misleading and incorrect answers like this are an excellent
reason not to post off-topic questions.

Nov 14 '05 #7
Peter Ammon <ge******@splintermac.com> writes:
John wrote:
Hi all:
Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?
Thanks


You can use the localtime() function combined with the time() function
to get the current time. You can poll on those until the delay is up.

Be aware that both those functions are allowed to fail.


Something like that is probably the only *portable* way to delay for a
specified time interval. You don't really need localtime(); you can
do it with time() and difftime(). For example, the following program
should sleep for about 3 seconds:

#include <stdlib.h>
#include <time.h>

int main(void)
{
time_t start_time = time(NULL);
while (difftime(time(NULL), start_time) < 3.0) {
;
}
return 0;
}

I've omitted any error checking. Even if it works, the amount of time
it sleeps is likely to be imprecise; the standard doesn't specify the
precision of the time() function, and one second is typical.

On many systems, this technique has some severe drawbacks. On a Linux
or other Unix-like system, or on any multi-process system, the
continuous polling is likely to cause the program to gobble up nearly
100% of the CPU time. What you almost certainly really want your
program to do is go to sleep for a specified interval, allowing other
processes to run until your program wakes up.

This concern is not addressed by the C standard because the standard
is not concerned with multi-processing systems, but it's something you
should think about.

There are system-specific functions that will do exactly what you
want. You can probably get more information about such functions from
your system's documentation or, if that fails, by asking in a
system-specific newsgroup such as comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #8
jo*********@yahoo.com (John) wrote in message news:<c3**************************@posting.google. com>...

Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?


Look up sleep(), usleep() and nanosleep().

On Windows see Sleep().
Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shuo Xiang | last post by:
Greetings: I'm working on some graphical game and need to animate certain things (by continuously changing the x/y coordinate and update the display), however, the system is blinkingly fast so...
7
by: John | last post by:
Thanks. I am writing a C++ code on Linux and Sun OS platform. How to make a procedure sleep or delay? Thanks again. "John Carson" <donaldquixote@datafast.net.au> wrote in message...
1
by: Bill Woodruff | last post by:
As an exercise I wrote a small C# program to download several hundred text files of guitar tab music by parsing the home page of the site and retrieving all the links to the music text files and...
9
by: John Walker | last post by:
Hi, I have a datagrid with a radiobutton template column, with AutoPostBack set to TRUE. When the user clicks on a radiobutton the application will PostBack, and in the PostBack there will be...
5
by: Sweet.mhtrq | last post by:
I want to use "send" to send a string like Code: send "p" & OutputString if OutputString is "1234" , "p1234" will be sent. but it is sent too fast, my robot' cpu cant receive the whole...
1
by: brianwyld | last post by:
Maybe someone has some experience with "realtime" operation of JNI threads? I have a java app, which calls some C++ code for real time actions. This C++ code creates an independant pthread to do...
2
by: Lou | last post by:
How can I add a delay in my code. I used to use "Sleep" in VB6 -Lou
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.