2

My Mac won't sleep, not even the screen saver turns on.

If I press the sleep option at the top left corner or hit the key combo: touch-id button with not registered finger, locks computer, then escape, sleeps.

Goes to sleep but comes back after some time.

  • I do not have any sharing options enabled (System Preferences → Sharing).
  • I do not have "Wake for network access" enabled (System Preferences → Energy Saver).
  • I tried to reset the SMC and the PRAM, but the key combinations I tried didn't seem to make and effect at restart. Maybe I should try more.

Ran:

pmset -g assertions

found out there are a bunch of caffeinate processes running, keeping my mac from sleeping. If I kill them, one always comes back.

$ ps aux -o ppid | rg caffeinate
root             24456   0.0  0.0 408544784   7200   ??  S     4:32PM   0:00.02 caffeinate -d -i     1

Seems like my Mac is infected with something. Downloaded Avast rans a scan, nothing found. Does anyone know why does this happen, which app does it?

Thanks MacBook Pro M1 Max, 2022, Monterey 12.6

Alper
  • 3,936

1 Answers1

4

It's really great that you used -o ppid because you can see the last column says the parent process ID is 1. If you do ps 1 you should see that the parent process is /sbin/launchd. That's why caffeinate keeps coming back. Someone or something has created a LaunchDaemon config that is respawning it.

There are at least a few different scopes for LaunchDaemons and it's a little hard to find them all. I recommend using Lingon because it shows you every possible thing that is launched and what file controls its launch. The free version will show you things, the paid version lets you manage them from within the Lingon app. I recommend using Lingon to figure out which of the launchctl files is spawning caffeinate.

A different brute-force approach would be to simply grep all the launchctl files.

sudo grep -r caffeinate /Library/LaunchAgents
grep -r caffeinate ~/Library/LaunchAgents
sudo grep -r caffeinate /Library/LaunchDaemons
grep -r caffeinate ~/Library/PrivilegedHelperTools

The name of the file will give you a hint at what app has created this file. E.g., a file named com.microsoft.teams.TeamsUpdaterDaemon.plist strongly suggests that it was Microsoft Teams that created the file.

Hope that helps.

Paco Hope
  • 171