Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Making a program pause

Reply
Thread Tools

Making a program pause

 
 
dave.zoltan@gmail.com
Guest
Posts: n/a
 
      12-26-2007
Hey everybody,

I attempted to use the sleep() function, but I am using Pelles C
compiler and unistd.h has sleep() commented out. I guess I will have
to figure out something else to try to get my program to pause.

Thanks for your help everyone,

Dave
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      12-26-2007
Joachim Schmitz wrote:
> "Keith Thompson" <(E-Mail Removed)> schrieb im Newsbeitrag
>> "Joachim Schmitz" <(E-Mail Removed)> writes:
>>> "CBFalconer" <(E-Mail Removed)> schrieb im Newsbeitrag
>>>> Ivan Novick wrote:
>>>>> Richard Heathfield <(E-Mail Removed)> wrote:
>>>>>
>>>>>> Ideally, I would like the program to wait 5 minutes before
>>>>>> executing the rest of the code. Is there some way that I can
>>>>>> use time.h and just run a for loop that waits until 5 minutes
>>>>>> has passed to continue down the program?
>>>>>
>>>>> There is a sleep function in the GNU C library.
>>>>>
>>>>> http://www.gnu.org/software/libc/man....html#Sleeping
>>>>
>>>> GNU C is not ISO standard C. Extensions are off-topic here.
>>>> There would have been no objection if you had made this clear.
>>>
>>> He did make it very clear that this is in the GNU C library.
>>> How could it possibly get any clearer?

>>
>> The GNU C library also has a strlen function.

>
> So what? Does that make strlen off topic here?


No. But 'sleep' is off-topic. Have you caught on to the
difference yet?

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-26-2007
"Joachim Schmitz" <(E-Mail Removed)> writes:
> "Keith Thompson" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed)...
>> "Joachim Schmitz" <(E-Mail Removed)> writes:
>>> "CBFalconer" <(E-Mail Removed)> schrieb im Newsbeitrag
>>> news:(E-Mail Removed)...
>>>> Ivan Novick wrote:

[...]
>>>>> There is a sleep function in the GNU C library.
>>>>>
>>>>> http://www.gnu.org/software/libc/man....html#Sleeping
>>>>
>>>> GNU C is not ISO standard C. Extensions are off-topic here. There
>>>> would have been no objection if you had made this clear.
>>> He did make it very clear that this is in the GNU C library. How could it
>>> possibly get any clearer?

>>
>> The GNU C library also has a strlen function.
>> http://www.gnu.org/software/libc/man...ng-Length.html

> So what? Does that make strlen off topic here?


Of course not.

Sorry, apparently I wasn't as clear as I thought I was. My point is
that saying that the GNU C library has a sleep function does not by
itself make it perfectly clear that the sleep function is
non-standard.

The GNU C library provides implementations of both sleep() and
strlen(). strlen() is topical here; sleep() is not (though a brief
mention of sleep() with a redirection to a more appropriate forum is
IMHO perfectly ok).

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      12-26-2007
CBFalconer <(E-Mail Removed)> wrote:
# Ivan Novick wrote:
# > Richard Heathfield <(E-Mail Removed)> wrote:
# >
# >>> Ideally, I would like the program to wait 5 minutes before
# >>> executing the rest of the code. Is there some way that I can use
# >>> time.h and just run a for loop that waits until 5 minutes has
# >>> passed to continue down the program?
# >
# > There is a sleep function in the GNU C library.
# >
# > http://www.gnu.org/software/libc/man....html#Sleeping
#
# GNU C is not ISO standard C. Extensions are off-topic here. There
# would have been no objection if you had made this clear.

system("sleep 300");

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-27-2007
SM Ryan <(E-Mail Removed)> writes:
> CBFalconer <(E-Mail Removed)> wrote:
> > Ivan Novick wrote:
> > > Richard Heathfield <(E-Mail Removed)> wrote:
> > >
> > >>> Ideally, I would like the program to wait 5 minutes before
> > >>> executing the rest of the code. Is there some way that I can use
> > >>> time.h and just run a for loop that waits until 5 minutes has
> > >>> passed to continue down the program?
> > >
> > > There is a sleep function in the GNU C library.
> > >
> > > http://www.gnu.org/software/libc/man....html#Sleeping

> >
> > GNU C is not ISO standard C. Extensions are off-topic here. There
> > would have been no objection if you had made this clear.

>
> system("sleep 300");


This is, of course, portable only to systems that provide a command
called "sleep" that does what you expect it to do.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      12-27-2007
On Dec 24, 10:18*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Hi everybody,
>
> I am awfully new to programming in C and all I have had to work with
> so far have been tutorials that I've found online. In my searching,
> however, I have not found a solution to a problem I have been facing.
> Ideally, I would like the program to wait 5 minutes before executing
> the rest of the code. Is there some way that I can use time.h and just
> run a for loop that waits until 5 minutes has passed to continue down
> the program?
>
> Any help that you experts could give would be greatly appreciated.
> Also, I apologize in advance if there is an obvious solution I have
> overlooked.


The obvious solution that you overlooked was to read the C-FAQ:

19.37: How can I implement a delay, or time a user's response,
with sub-second resolution?

