473,659 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14759

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*********@yah oo.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.li nux.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.l earn.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******@splin termac.com> wrote in message news:<9y******* ***********@new ssvr29.news.pro digy.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******@splin termac.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.progr ammer.

--
Keith Thompson (The_Other_Keit h) 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*********@yah oo.com (John) wrote in message news:<c3******* *************** ****@posting.go ogle.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
18881
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 no actual animations can be seen. Therefore I need a "delay" function. Is there a "delay" function in C++ that accepts a time argument in seconds or its varieties (i.e. so that I don't have to resort to the "big for loop" scheme). Regards,
7
947
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 news:<40455261$1@usenet.per.paradox.net.au>... > "John Carson" <donaldquixote@datafast.net.au> wrote in message > news:40455214$1@usenet.per.paradox.net.au
1
1791
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 using 'WebRequest and a StreamReader to download them. I followed up the call to WebRequest.Create with a call to Application.DoEvents, and called Application.DoEvents() again after the call to ReadToEnd on the StreamReader. What I was looking...
9
3328
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 certain logic performed, and the dataview will be re-binded to the datagrid. There turns out to be about 2-5 seconds delay between the time the user clicks the radiobutton and when the page is completely re-loaded. During this time the user may try...
5
1160
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 string. Sometime it
1
3015
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 its work, which should run every 20ms. To do this, it does its business, then calculates how long to sleep for until the next 20ms boundry (sleeping using usleep()). Now, generally this works very nicely, except that 'sometimes' my usleep waits...
2
1679
by: Lou | last post by:
How can I add a delay in my code. I used to use "Sleep" in VB6 -Lou
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7359
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.