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

739 views

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

26 Answers

Anonymous 0 Comments

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.

You are viewing 1 out of 26 answers, click here to view all answers.