schedule_timeout(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’€ schedule_timeout(9) β€” the "just nap for a bit, bestie" kernel function ✨

okay so this is a page from the Kernel API Manual, and it's about schedule_timeout, which is basically the kernel's way of saying "girl, go to sleep for a minute." πŸŽ€


🌸 NAME 🌸

schedule_timeout β€” sleep until timeout πŸ’€


✨ SYNOPSIS ✨

signed long schedule_timeout (signed long timeout );

🧚 ARGUMENTS 🧚

  • timeout β€” the timeout value, measured in jiffies. (ya, jiffies. iconic unit, no notes 🫢)

πŸ‘‘ DESCRIPTION πŸ‘‘

So the whole vibe here: this makes the current task sleep until timeout jiffies have elapsed. That's it. That's the function. But β€” and this is the part that's giving ✨main character energy✨ β€” what actually happens depends on the current task state (peep the set_current_state description too, bestie, they're linked):

  • TASK_RUNNING β€” the scheduler gets called, but the task does not sleep at all. Zero nap. Not even a lil closing of the eyes 😭 And why? Because sched_submit_work does literally nothing for tasks in TASK_RUNNING state. nothing. nada. it's giving unbothered.
  • TASK_UNINTERRUPTIBLE β€” at least timeout jiffies are guaranteed to pass before the routine returns, unless the current task gets explicitly woken up (like, by wake_up_process). So it's a proper deep sleep, no interruptions, no "mom's calling" energy. πŸ’…
  • TASK_INTERRUPTIBLE β€” this one's the light sleeper πŸ¦‹ the routine may return early if a signal is delivered to the current task, or if the current task is explicitly woken up. so like, you can be woken. it's fine. it's flexible.

And the glow-up guaranteed at the end: the current task state is guaranteed to be TASK_RUNNING when this routine returns. always. periodt. ⭐

Also, if you specify a timeout value of MAX_SCHEDULE_TIMEOUT, it'll schedule the CPU away without a bound on the timeout β€” like, no clock, no limit, just vibes πŸ”₯ In that case the return value will be MAX_SCHEDULE_TIMEOUT.


πŸ’– RETURN πŸ’–

  • 0 when the timer has expired β€” slay, nap complete βœ…
  • otherwise the remaining time in jiffies gets returned πŸ•

And in all cases, the return value is guaranteed to be non-negative. no negativity allowed here, we don't do that πŸ™ˆ


🌈 SEE ALSO 🌈

Kernel file ./kernel/time/sleep_timeout.c β€” go read it, it's cute

the whole sleep-timeout friend group fr fr 🫢


✿ and that's the whole page, bestie ✿ this one's chillin' under ./kernel/time, October 2026 edition β€” go take a nap, you've earned it πŸ’œπŸ’€

πŸ“¦ where this page comes from