rugarciap / Turbo-Boost-Switcher

Turbo Boost disabler / enable app for Mac OS X
GNU General Public License v2.0
1.48k stars 146 forks source link

Zombie Processes #201

Closed WaywardHeart closed 5 months ago

WaywardHeart commented 11 months ago

AuthorizationExecuteWithPrivileges leaves behind a zombie process that persists until the application either exits or calls waitpid on it. If you go long enough without either quitting the app or restarting the computer, this eventually starts causing problems as the root user accumulates hundreds of defunct processes (two new processes every time the computer wakes from sleep and turbo boost is re-disabled). Unfortunately, the function doesn't provide the child process's pid, which makes reaping the child process a little complicated. A quick search shows people have found two solutions to the problem:

  1. Have the child process echo its pid and retrieve it from the communications pipe to pass to waitpid
  2. Call while (waitpid(-1, 0, WNOHANG) > 0); afterward to attempt to reap all stopped child processes. Simply calling wait(NULL); immediately afterward should also work if you're not worried about the child process never exiting for some reason.

I tested the second solution and found that it leaves the latest child process lying around, but that's harmless compared to what's happening now.