8

I've got a pesky process (in this case, a stranded process that was supposed to be running in iPhone Simulator (now long quit).

97442 ??         0:00.00 (MyProcess)

I've tried everything I can think of, including

sudo kill -9 97442
sudo kill -HUP 97442

And yet, like the Raven... the process remains.

In this case, it means in order to continue working I have to reboot my machine.

5
  • Not a programming question - but have a look at zombie processes Feb 4, 2012 at 1:27
  • Is there a better xxxOverflow then stackoverflow for this kind of question?
    – BadPirate
    Feb 4, 2012 at 1:29
  • I voted for superuser- it should move automagically :-) Feb 4, 2012 at 1:30
  • 1
    Shame is that the context is one that I keep seeing on X-Code 4 (Seems to happen while trying to debug in simulator) which means you can't continue working until you reboot, as trying to launch the app in the simulator with the zombie process in existence causes your app to crash immediately on launch.
    – BadPirate
    Feb 4, 2012 at 1:35
  • Just trying to help here , take a look at this script , it helps me to kill any process with a given "name" works better than killall for me shellswissknife.blogspot.com/2013/03/killall.html
    – user36035
    Mar 27, 2013 at 20:51

1 Answer 1

13

When a process remains in the process table as this process has, then you need to kill its parent process. First, find the parent process PID:

ps -eo 'pid,ppid,comm' | grep 97442

Then run kill <pid> for whatever the ppid result is. (Give it a chance to die cleanly, first.)

The traditional Unix design keeps process information around for the parents to reap and clean up, in case the parent processes want to run getrusage(2) to find out the resource usage of its children, or wait(2) for their exit status, etc.

When parents don't reap their children, the children remain zombies -- UNTIL the parent process is killed, at which point the kernel will re-parent the children to init(8). init(8) will reap the newly re-parented children.

8
  • Hrm, sounds like it would be worth filing a bug report with Apple if you can get launchd to fail to reap a dead child. Will OS X restart launchd for you if you kill it? (Make certain you don't have any important unsaved content before testing.)
    – sarnold
    Feb 4, 2012 at 1:50
  • Hmm.. in this case the parent process is a launchd process, who's parent is PID 1 -- $ ps -eo 'ppid,comm' 97442 PPID COMM 155 (MyProcess) $ ps -eo 'ppid,comm' 155 PPID COMM 1 /sbin/launchd $ ps -eo 'ppid,comm' 1 PPID COMM 0 /sbin/launchd $ ps -eo 'ppid,comm' 0 PPID COMM
    – BadPirate
    Feb 4, 2012 at 1:55
  • Yeah, tried sudo kill -HUP on the launchd process and didn't do anything, using the same rules, looked for it's parent and applied the same technique, still no joy.
    – BadPirate
    Feb 4, 2012 at 1:56
  • I expect launchd will ignore or block the HUP signal. (Which signals a modem hangup. These days it's also used when ssh drops the connection, bash(1) or other shells will deliver HUP to the child processes it started. Because it can't happen for daemons, most daemons will either ignore it or use it to signal a request to re-read a configuration file.) Try just kill $(pidof launchd) and if that fails, kill -KILL $(pidof launchd).
    – sarnold
    Feb 4, 2012 at 2:01
  • 1
    Hmm, so maybe this morphs into a launchctrl question... I tried killing the launchd process, but that took out my OS :) Which ultimately allowed me to get back to work (after a restart)... however the mule in me seems to think there has to be a way to clear the process without necessitating a restart :/
    – BadPirate
    Feb 6, 2012 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .