15

When I run Zotero/Firefox, they often crash and I am left with zombie processes; after this I cannot open new instances of Zotero or Firefox. I want to get rid of these zombie processes rather than rebooting, so for <pid> of the zombie process,

$ ps -p <pid> -o ppid=

gives me the <parent_pid> and

ps aux | awk -v PID=<parent_pid> '$2 == PID {print $0}'

tells me the parent process is /sbin/launchd for user crippledlambda.

Is there a way to restart this without killing my system?

sudo kill -1 <parent_pid>

does nothing. I've tried writing this in a script and running it with sudo:

for i in `launchctl list | grep launchd | awk -v PID=<parent_pid> '$1==PID { print $NF }'`; do `launchctl stop $i && launchctl start $i` ; done

and this obviously(?) leaves me with an unresponsive gray screen so I have to reboot anyway. Thanks in advance for your suggestions.

Doktoro Reichard
  • 5,390
  • 5
  • 35
  • 42
hatmatrix
  • 844
  • 2
  • 10
  • 21
  • Why are you killing launchd instead of the leftover processes themselves? launchd is a core part of the user session; even if you could restart it, the new instance would not be the parent of all the *other* processes it's responsible for... things like the Finder, Dock, etc. – Gordon Davisson Apr 21 '13 at 04:13
  • @Gordon, you cannot kill zombie processes so you have to go after the parent, unless I'm missing something. – hatmatrix Apr 23 '13 at 12:13
  • Are they true [zombies](http://en.wikipedia.org/wiki/Zombie_process) (i.e. processes that have exited, but whose exit status has not been read)? If they are, something much deeper is wrong, since `launchd` should always read its children's exit statuses immediately. If they aren't truly zombies, then you should be killing them. In either case, killing `launchd` is going to cause more problems than it solves. – Gordon Davisson Apr 23 '13 at 15:55

2 Answers2

19

The proper way to stop and start launch daemons is launchctl unload.

For example:

You can stop a launch daemon service using the unload subcommand of launchctl.

$ sudo launchctl unload /System/Library/LaunchDaemons/<daemon name>.plist

To start a disabled or stopped launch daemon:

$ sudo launchctl load /System/Library/LaunchDaemons/<daemon name>.plist

★ Be careful with disabling launch daemons haphazardly - especially the official Apple ones; it can potentially make your system unbootable until you start in safe mode and manually re-enable them. You don't kill a launchctl like a normal process because it can potentially kill your system like you've experienced.

> more info on launchctl here. (Apple launchctl man page)

Mena Ortega
  • 191
  • 2
  • Sorry, is that `com.apple.bsd.launchdadd.plist`? I don't see `launchd` exactly. And thanks for the warning... – hatmatrix Apr 23 '13 at 12:15
  • For future reference, these commands also work with `scrun simctl spawn sudo launchctl unload …`. The plist files are under `$(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/LaunchDaemons/` – Léo Natan Apr 19 '17 at 10:49
  • This does not answer the question and is not helping others with the same problem. Looks like restart is the only solution – zzz Mar 25 '22 at 02:38
4

From the launchd man page:

You cannot invoke launchd directly.

Hence even if you could stop it you would not be able to start it so the answer is that there is no way.

ostergaard
  • 561
  • 4
  • 8
  • 1
    Why the downvote? My post correctly answers the question asked. Granted the other post is more constructive but it actually fails to answer the actual question as per the title of the post! – ostergaard Jan 01 '18 at 12:18
  • The other post does answer the question. – DavidPostill Jan 01 '18 at 12:41
  • 4
    No it doesn't, it says how to restart daemons not launchd itself. – ostergaard Jan 01 '18 at 12:44
  • {shrug} whatever. In any case complaining about downvotes is not constructive. Clearly people think your answer is not useful. – DavidPostill Jan 01 '18 at 12:46
  • 6
    lol - and it's that attitude, that accuracy no longer matters, that explains the slow decline in quality on SO. Happy New Year! – ostergaard Jan 01 '18 at 13:00
  • 3
    Too bad I can't downvote comments. Not only this answer is correct, the other answer fails to actually address the question at all. This isn't about daemons started by launchd, but zombie processes inherited by launchd when an unresponsive process has been forcibly terminated. I have the same problem and no bloody daemon to kill since it's a browser that triggers the faulty behaviour in launchd. Replying with "whatever" gets my blood boiling as the same people who have found the answer useful fail to understand the question in the first place and that's worse by an order of magnitude. – SaltwaterC Dec 23 '19 at 20:01