Standard way to yield cpu

Doug Gwyn gwyn at smoke.brl.mil
Tue Nov 27 09:19:47 AEST 1990


In article <SCOTT.90Nov25223409 at next-8.gac.edu> scott at next-8.gac.edu (Scott Hess) writes:
>Is there any method under standard Unix to yield up the CPU so that other
>tasks can run for a time?  I speculate that a call to sleep() with 0
>timeout _might_ do it, but someone may just have optimized that part . . .
>I could do testing, but it would not be very conclusive, as I'd have no
>way of telling whether another task actually ran.

Basically, any system call provides a rescheduling opportunity.  If you
want to minimize the overhead, getpid() is the cheapest possible system
call.  However, other system calls such as select() will already be
providing reschedule opportunities in most cases.  If you really want
to delay the suspended process, sleep(nonzero) is the way to do it.



More information about the Comp.unix.questions mailing list