Knowledge

Sleep (system call)

Source 📝

252:. The Windows Sleep function is non-interruptible due to absence of signals (other than the thread or its process being terminated), although the related SleepEx function can be used to put the thread into an alertable state, allowing APC calls being made while the thread is sleeping. Also, a thread can technically be "interrupted" in case e.g. the process terminates due to an exception in a different thread. 293:
function call can be repeatedly called for short periods of time to slow the execution of a running program or code. Throttling code in this manner provides a coarse mechanism for mitigating the effects of overheating hardware or easing timing issues for legacy programs. The downside to cycling sleep
275:
for events by going to sleep and resuming execution after a specific interval of time. Once execution is resumed, the program polls for events or status changes, and then services any that occurred while it was asleep. After servicing the events, the program then goes to sleep again for the next time
232:
state for the specified duration. While there is generally a guarantee for the minimum time period, there is no strict guarantee that the thread will run immediately or soon, or even at all, once the specified time has passed. It is up to the scheduler's discretion, and dependent on thread priorities
302:
An uninterruptible sleep state is a sleep state that will not handle a signal right away. It will wake only as a result of a waited-upon resource becoming available or after a time-out occurs during that wait (if specified when put to sleep). It is mostly used by device drivers waiting for disk or
294:
and running states rather than leveraging cycle emulation (via an emulator) to control the execution speed of software is that interactive software will acquire a notable stutter if too little time is spent awake, too much time is spent sleeping, or a combination of both.
70:
takes a time value as a parameter, specifying the minimum amount of time that the process is to sleep before resuming execution. The parameter typically specifies seconds, although some operating systems provide finer resolution, such as milliseconds or microseconds.
268:, going to sleep at the start of each cycle and waiting for some event to awaken them. Once an event is received, the program services the event, then returns to the beginning of the next wait cycle. 303:
network IO (input/output). When the process is sleeping uninterruptibly, signals accumulated during the sleep will be noticed when the process returns from the system call or trap.
134:
function is called providing a single parameter of type unsigned integer of the number of seconds to sleep. A higher-precision version is the
98:
function has a resolution no higher than the current timer resolution, typically 16ms but at minimum 1ms, adjustable via the
380: 592: 619: 614: 272: 261: 154: 158: 32: 368: 509: 314:" for the uninterruptible sleep state of a process. Such processes cannot be killed even with 233:
and implementation details such as timer resolutions when the sleeping thread will run again.
228:
Sleep causes the thread or process to give up the remainder of its time slice and stay in the
240:
and related syscalls are interruptible by signals, returning the remaining sleep time. The
8: 24: 558: 349: 329: 48: 588: 28: 20: 533: 339: 485:"BES – Battle Encoder Shirase 1.6.3 (stable) & 1.7.4 for Windows 7/XP/2000" 320:
and the only non-sophisticated way to get rid of them is to reboot the system.
278: 102:
family of "media timer" APIs. For higher precisions, it is necessary to use a
83:
function takes a single parameter of the number of milliseconds to sleep. The
608: 40: 88: 465: 334: 170: 67: 443: 157:, but was rejected. The UTC time part of the same proposal was added to 142:. POSIX also allows for choosing clock sources via the extended version 344: 265: 123: 103: 52: 452: 430: 408: 421: 315: 484: 111: 43:
for a period of time. Eventually the expiration of an interval
399: 449: 427: 405: 127: 44: 244:
library function, on the other hand, is implemented via the
381:"winapi - Is there a Windows equivalent of nanosleep?" 286:
signals can be generated by these kinds of programs.
248:syscall on many older systems, thus it only works 559:"Processes in an Uninterruptible Sleep (D) State" 606: 223: 507: 297: 55:causes the program to resume execution. 607: 582: 482: 13: 306:In Unix-like systems the command ' 14: 631: 463: 369:MSDN Library Reference - Sleep() 264:that never terminate execute an 138:function and the now deprecated 576: 551: 508:Marletta, Angelo (2015-03-12). 201:In Unix or POSIX system calls: 585:The Linux Programmer's Toolbox 526: 501: 476: 457: 435: 413: 391: 373: 362: 1: 355: 164: 534:"top(1) - Linux manual page" 271:Other programs periodically 7: 323: 276:interval. Certain kinds of 153:was proposed to be part of 10: 636: 583:Fusco, John (2007-03-06). 466:"Modernized API for ISO C" 155:the C programming language 110:, such as the one used in 74: 39:, which places it into an 150: 143: 139: 135: 108:QueryPerformanceCounter() 107: 99: 95: 203: 175: 87:function is included in 58: 255: 224:Low level functionality 130:operating systems, the 117: 250:by delivering a signal 236:On POSIX systems, the 218:// Sleep for 2 seconds 196:// Sleep for 2 seconds 47:, or the receipt of a 587:. Pearson Education. 298:Uninterruptible sleep 16:Computer system call 620:Threads (computing) 615:Process (computing) 483:mion (2016-12-06). 444:clock_nanosleep(3p) 350:wait (system call) 151:clock_nanosleep() 144:clock_nanosleep() 100:timeBeginPeriod() 627: 599: 598: 580: 574: 573: 571: 570: 555: 549: 548: 546: 545: 530: 524: 523: 521: 520: 505: 499: 498: 496: 495: 489:mion.faireal.net 480: 474: 473: 470:www.cl.cam.ac.uk 461: 455: 447: 446: 439: 433: 425: 424: 417: 411: 403: 402: 395: 389: 388: 377: 371: 366: 318: 313: 309: 292: 219: 216: 213: 210: 207: 197: 194: 191: 188: 185: 182: 179: 152: 145: 141: 137: 133: 109: 101: 97: 86: 82: 79:On Windows, the 21:computer program 635: 634: 630: 629: 628: 626: 625: 624: 605: 604: 603: 602: 595: 581: 577: 568: 566: 557: 556: 552: 543: 541: 532: 531: 527: 518: 516: 506: 502: 493: 491: 481: 477: 462: 458: 442: 441: 440: 436: 420: 419: 418: 414: 398: 397: 396: 392: 379: 378: 374: 367: 363: 358: 340:sleep (command) 326: 316: 311: 307: 300: 290: 262:system programs 258: 226: 221: 220: 217: 214: 211: 208: 205: 199: 198: 195: 192: 189: 186: 183: 180: 177: 167: 131: 120: 84: 80: 77: 61: 17: 12: 11: 5: 633: 623: 622: 617: 601: 600: 593: 575: 550: 525: 500: 475: 464:Kuhn, Markus. 456: 434: 412: 390: 385:Stack Overflow 372: 360: 359: 357: 354: 353: 352: 347: 342: 337: 332: 325: 322: 299: 296: 257: 254: 225: 222: 204: 176: 166: 163: 119: 116: 76: 73: 60: 57: 41:inactive state 15: 9: 6: 4: 3: 2: 632: 621: 618: 616: 613: 612: 610: 596: 594:9780132703048 590: 586: 579: 564: 560: 554: 539: 535: 529: 515: 511: 504: 490: 486: 479: 471: 467: 460: 454: 451: 448: –  445: 438: 432: 429: 426: –  423: 422:nanosleep(3p) 416: 410: 407: 404: –  401: 394: 386: 382: 376: 370: 365: 361: 351: 348: 346: 343: 341: 338: 336: 333: 331: 328: 327: 321: 319: 310:' uses code " 304: 295: 287: 285: 281: 280: 274: 269: 267: 263: 253: 251: 247: 243: 239: 234: 231: 202: 174: 172: 162: 160: 156: 149:A version of 147: 129: 125: 115: 113: 105: 92: 90: 72: 69: 66: 56: 54: 50: 46: 42: 38: 34: 30: 26: 22: 584: 578: 567:. Retrieved 565:. 2009-02-21 562: 553: 542:. Retrieved 540:. 2016-12-12 537: 528: 517:. Retrieved 513: 503: 492:. Retrieved 488: 478: 469: 459: 437: 415: 393: 384: 375: 364: 305: 301: 288: 283: 277: 270: 259: 249: 245: 241: 237: 235: 230:Not Runnable 229: 227: 200: 168: 148: 121: 93: 89:kernel32.dll 78: 64: 62: 36: 18: 335:System time 171:Windows API 136:nanosleep() 68:system call 609:Categories 569:2017-02-09 544:2017-02-09 519:2017-02-09 510:"CPULIMIT" 494:2017-02-09 356:References 345:Sleep mode 284:keep-alive 282:events or 266:event loop 165:C examples 126:and other 63:A typical 400:sleep(3p) 279:heartbeat 238:nanosleep 124:Unix-like 104:busy loop 53:interrupt 538:man7.org 324:See also 317:SIGKILL 291:sleep() 132:sleep() 96:Sleep() 85:Sleep() 81:Sleep() 75:Windows 25:process 591:  563:Novell 514:GitHub 453:Manual 431:Manual 409:Manual 330:Signal 140:usleep 112:gnulib 49:signal 35:) may 33:thread 450:Linux 428:Linux 406:Linux 308:ps -l 260:Some 246:alarm 242:sleep 206:sleep 178:Sleep 128:POSIX 106:over 65:sleep 59:Usage 45:timer 37:sleep 31:, or 589:ISBN 289:The 273:poll 256:Uses 190:1000 118:Unix 94:The 29:task 169:In 159:C11 122:On 51:or 611:: 561:. 536:. 512:. 487:. 468:. 383:. 215:); 193:); 173:: 161:. 146:. 114:. 91:. 27:, 19:A 597:. 572:. 547:. 522:. 497:. 472:. 387:. 312:D 212:2 209:( 187:* 184:2 181:( 23:(

Index

computer program
process
task
thread
inactive state
timer
signal
interrupt
system call
kernel32.dll
busy loop
gnulib
Unix-like
POSIX
the C programming language
C11
Windows API
system programs
event loop
poll
heartbeat
SIGKILL
Signal
System time
sleep (command)
Sleep mode
wait (system call)
MSDN Library Reference - Sleep()
"winapi - Is there a Windows equivalent of nanosleep?"
sleep(3p)

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.