Programmer question: how to sleep a task for a while?

Programmer question: how to sleep a task for a while?

Post by Mat Nieuwenhove » Wed, 14 Jul 1999 04:00:00



Hi all,

I need to suspend execution from within a task for a short while (1
second or so, millisecond resolution would be best). On PC OSs, you can
use sleep(time to sleep) , but on Solaris sleep is an executable. I know
I can get this by using select() on a TCP/IP port, but that seems silly
for such a simple function, as seems starting the sleep executable just
for this. Does there exist such a function in Solaris 2.5 or do I have
to roll my own? I've also looked at create_timer and pals, but that
doesn't seem to fit the bill, as it employs signals. Ideas anyone?

Thanks, Mat Nieuwenhoven

 
 
 

Programmer question: how to sleep a task for a while?

Post by Michael Fu » Wed, 14 Jul 1999 04:00:00



> I need to suspend execution from within a task for a short while (1
> second or so, millisecond resolution would be best). On PC OSs, you can
> use sleep(time to sleep) , but on Solaris sleep is an executable. I know
> I can get this by using select() on a TCP/IP port, but that seems silly
> for such a simple function, as seems starting the sleep executable just
> for this. Does there exist such a function in Solaris 2.5 or do I have
> to roll my own? I've also looked at create_timer and pals, but that
> doesn't seem to fit the bill, as it employs signals. Ideas anyone?

man -s1 sleep
man -s3c sleep
man usleep

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

 
 
 

Programmer question: how to sleep a task for a while?

Post by Mat Nieuwenhove » Wed, 14 Jul 1999 04:00:00


Thanks Michael, that answers the question.

I have meanwhile discovered the catman command. After running it and
doing man -k sleep, it shows there are other sections which include
sleep, like you've shown. All works now.

Thanks, Mat Nieuwenhoven


> man -s1 sleep
> man -s3c sleep
> man usleep

> --

 
 
 

Programmer question: how to sleep a task for a while?

Post by Scott Giffor » Wed, 14 Jul 1999 04:00:00


What language are you programming in?

If it's C, you can just use sleep(3C) or usleep(3C), or select(3C)
with no file descriptors at all.  sleep() and usleep() use an ALRM
signal and an interval timer, respectively, while select() uses
neither.

-----ScottG.


> Hi all,

> I need to suspend execution from within a task for a short while (1
> second or so, millisecond resolution would be best). On PC OSs, you can
> use sleep(time to sleep) , but on Solaris sleep is an executable. I know

 
 
 

Programmer question: how to sleep a task for a while?

Post by Elias Martenso » Wed, 14 Jul 1999 04:00:00



> I need to suspend execution from within a task for a short while (1
> second or so, millisecond resolution would be best). On PC OSs, you can
> use sleep(time to sleep) , but on Solaris sleep is an executable. I know
> I can get this by using select() on a TCP/IP port, but that seems silly
> for such a simple function, as seems starting the sleep executable just
> for this. Does there exist such a function in Solaris 2.5 or do I have
> to roll my own? I've also looked at create_timer and pals, but that
> doesn't seem to fit the bill, as it employs signals. Ideas anyone?

For second granularity you can use the library call sleep() (it's a
unix command as well as a C library function). For millisecond
granularity that works on most unices you can use:

        select( 0, NULL, NULL, NULL, milliseconds_to_sleep );

That said, I think the function you are looking for is nanosleep(). It
has the best prescicion and have no reentrancy problems.

Hope this helps

--
Elias Martenson
elias.martenson (atsign) sweden.sun.com

 
 
 

1. Is it bad to have lots of sleeping tasks?

If you can implement an O(1) scheduler that is faster than Linus scheduler
for the normal case and for scalable cases I expect Larry would probably
jump up and down happily instead.

The current scheduler does make some very bad decisions
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. dd did a lame thing

3. Problems with redhat 4.2 install : Idle tasks may not sleep!

4. Help Using HP Deskjet 550C color printer with RS/6000 AIX 3.2.1

5. Message "idle task may not sleep"

6. Linux Fax Programs

7. Idle task may not sleep

8. Problem with Screen Refreshes...

9. task[0]trying to sleep...

10. Second Try: "Idle Task May Not Sleep"

11. task[0]trying to sleep...

12. idle task may not sleep

13. Help Plz: "Idle Task May Not Sleep"