What happens to my app when my Mac goes to sleep?

前端 未结 5 1769
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 23:05

When Mac OS X goes to sleep, due to closing a laptop or selecting \"Sleep\" from the Apple menu, how does it suspend an executing process?

I suppose non-windowed process

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 23:53

    It depends on your app.
    If you are interacting with external systems (think networking or doing something over usb/firewire,etc) then it might be affected. An application running on OSX gets to run for a limited time ( max 10ms ) , after which it is interrupted by the kernel which schedules a new process from the process queue to run on the CPU. This is transparent for the application , which "thinks" that it runs all the time on the CPU. Thus , a transition to sleep is no different - apart from the time jumping ahead.
    If you need to be aware that there was a transition to sleep mode please refer to this tech note which details how to receive notifications about the state change : Registering and unregistering for sleep and wake notifications

提交回复
热议问题