9

I'm on macOS 10.13.6.

I often need to set a long process running from the terminal, and then lock my Macbook for a while, and I want the process to be still running when the screen is locked. However, the process just hangs as long as the screen is locked. I can confirm that the Macbook is not asleep, and I've checked the box that says "prevent computer from sleeping automatically when the display is off" in "Energy Saver". How do I keep the process running (not hang) when the computer is locked (but not asleep)?

Ray
  • 241
  • Can you elaborate on what process are you talking about? – Nimesh Neema Oct 11 '18 at 09:52
  • Any long-running process. A machine learning training run for example. More concretely, a Python program that takes ages (hours) to run. – Ray Oct 11 '18 at 10:06
  • Do you use a sleep prevention app like Caffeine or KeepingYouAwake? https://apple.stackexchange.com/questions/89277/keeping-the-mac-awake-when-running-certain-applications and https://apple.stackexchange.com/questions/76107/how-can-i-keep-my-mac-awake-and-locked/186300#186300 – Nimesh Neema Oct 11 '18 at 10:16
  • I've heard of them, but as I said, the computer is not asleep. It's merely locked. – Ray Oct 11 '18 at 10:45
  • I inferred that from the question. I was simply suggesting giving it a try and making observation. – Nimesh Neema Oct 11 '18 at 10:47
  • @Ray What you're describing simply isn't normal behavior with macOS. I'm suspecting that either (a) the program you're running is pausing itself, (b) you're incorrectly determining that the program was stopped while it was actually not, or (c) you're mistaken about the computer not sleeping. – jksoegaard Sep 06 '22 at 22:47
  • I would suggest that you do the following: create a simple script that simply outputs an ever increasing count, lock your display for a minute, unlock it and check whether the count did indeed increase while locked or not. I would also recommend that you try enabling SSH, use another computer (or tablet/phone) to connect to your computer, lock the computer, and then confirm that you can still run commands using SSH. – jksoegaard Sep 06 '22 at 22:49

2 Answers2

4
  1. In System Preferences > Energy Saver, check the box for "Prevent computer from sleeping automatically when the display is off" (on laptops, this is under the Power Adapter tab)
  2. In System Preferences > Security & Privacy, check the box for "Require password after sleep or screen saver begins" and set the delay in the dropdown menu to "immediately"

Now, you can hit command-option-power to turn off the display without sleeping the computer, and doing anything that turns on the display (like hitting a key or clicking a mouse button) will prompt you for your account password.


Credits: This answer

  • 1
    Both are already ticked. In fact I've already mentioned in my question precisely what you mentioned in your point 1. This does not answer my question at all. – Ray Oct 12 '18 at 09:11
0

In addition to the answer by @haran-rajkumar , I've found I need to also do the following to keep things like ssh sessions open and maven builds running in the Terminal app. The preferences below are from Monterey...

  1. In System Preferences > Battery > Battery menu item, un-check the "Put hard disks to sleep when possible".
  2. In System Preferences > Battery > Power Adapter menu item, un-check the "Put hard disks to sleep when possible".
chaserb
  • 101