How to find out what launch agent or daemon is starting a process

After installing Autodesk Smoke, I have two httpd processes running all the time, and I'd like to stop them. When I use sudo killall httpd, they stop and are restarted right away. Activity Monitor shows that the parent process is launchd, but how do I determine which agent or daemon is starting it so I can disable it?

launchctl list | grep httpd shows these results:

302 -   0x7f94ea700dd0.anonymous.httpd  
92  -   org.apache.httpd

I look in /System/Library/LaunchDaemons/org.apache.httpd.plist and it shows the following. You can see it's set to disabled. The other launchd item with a weird name doesn't show up in a filesystem search, so I have no idea what it is.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>org.apache.httpd</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>XPC_SERVICES_UNAVAILABLE</key>
        <string>1</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/httpd</string>
        <string>-D</string>
        <string>FOREGROUND</string>
    </array>
    <key>OnDemand</key>
    <false/>
</dict>
</plist>

You can grep the output of launchctl list for the pid:

$ pgrep -fl foo
40679 bash /tmp/foo
$ launchctl list|grep 40679
40679   -   com.example.foo

Then for example look for a file named com.example.foo.plist in ~/Library/LaunchAgents/, /Library/LaunchAgents/, or /Library/LaunchDaemons/.

Edit: the Disabled key can be overridden in /var/db/launchd.db/com.apple.launchd/overrides.plist, which is modified when launchctl load -w is run as root, or in /var/db/launchd.db/com.apple.launchd.peruser.$UID/overrides.plist, which is modified when launchctl load -w is run as the user.

If the Apache plist that comes with OS X was enabled, you can disable it by running sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist.


Based on the label value (e.g. org.apache.httpd), you can try to find the .plist using the following command:

find /System/Library/Launch* /Library/Launch* ~/Library/Launch* -name '*.plist' -print -exec /usr/libexec/PlistBuddy -c "Print Label" {} ';' | grep org.apache.httpd -A1

To find what started the process, check its parent PIDs, e.g.

ps -f $(launchctl list | grep org.apache.httpd | grep -o '^[0-9]\+')

Or use pstree command by specifying PID manually, e.g.

pstree 92