A: Unfortunately, there is no portable way. Routines you might
look for on your system include clock(), delay(), ftime(),
gettimeofday(), msleep(), nap(), napms(), nanosleep(),
setitimer(), sleep(), Sleep(), times(), and usleep().
(A function called wait(), however, is at least under Unix
*not*
what you want.) The select() and poll() calls (if available)
can be pressed into service to implement simple delays.
On MS-DOS machines, it is possible to reprogram the system
timer
and timer interrupts.

Of these, only clock() is part of the ANSI Standard. The
difference between two calls to clock() gives elapsed
execution
time, and may even have subsecond resolution, if
CLOCKS_PER_SEC
is greater than 1. However, clock() gives elapsed processor
time used by the current program, which on a multitasking
system
may differ considerably from real time.

If you're trying to implement a delay and all you have
available
is a time-reporting function, you can implement a CPU-
intensive
busy-wait, but this is only an option on a single-user,
single-
tasking machine, as it is terribly antisocial to any other
processes. Under a multitasking operating system, be sure to
use a call which puts your process to sleep for the duration,
such as sleep() or select(), or pause() in conjunction with
alarm() or setitimer().

For really brief delays, it's tempting to use a do-nothing
loop
like

long int i;
for(i = 0; i < 1000000; i++)
;

but resist this temptation if at all possible! For one thing,
your carefully-calculated delay loops will stop working
properly
next month when a faster processor comes out. Perhaps worse,
a
clever compiler may notice that the loop does nothing and
optimize it away completely.

References: H&S Sec. 18.1 pp. 398-9; PCS Sec. 12 pp.
197-8,215-6; POSIX Sec. 4.5.2.
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      12-27-2007
"CBFalconer" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Joachim Schmitz wrote:
>> "Keith Thompson" <(E-Mail Removed)> schrieb im Newsbeitrag
>>> "Joachim Schmitz" <(E-Mail Removed)> writes:
>>>> "CBFalconer" <(E-Mail Removed)> schrieb im Newsbeitrag
>>>>> Ivan Novick wrote:
>>>>>> Richard Heathfield <(E-Mail Removed)> wrote:
>>>>>>
>>>>>>> Ideally, I would like the program to wait 5 minutes before
>>>>>>> executing the rest of the code. Is there some way that I can
>>>>>>> use time.h and just run a for loop that waits until 5 minutes
>>>>>>> has passed to continue down the program?
>>>>>>
>>>>>> There is a sleep function in the GNU C library.
>>>>>>
>>>>>> http://www.gnu.org/software/libc/man....html#Sleeping
>>>>>
>>>>> GNU C is not ISO standard C. Extensions are off-topic here.
>>>>> There would have been no objection if you had made this clear.
>>>>
>>>> He did make it very clear that this is in the GNU C library.
>>>> How could it possibly get any clearer?
>>>
>>> The GNU C library also has a strlen function.

>>
>> So what? Does that make strlen off topic here?

>
> No. But 'sleep' is off-topic. Have you caught on to the
> difference yet?

Of course I do and did. I was only pointing out that Ivan clearly stated
where his sleep is from.
Nothing else.

Bye, Jojo


 
Reply With Quote
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      12-30-2007
[snips]

On Wed, 26 Dec 2007 23:09:13 +0000, SM Ryan wrote:

> system("sleep 300");


Wonder what effect that would have on systems:

a) That have no sleep command
b) That have a sleep, but the parameter is in minutes
c) That have a sleep, but the parameter is in milliseconds
d) That have a sleep, but the parameter is a resource or device ID and
sleep waits for the resource to become available

FWIW, Windows XP - arguably the most populous desktop OS - seems to have
no bundled sleep command.
 
Reply With Quote
 
Chris Saunders
Guest
Posts: n/a
 
      12-31-2007
Not sure what you mean by bundled but the Windows API has a Sleep() function
that has been available at least since Windows 95.

Regards
Chris Saunders

"Kelsey Bjarnason" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> [snips]
>
> On Wed, 26 Dec 2007 23:09:13 +0000, SM Ryan wrote:
>
>> system("sleep 300");

>
> Wonder what effect that would have on systems:
>
> a) That have no sleep command
> b) That have a sleep, but the parameter is in minutes
> c) That have a sleep, but the parameter is in milliseconds
> d) That have a sleep, but the parameter is a resource or device ID and
> sleep waits for the resource to become available
>
> FWIW, Windows XP - arguably the most populous desktop OS - seems to have
> no bundled sleep command.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-31-2007
"Chris Saunders" <(E-Mail Removed)> writes:
> "Kelsey Bjarnason" <(E-Mail Removed)> wrote in message

[...]
>> FWIW, Windows XP - arguably the most populous desktop OS - seems to have
>> no bundled sleep command.

>
> Not sure what you mean by bundled but the Windows API has a Sleep()
> function that has been available at least since Windows 95.


Please don't top-post (corrected here).

A Sleep() function is not the same as a "sleep" command.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pause until external program exits with success? Tuxedo Perl Misc 7 08-16-2012 03:07 PM
Pause Perl Program? still me Perl Misc 5 07-08-2007 07:22 PM
Pause Frames on Catalyst switches? Cisco Fan Cisco 6 12-09-2004 05:51 AM
Pause a program while running Amit Nath C Programming 10 07-20-2004 11:49 PM
How to pause a running program Rick Java 4 10-07-2003 11:19 PM



Advertisments