Why does ending a task from task manager work better than canceling a program?



When a computer starts to freeze or operate slowly and doesn’t respond, ending the task(s) from the task manager usually ends the program and the problem. Why does this work better than simply canceling the task with ALT+F4/pressing the cancel button in the window?

In: Technology

Because the “close” button asks politely, while the task manager is like [forcefully throwing somebody out of the door](https://www.youtube.com/watch?v=qvJeATp31dw).

In general you want the first one, because it allows things to finish in an orderly manner, and allows the program to ask “Do you want to save the last 6 hours of work?”

A lot of programs have what is called “shutdown hooks” which is basically a piece of code that does something when you click Close or Alt-F4. The easiest example is the dialog you get when closing browser (“Do you want to close multiple tabs?”) or when closing Word or Excel (“Do you want to save your changes?”). When the program freezes it can get blocked completely so the hooks are waiting for the program to unfreeze which it never will so the program can’t close at all.

Ending the program in task manager bypasses all that and “kills” the process (think depriving it of resources). So it’s more effective in closing the applications but can result in unwanted things, i.e. losing changes, stuff not being saved to DB, connections not closing properly etc.

End task, alt+f4, and clicking the corner x all do the same thing. They politely ask the program to stop. The program will normally finish what it’s doing, maybe pop up a message asking if you want to save, and then close itself. This is usually the best way to close a program. It gives the program a chance to finish what it’s doing so everything works properly. But, if the program is already malfunctioning, like if it’s frozen, asking the program politely to close might not work, as it’s already too messed up to respond to requests.

End process is different. It just kills the program instantly. It doesn’t let the program finish what it is doing, it doesn’t let the program control how the program shuts down. It just stops everything instantly.

If your computer was a bar, most ways of closing a program would be like asking “We are closing soon, please finish your drink and leave.” Ending the process is like a bouncer physically picking up a patron and tossing him out the door: it works even if the patron is passed out drunk.

To understand this I think you want to understand what differentiate killing a task, sending a shutdown command and pressing the “X”.

A shutdown command (Pressing X, quit from the software, in some cases alt – f4) is like when the factory closes down at the end of the day. Workers will put tools back, turn of all machines calmly and orderly and clean up the work space. In computers that would be writing caches/deleting caches, writing saved setting to a config file, sending some data to a server, making sure open documents are saved.

A “kill” command, what task manager does, is like the fire alarm going off in a factory. Everyone just drops everything and runs out. (Maybe more accurately it would be like if someone just took the factory and launched into space with no traces left of it. The OS just drops the task associated with the application”)

Alt – F4 is a Windows OS specific shortcut that sends a kill command to currently focused window. Which is why it often doesn’t work for some application that fail to launch completely. Applications can be made to “intercept” this command though.

I don’t know the full technical details of how an OS handles the different terminate signals it can send, but I feel this analogy explains why task manager often works, it simply doesn’t do all the things a normal shutdown of an application does.

I know others already talked detailly about the difference between cleaning up and close the program, and directly yeet the process to oblivion. But another thing is that usually when u need to use the task manager or any OS-level process manager to close a program, its because the program hanged.

In that case, asking the program politely to stop itself will not work as there is no free threads in that process that can handle the “close down the program” callback. Only an outsider (the OS) can directly shut down the process.

Using the factory analogy others used, when every worker in the factory is being unproductive and just shout at each other, adding to the chaos and shout “stop and leave” is not gonna work. Someone has to work from the outside, and probably just burn down the whole place.

But the problem with this is that all the previous work and products that those workers made that havent been shipped out of the factory are all gonna be lost (cuz they all got burned down). Similarly, all the previously done calculation and unsaved progress of applications are going to be lost after being terminated by the task manager. So all you got left after terminating Word is the autosaved version 10 minutes prior.

Most relatable answer is Skype that doesn’t want to close after closing, so you TERMINATE the program by knocking it out with a roundhouse kick

Closing a program normally is like getting a valued guest to leave amicably when they’ve overstayed their welcome but it’s too awkward to bluntly tell them to leave.

Closing it via task manager is like telling them to fuck off and die and shooting them in the head.

When your wife texts you it’s time to leave the bar you close your tab, get your credit card back, put on your jacket, take a leak on your way out. When your wife texts the bouncer she knows he picks you up and throws you out of your ass. Option two is faster, but not always better.

[I think the man himself answers this most effectively](https://www.youtube.com/watch?v=f8VBOiPV-_M)

Alt+F4 is like asking a guest to leave.

Task Kill is picking them up and throwing them out the window.

Basically the OS sends a message saying “Stop what you are doing gracefully” (Alt+F4) and if it doesn’t it shoots it and attempts to clean up the body (Task Kill).

X’ing out of a program means you are requesting that the program end itself. If the program isn’t working, it may not be able to do anything at all, including closing itself.

Using the Task Manager means you’re asking the computer to close the program. Your computer is still working, even if the program isn’t, so the computer can carry out the close command where the program can’t.

Closing a program the normal way is basically telling it “ok, finish up all the stuff you’re doing and get out of here”.

Killing the task (or better yet, process) says “I don’t care what you’re doing, get out now.”

Pressing the X is like telling someone to leave. Ending the task is like physically removing them.

When you press the X, you’re telling the program to shut down. When you end task, you’re telling your computer to stop running the program.

The real ELI5 explanation: Pressing the close button is like asking you to leave the room. Using the task manager to end an application is the same as your parents dragging you out of the room.

Computer engineer here!

When you exit a program, it tries to do some clean up before it shuts down completely. If the program is already having problems, it may not even recognize that you asked it to shut down and never gets to that step. As a result, it either doesn’t quit or it takes a long time.

One of the things your operating system does is pause and resume different programs really quickly so that you can run multiple things at one time (like listen to music and surf the internet). When you kill a task through the task manager, you are telling the operating system to remove that task from its todo list and give back the RAM.

It doesn’t. Killing a program this way is like stopping a car by firing a rocket at it instead of turning the traffic lights red.

You stop the car both ways, but one way is guaranteed to be ok to drive after, and the other might not depending on if your rocket hit the car or just the road in front.

The simplest version is that the operating system controls virtually all access between software and the hardware. The application itself can send instructions to the operating system to say “Hey, I’m good to shut myself down”, which the operating system will then accept and process…killing the task. If you use Task Manager, you are more closely interacting with the operating system itself (technically, using a different application with higher privileges) – and your instruction is to “stop executing that task”, which the OS is happy to oblige, usually, and usually quickly.

The reasons why Task Manager is quicker at the job:

* if the application has any house cleaning to do before it shuts down like freeing up used memory or saving inprogress files it will complete them before asking to be shut down
* if it’s busy doing …whatever it is that it is supposed to do…or if anything has gone wrong and it’s stuck in an infinite loop – there may not be enough instruction cycles left for it to actively monitor the X button for clicks, so it never, or very slowly queues the command to shut itself down.
* Task manager doesn’t care about those things – it just looks at the list of tasks that get allocated processor time, and removes the task/threads associated. That program ceases to exist.

When you say ‘work better’ – it works better at killing the program more quickly, but can do damage to files that may be in the process of being written, only getting part of the data computed or stored before the app stops.

I’ll just throw in a Linux reference (I don’t know if this also applies to windows).

There are 3 main ways to terminate a program in Linux: from the program itself, with a signal, hard kill.

Within the program: programs often look for you to ask it to close. That might be pressing a key or clicking a button. The program has to specifically look for that happening. Sometimes there’s a bug in the program and it forgets to check for your request. In that case clicking the button or hitting the key does nothing.

Signal: the OS can interrupt the program and tell it to do something, this is called a signal. Signals can be sent in multiple ways, but the command “kill” is the typical way from the command line (despite the name, kill can send lots of different signals, not just the one for kill). Even if the program is stuck doing something, the OS forces it to stop that and do something else. That something else is called a handler and the program decides what it is. On Linux, the signal that tells the program to shut down is called SIGTERM. If all goes well, the program stops what it’s doing (even if there’s a bug and it normally couldn’t stop) and tries to shut down cleanly (just like the “within the program” case). The big difference here is that the OS interrupted the program rather than the program checking for your request itself.

Hard kill: if both of the above fail, it means the program has a big problem and can’t be trusted to shut down. In this case, we’re not even going to ask. No buttons, no signals. The OS just stops the program in its tracks and removes it from memory. This is done using another signal called SIGKILL. This signal is special because the program never even sees it, the OS does everything.

We prefer the first two methods because the program might want to save open files and generally clean up after itself. The last one is a last resort since the program doesn’t have a chance to do anything before it dies.

One you ask politely for it to leave and wait for it to get its luggage, fill it and calmly leave.

The other you kick it out the door and burn its belongings.

The guy who wrote task manager has a YouTube channel and made an episode about this. Search for Dave plummer.