473,396 Members | 2,108 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,396 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 14716

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.