kill command doesn't do anything - Is Mac OS X *REALLY* Unix

A few times now I have had trouble getting various apps to quit. I try using Force Quit, but that almost never works.
Aside on Force Quit: With apps that are not responding, I choose Force Quit from the Apple menu, then as I select apps and click the Force Quit button, they obediently disappear from the list, but nothing seems to actually be happening - the app is still there, and when I close and reopen the Force Quit dialog, they're back in the list! Force Quit from the context menu of their dock icons also does nothing...


Anyway, so having tried Force Quit and not gotten anywhere, I open up a Terminal window (thinking, here we go, OS X is Unix so I can get right down to the low-level stuff here). I use ps to find out the PID of the app's process and use kill -9 <PID> to try to terminate it manually.

...but NOTHING! If I run the ps command again, the process is STILL THERE!

So now I'm thinking, hang on a second! This is supposed to be Unix, uber-low-level control! I've never had the kill command not work on any other Unix system...

Maybe I'm a paranoid conspiracy theorist or something, but this experience has made me wonder if OS X really is Unix and not some kind of Unix emulation wrapped around a proprietary kernel.

Someone please put my fears to rest (and oh yeah by the way also help me with the kill command thing).

Posted on Oct 16, 2005 9:49 PM

Reply
38 replies

Oct 17, 2005 10:06 PM in response to Gary Kerbaugh

UNIX protects sensitive system data structures (which could affect multiple users) by restricting access to code that executes within a separate "kernel" address space*. When a process does something which needs to modify those structures, it does so by using a special machine instruction (a "trap") which causes execution of operating system code in the kernel address space. Examples of such operations are I/O (changes the system file table, the file system cache, and of course the data on devices), process scheduling (changes the scheduling queue), and inter-process communication... Most low-level C library routines (open/close/read/write/poll/sleep/map etc.) are wrappers around kernel traps.

"Going into the kernel" is executing a trap.

* Processes can't read or write each other's address spaces except through
instructions that can only be executed by the kernel.

Oct 18, 2005 5:18 AM in response to Gary Kerbaugh

OK, what you're saying makes sense, but I don't think it was a process owned by another user. I mean, I'm the only user on my machine, and from memory, I started the process myself... I'll have to pay better attention next time to see who the owner is, but anyway, when I do a kill or killall and I'm no† the owner, I usually get an error message saying "you are not the owner" or something to that effect.

Next time it happens I'll pay more attention to the owner and report back.

Oct 18, 2005 5:27 AM in response to Gary Kerbaugh

But if you're doing a Force Quit, it's precisely because the process has hung and there is no opportunity for it to clean up after itself. Maybe the OS X designers had something else in mind, but as a user, my interpretation of "Force Quit" is "I know there is a potential to lose or corrupt data, but I think we're past that point now and I just want this thing to die". In fact, when you use the GUI to Force Quit it tells you that you might lose data.

The point is, from the GUI, Force Quit is your last option, therefore it should do whatever is necessary at the OS level to stop that process. The fact that there is a way to do it from the CLI doesn't enter into it. GUI builders should assume there is no CLI. That's because avoiding the use of a CLI is the justification for having GUIs in the first place.

Oct 18, 2005 10:40 PM in response to bdinmstig

I'm the only user on my machine


Not as far as the system is concerned. There are lots f users on any *nix system (that's part of the definition of Unix or Unix like system, including Linux).
For example, if you print someting then you have passed asked the user 'lp' to do a something. You may have been the one who started things but lp initiated the process. Open your NetInfo manager and check out all the users-- but don't delete them (as a client once did). Some consultants charge double to fix that sort of thing.

Reese

Oct 19, 2005 3:42 AM in response to Karl Zimmerman

This ignores the most common reason for the spinning wheel and the inability to kill a process, namely it's asleep in the kernel waiting on a resource.

The most common example of this in UNIX is a process in "disk wait" state. This means the process has requested data from the disk and is asleep waiting for it.

A process in disk wait is asleep in the kernel and is not killable, because of the way signals work:
When you kill a process, you're sending it an asynchronous signal. But what really happens is the kernel sets some bits in that process' memory structures telling it that it should deliver the signal to itself the next time it runs.

But guess what - if the process never awakens because it never gets the disk block it's waiting for, it will never execute, thus it will never deliver the signal to itself. Voila! An "unkillable" process.

But since this process still exists, it will still show up in the output of ps and Activity Monitor. You can continue to attempt to kill it all you like, but all that's happening is the kernel is setting the same bits in the data structure telling the process it has to deliver a signal to itself the next time it runs.
The key to all this is that most things a process sleeps waiting for do not fall into this category, and the kill will cause the process to be marked runnable which will cause the process to awaken and deliver the signal to itself as expected.

Oct 19, 2005 6:44 AM in response to bdinmstig

I'm the only user on my machine


Not as far as the system is concerned. There are lots f users on any *nix system (that's part of the definition of Unix or Unix like system, including Linux).
For example, if you print someting then you have passed asked the user 'lp' to do a something. You may have been the one who started things but lp initiated the process. Open your NetInfo manager and check out all the users-- but don't delete them (as a client once did). Some consultants charge double to fix that sort of thing.

Reese

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

kill command doesn't do anything - Is Mac OS X *REALLY* Unix

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.