LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 04-20-2015, 09:13 AM   #1
viveksingh
LQ Newbie
 
Registered: Apr 2015
Posts: 1

Rep: Reputation: Disabled
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
 
Old 04-20-2015, 10:02 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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)
 
Old 04-20-2015, 01:21 PM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
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.
 
Old 04-21-2015, 06:43 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
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."
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sleep( ) call causes whole GNU Linux system to hang indefinitely wtruong Programming 14 06-27-2011 04:06 AM
Disable suspend/sleep/hibernate/whatever-you-call-it arizonagroovejet Linux - General 4 02-06-2009 04:33 AM
sleep() call prital Programming 2 06-27-2005 07:04 AM
alarm() call socket9001 Programming 3 04-26-2004 03:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 07:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration