There are multiple different levels of “close” that you can do.
On a simpler level, there’s a nice close, where the application is allowed to interrupt it and do things like offer a save prompt. This is what happens when you click the X in the corner.
Then there’s the not-so-nice close, where the OS just rips out the process and stops everything. The process is not allowed to interrupt this one, so it can’t do things like offer a save prompt.
Everything in that program’s window is under the program’s control. Hitting the X sends an event to the program telling it to commence its shutdown procedure (could be a bunch of cleaning up and stuff it likes to do before it quits). But if the program is hung or unresponsive, it won’t do anything in response to hitting the X. That shutdown part of the program is as frozen as the rest of it.
Using the OS to end the program just kills the program’s entire process from above.
The Task Manager in Windows (or Finder in macOS) communicate with programs by sending them *signals*. When a program receives a signal, it briefly pauses (gets *interrupted*) to respond to the signal.
There are a couple common signals an OS might send to a program:
* **SIGTERM**. (Terminate signal). This signal is a request for the program to exit gracefully. For example, the program could save its data to a file before exiting. It is functionally similar to a user issuing a File > Exit or Quit command. Note: since SIGTERM is only a request, a program could ignore this signal and continue processing. An unresponsive program will not be able to handle the signal, and therefore may fail to exit.
* **SIGKILL**. (Kill signal). This signal is sent to forcefully terminate a program. Unlike SIGTERM, SIGKILL is not a request and cannot be ignored by the program. SIGKILL always terminates a program unless there’s an operating system kernel bug or an extremely anomalous condition.
So if we take macOS’s Finder as an example, selecting Quit from the dock menu will cause a SIGTERM to be sent to the application’s main process, while selecting Force Quit sends a SIGKILL instead.
Computers can only run one program at a time. This may seem strange, because it certainly looks like a computer runs many at once, but this is an illusion. Your computer achieves it by switching back and forth between many different programs at once. This is handled by the operating system, and there are a few different ways to do it, but most systems nowadays use a technique called *preemptive multitasking*, where the operating system handles everything automatically. Usually, even when one program hangs, it doesn’t affect other programs. The funny thing is, it’s also an illusion to the programs, which generally think they’re the only thing running on the machine.
So how does the computer manage all of this? It does so using program called a *process manager*, whose job it is to keep track of the other programs and make sure they stay organized. It coordinates with the deepest part of the operating system, the *kernel*, which, among other things, determines which programs are allowed to run and what they can access.
The reason all of this matters to your question is that the Quit command and the Force Quit button approach this problem from two very different angles. When you tell a program to quit, it’s supposed to run whatever kind of housekeeping it needs to, and then tell the operating system that it’s done. This lets the program clean up after itself, but if something goes wrong in that code (or was already going wrong even before then), it might never get to tell the operating system that it finished, and this looks like the program is just hanging.
The Force Quit button, by contrast, tells the process manager that this program is not allowed to run anymore, so please kick it out of the system *right now*. This works in most cases, and if it doesn’t then you usually have bigger problems. But it also means the program doesn’t get a chance to run its cleanup code (if it has any), so it is better to quit programs manually when you can. But sometimes you need a different way, and that’s where Force Quit is useful.
There are actually a number of kill signals that the operating system uses that range from politely asking to shut down to simply killing it no matter what trouble that is going to cause. Now hitting the X, send a polite signal to shut down and usually the programmer can set for himself how to react to that signal, meaning the program can delay the shutdown and instead do something else before shutting down. So for example often enough instead of shutting down the program you’re greeted with a dialogue asking whether you’re sure about that or whether you want to save stuff or whatnot.
That’s meant to give the program a chance to wrap up what it’s doing so that no important stuff gets lost or whatnot. Open connections get closed, parameters get saved, tmp data gets deleted and whatnot. So when a program freezes it can also ignore that signal because “it has better things to do”, now if you disagree with that assumption you can send a more forceful signal in terms of what the operating system has to offer that simply ends the task altogether without a chance to wrap things up.
When you click the x, the operating system sends a “hey, you’ve been told to close, you should close now” msg to the program; so it can close files, save data etc. But if the program is unresponsive its not gonna listen to that. Task Manager’s killing of the program literally removes the application from memory and any scheduling on the CPU.
Its a bit like being asked nicely to leave the bar because you’ve had too much to drink, with the bouncer standing over your shoulder vs. the bouncer literally carrying you outside.
IIRC clicking the X is basically sending the program a request to close. If it freezes, or is running slow/bogged down with other shit, it might take a while if it happens at all. Sometimes it might need to get through the other stuff on it’s list first. If it’s completely bugged out, it may just not respond properly.
Task Manager just forcibly closes the program. You could say they are akin to something like being sent a letter of eviction vs being escorted out by law enforcement.
However there are times when something borked so badly that TM doesn’t work either. I am not sure if the two OS handle things differently, but I have a hunch, because I’ve had much more consistent results with Force Quit in the past than with TM. Maybe because the stuff I’ve done in those systems was different. I’ve had way fewer instances of FQ not actually forcibly quitting something than TM ending tasks unsuccessfully.
Latest Answers