LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   linux sleep and alarm call (https://www.linuxquestions.org/questions/linux-kernel-70/linux-sleep-and-alarm-call-4175540216/)

viveksingh 04-20-2015 09:13 AM

linux sleep and alarm call
 
When we use sleep in our program then what happen our current process is put outside the ram or is it in ram.before sleep I put alarm so what happen alarm also get continue or put on hold when sleep occur

pan64 04-20-2015 10:02 AM

that is handled automatically by the kernel: if required the sleeping process will be swapped out (if not it will be kept in memory). Anyway if an alarm was arrived it should wake this process up (and obviously bring back from swap if needed)

veerain 04-20-2015 01:21 PM

All the programs are run from RAM. If only RAMS memory gets less then only it's swapped to swap partition provided one has setup swap.

sundialsvcs 04-21-2015 06:43 PM

The kernel is ultimately responsible for all of these things. (Which is one of the many reasons why the kernel is "a slightly-complicated ;) computer program" ...)

When a process "voluntarily goes to sleep," from the kernel's point-of-view that process has (a) given up the remainder of its current time-slice, and (b) voluntarily designated itself as "asleep, therefore non-dispatchable." Therefore, the CPU/core that had been running this process will move along to other-things, and all other CPUs will decline to run it.

(Maybe the swapper "picks this particular process to be its next victim," or maybe it doesn't. This doesn't affect the process's "basic runnability," although a swap-out might delay things a bit ...)

Anyhow: eventually, a signal arrives. (Could be an alarm, could be something else.) The process, as a result, switches from "not-runnable" to "runnable." (Or, if it's swapped-out, "soon to be runnable, and by-the-way needs to be swapped back in.")

Yeah, the kernel gets real complicated, real fast. ;)

But ... lo and behold ... if the process had been swapped-out, very soon it gets swapped back in. Then, it re-enters the "run-list." Shortly thereafter, some CPU picks it up.

... and the user (and, the application programmer) "is none the wiser." :)


All times are GMT -5. The time now is 07:54 AM.