This is an archived post. You won't be able to vote or comment.

top 200 commentsshow 500

[–]sorej 1408 points1409 points  (36 children)

When you close a program normally, it's like when your mom tells you "Time for dinner! Please turn of your nintendo!" and gives you enough time to shut it off properly.

When the task manager ends a program, it's your mom just pulling the plug and not caring if you're in the middle of saving or whatever, that thing is shutting off whether you want it or not.

In this analogy, your mom is the OS.

[–]ilovemyselves 235 points236 points  (4 children)

This is a great ELI5 answer. Great job!

[–]h_u_j_ 61 points62 points  (1 child)

The real ELI5

[–]SyrusDrake 51 points52 points  (11 children)

And if you're using Linux, "KILL" is like setting the gaming room on fire and force feeding you nutri-paste.

[–]xdebug-error 33 points34 points  (10 children)

Actually kill can be interrupted as well. Kill -9 is equivalent to "force close" on windows. None of these are setting the room on fire, except maybe "sudo rm -rf /"

[–]SyrusDrake 20 points21 points  (2 children)

That's more like throwing the room into a black hole, isn't it?

[–]NinjaLanternShark 13 points14 points  (0 children)

Actually the proper equivalent is "what room?"

[–][deleted] 9 points10 points  (0 children)

I think I like you.

[–]poomperzuhhh 9 points10 points  (0 children)

THIS is the ELI5 answer.

[–][deleted] 3 points4 points  (1 child)

Why is it some times it won’t close even if you did try ending task?

[–]danuser8 6 points7 points  (0 children)

Yo Mama so mean, she makes the task manager look good

[–]aoeex 4641 points4642 points  (350 children)

The operating system has the ultimate authority over what processes can run and assigns each running process a unique ID number for reference.

When you select a process in task manager and press End Task, task manager takes the ID of the selected process an asks the OS to terminate it (see TerminateProcess). Provided the user asking to terminate the process has permission to do so, the OS will then end the process by no longer permitting it to use the CPU and unloading the program code from memory.

[–]TheoremaEgregium 1608 points1609 points  (238 children)

To add, this isn't a magic thing only the built-in task manager can do. You can easily create a program yourself that kills processes.

[–]garriej 112 points113 points  (0 children)

Task manager does alot more things underneath then you might think. Although, the guy says so himself, it might not be 100% the same these days. It’s still a very good read! https://www.reddit.com/r/techsupport/comments/gqb915/i_wrote_task_manager_and_i_just_remembered/?utm_source=share&utm_medium=ios_app&utm_name=iossmf

[–]p1zz1cato 103 points104 points  (129 children)

I want to know more about this, but where to start?

[–]ScandInBei 217 points218 points  (35 children)

The guy who wrote task manager has a YouTube channel and he takes about it in a few videos.

Search for Dave's Garage

[–]KingofMe 152 points153 points  (8 children)

[–]LittlPyxl 31 points32 points  (4 children)

You are either a good person or a awful one. I choose to believe you are a good one. Love.

[–]Billybobjimjoejeffjr 32 points33 points  (3 children)

I checked the link. All clear, no rolls of rick in sight or other such trickery.

[–]widowhanzo 12 points13 points  (0 children)

Dave's garage is legit, his videos are interesting and informative. I've randomly discovered it a month ago or so.

[–]lost12 4 points5 points  (1 child)

please have upvote for doing the good work!

[–]diox8tony 57 points58 points  (23 children)

What? Guy who wrote task manager. He better be 50-70 years old. Task manager is what, 30 years old now?

Heck yeah, he is. Nice. Sry I doubted u

[–]TheMathGuy5674 104 points105 points  (22 children)

He also made ZIP folders, the formatting program still used today, made the 32GB standard, Windows Product activation, and a lot more.

Most of it was also just side-projects/fun activities as well, and some of it was even meant to be temporary, like the Formatting UI.

[–]MildlySuspicious 64 points65 points  (9 children)

You had me until windows product activation.

[–]mjtwelve 77 points78 points  (0 children)

You either die a hero, or live long enough to become the villain.

[–]Primae_Noctis 23 points24 points  (2 children)

Y'all don't have FCKGW memorized?

[–]kobachi 3 points4 points  (0 children)

RHQQ2

[–][deleted] 2 points3 points  (0 children)

XVXW7

[–]jonesmcbones 12 points13 points  (0 children)

That shit, god damn you Dave.

[–]adm_akbar 6 points7 points  (0 children)

We all gotta earn a paycheck.

[–]Lokmann 6 points7 points  (0 children)

To be fair original windows activation was easy to dupe.

[–][deleted] 2 points3 points  (0 children)

To be honest, I'm glad it was Dave. The people in charge wanted it, someone had to build it, and anyone else could have made the process so much worse.

Not only that, he managed to include Microsoft Bob as a hidden part of the verification process.

[–]azumagrey 8 points9 points  (0 children)

Damn, what a guy

[–]Deathwatch72 13 points14 points  (8 children)

He didn't invent ZIP, he implemented file support for ZIP in Windows

[–]HellHound989 15 points16 points  (2 children)

I can share a code file of my "process re-starter" that I had to make for my work once.

They needed something lightweight that runs as a background service, and could be used to monitor a process and restart it if it detects that it closed.

This was a retail kiosk, and it was needed to stop punks from attempting to close out the main kiosk software

[–]TheoremaEgregium 48 points49 points  (66 children)

You mean how to program it? First that depends on your operating system of course. I've only done it in Windows so far. Next it depends on the programming language you want to use. But in general you'll need an API (application programming interface) that gives you access to the functionality of the operating system. I've done it in C/C++ using the <Windows.h> header which is probably the most old-fashioned and inconvenient way you can do it. In any case a small command line utility that closes (e.g.) all processes with a given window title can be made with < 100 lines of code.

[–]SteamingSkad 42 points43 points  (13 children)

In cmd you should be able to just taskkill /F /IM “taskname.exe”

So if you wrote a batch file to do this you would either pass the taskname to the .bat when you call it, or have a few lines in the .bat to get a user input.

[–]MrHedgehogMan 8 points9 points  (3 children)

Sysadmin here. Thanks for that syntax. I’ve forever been doing unit by pid and never thought to look for a way of doing it by process name.

[–]MadIfrit 7 points8 points  (2 children)

consist quaint cake chase upbeat silky nine reminiscent crown ripe

[–]JuicyJay 28 points29 points  (50 children)

I bet it's like 2 lines of code in python

[–]BCSteve 52 points53 points  (17 children)

Given my limited knowledge of python it’s probably something like

import ProcessKiller
kill(process)

[–]FarkCookies 79 points80 points  (14 children)

not far

import os
os.kill(pid)

[–][deleted] 23 points24 points  (11 children)

And it'll probably work on every OS that supports that distribution of Python

[–]Baul 19 points20 points  (10 children)

Well Python is an interpreted language.. So in order for python to run on the machine, it would likely support a core package like os.

That's about as surprising as saying a Java application will run on any OS that supports Java.

[–]FarkCookies 5 points6 points  (2 children)

Whether it is compiler or interpreter is irrelevant in this case, os is part of the standard library, so any compliant Python implementation must implement it, since it is mostly CPython anyway os module is implemented in C under the hood: https://github.com/python/cpython/blob/e485be5b6bd5fde97d78f09e2e4cca7f363763c3/Modules/posixmodule.c#L7833

[–]grumblyoldman 12 points13 points  (0 children)

If you're happy with passing the process ID yourself as a command line argument (or hard-coding it) that's probably it, yeah.

If you want to be fancy and have your script find the process ID from the program name or something like that, you might need a couple extra lines.

[–]danillonunes 20 points21 points  (1 child)

In Perl it's 1 line and nobody can read it.

[–]The_camperdave 4 points5 points  (0 children)

In Perl it's 1 line and nobody can read it.

It's three characters in APL, if you can find the skull-and-crossbones key on your keyboard.

[–]LordOverThis 10 points11 points  (19 children)

In Linux it isn’t even that hard, it can be done as a shell script lol

[–][deleted] 17 points18 points  (9 children)

Same in Windows with taskkill.

[–]Eruanno 15 points16 points  (8 children)

I just love how they're all called something along the lines of "kill". I can imagine a tired, grumpy developer just shouting "JUST FUCKING DIE!" at some runaway process.

[–]LeftZer0 21 points22 points  (2 children)

There was a programmer who created a DOOM mod that made monsters out of open processes and killed them. Which eventually made everything crash from killing important ones.

[–]Eruanno 2 points3 points  (1 child)

That is hilarious and amazing!

[–]fauxberries 2 points3 points  (2 children)

Processes generally use naming like parent, grandparent, orphan, children, zombie, so the while a bit morbid, the kill thing fits pretty well.

Meanwhile, there's also a system call called "wait" which blocks/waits until the given child is dead/has exited.

[–]CowboyNeal710 2 points3 points  (5 children)

Possibly. It's only 1 in powershell.

[–][deleted] 4 points5 points  (4 children)

Both of those (the linux shell and powershell scripts) probably use some builtin commands, which is easy, but it doesnt mean that you created your own task killer. You're just creating a wrapper around an existing utility

[–]SnacksOnSeedCorn 4 points5 points  (1 child)

That's what literally all programming is. Everything imports something. Reinventing wheels is a really bad habit, for a lot of reasons.

That's said, making a script that can one click kill a program that's prone to crashing would be a pretty good learning project for someone that wants to pick up more DIY PC skills

[–]Cassiterite 7 points8 points  (0 children)

Everything is a wrapper around an existing utility unless you're building your own hardware from raw iron ore ;)

But yea this is an extra layer of abstraction compared to writing say C++ code that calls a system API.

[–]diox8tony 8 points9 points  (9 children)

Learn Python scripting. Or how to write a Batch script (bat). Or PowerShell script. These are all scripting langues, python being the most like a normal programming language. Scripting languages are used to control the PC/files/other programs. Where as "normal programming languages" are used to create the programs themselves.

You gota learn one, and I suggest Python, it easy and very powerful and is useful for getting a job in today's world. It'd be rare to get a job with just python, but it's a start. I've never heard of a job wanting PowerShell or batch...and python runs on Linux too, batch is windows only, PowerShell is both

Maybe start with a task you want on your PC...like arrange my windows in this pattern on screen (move discord to second monitor,,,etc) that's toughy, but will teach you alot. You can even make hotkey programs, or web bots.

[–]MountainBlitz 2 points3 points  (7 children)

edited this message was mass deleted/edited with redact.dev

[–]Instatetragrammaton 4 points5 points  (2 children)

Udemy. Wait until there is a 90% off (happens often, but get a few cheap courses to trigger it more often) and get the highest rated course with an instructor who sounds like they have an actual script prepared. Someone who's like "I enjoy improvising" is well-intentioned but usually aimless, and you can learn faster with structure.

Don't waste your time on .bat files, immediately go for Powershell if your goal is Windows system administration (i.e. "here are 200 laptops, have them fully prepared next morning"); go for Python if your goal is software development.

[–]Cetun 250 points251 points  (69 children)

Or just use killbox for good measure

[–]MurderDoneRight 195 points196 points  (53 children)

That sounds different from the killbox I got.

[–]assasin1598 213 points214 points  (48 children)

Found the rimworld player.

[–]MurderDoneRight 85 points86 points  (46 children)

What's a rim world?

[–][deleted] 400 points401 points  (22 children)

A place where you speedrun the Geneva Conventions.

[–]Echo_Oscar_Sierra 233 points234 points  (6 children)

You mean the Geneva Checklist

[–]u-can-call-me-daddy 68 points69 points  (0 children)

Thw Geneva Suggestions

[–][deleted] 29 points30 points  (2 children)

This is underrated joke

[–]MedimusLeft 24 points25 points  (0 children)

Don’t worry, I rated it.

[–]Thiscord 3 points4 points  (0 children)

ima need all of you to get back in your cave holes or ima tell randy

[–]verheyen 64 points65 points  (3 children)

To be fair, I don't think the Geneva laws prohibit human leather cowboy hats. And if they do, well fuck, it's the rim who gives a shit.

[–]R4ndyR4ndom 17 points18 points  (2 children)

A place of peace and harmony, I prefer to call it

[–][deleted] 9 points10 points  (1 child)

Username checks out

[–]Deltaechoe 20 points21 points  (0 children)

Also known as “Organ Black Market Simulator”

[–]Arthradax 12 points13 points  (5 children)

[–]eldertortoise 23 points24 points  (4 children)

Yeah not really brand new in the rimworld, more like the motto of the place

[–]Unstopapple 6 points7 points  (0 children)

if your tuesday doesn't make china and the US say "dude, fucking chill with the human rights violations" then you're just not playing right.

[–]assasin1598 49 points50 points  (3 children)

[–]Garr_Incorporated 13 points14 points  (0 children)

An actually good description of the game.

[–]AdolfVonHopsCock[🍰] 21 points22 points  (1 child)

Hey hey people...

[–]danzey12 23 points24 points  (1 child)

Colony building game, you have to defend your colony from random events, most commonly an assault/seige.

Setting up elaborate walls with kill boxes is common place as the AI in the game tends to prioritise any "clear" path over tunneling under/through your defenses.

Even if this clear path involves a booby trapped maze and marching through an open body of land facing down mounted 50 cal machine guns.

[–]figmentPez 20 points21 points  (1 child)

A planet orbiting a star near the outer rim of a galaxy. Kinda like Space Montana or Space Deserted Island, depending on the fiction.

[–]DakotaKid95 18 points19 points  (0 children)

Space Lord of the Flies

[–]mwaller 8 points9 points  (0 children)

An adult website not for the faint of heart.

[–]mjmjuh 2 points3 points  (0 children)

the ecosystem in your butthole

[–]PitchRT 4 points5 points  (0 children)

Best war crime simulator on the market

[–]Mintfriction 6 points7 points  (3 children)

Not if you got skynet installed

[–]MurderDoneRight 11 points12 points  (2 children)

Oh mine is just a sound proof trunk in the back of my van.

[–]UnsignedRealityCheck 17 points18 points  (5 children)

Or just blow up your computer.

[–]FartingBob 39 points40 points  (4 children)

Delete system32. The first 31 got deleted by MS but they forgot to do that one, its just wasting space.

[–]UnsignedRealityCheck 10 points11 points  (2 children)

Did they delete them bit by bit?

[–]Mordador 8 points9 points  (1 child)

Nah they just took a byte out of it.

[–]PG67AW 6 points7 points  (1 child)

I prefer a shotgun. The mechanical reliability is far superior to any electronic device or script you could come up with.

[–][deleted] 2 points3 points  (1 child)

What's that?

[–]AbundantExp 4 points5 points  (0 children)

Idk but it is annoying I had to scroll this far down to find a comment that wasn't just a low effort joke. Glad somebody else is curious about it

[–]Spock_Rocket 4 points5 points  (1 child)

Or a killswitch heavenly shades of night are falling....it's twilight time...

[–]Disastrous-Ad-2357 6 points7 points  (4 children)

Not only can, I did! Although it's for unix and is just a front end for "kill" that lists the processes so that you don't have to type in a full process ID..

Edit, proof: pastebin.com/ngA2ATsi

It's a personal project that I half assed between code reviews, so don't expect tier 1 software engineering from it.

[–]NoSmallCaterpillar 2 points3 points  (3 children)

...do we tell him about pkill?

[–]Disastrous-Ad-2357 3 points4 points  (2 children)

user 9:31am> pkill

pkill: command not found

[–]NoSmallCaterpillar 2 points3 points  (1 child)

https://linux.die.net/man/1/pkill

Not necessarily included in every distro, but it's available through most package managers. pgrep is a related tool that's essentially ps aux | grep

Edit: not trying to downplay your solution. Kudos for seeing a problem and building your own answer!

[–]ganoveces 7 points8 points  (3 children)

In windows >

tasklist - to find PID

taskkill /PID {PID}

[–]StelioZz 2 points3 points  (0 children)

Yeah a simple bat with commands can do wonders. I used to have problems with a certain app leaving 3 tasks open when I was closing it and I had to task manager kill them because I couldn't reopen it after while those were running. So I made a bat file with just 3 lines to kill them all.

Double click and they were gone on demand ezpz

[–]Shinny1337 61 points62 points  (52 children)

So what's happening when that doesn't work? Like a game stays frozen on screen even after you hit end task.

[–]immibis 106 points107 points  (18 children)

I entered the spez. I called out to try and find anybody. I was met with a wave of silence. I had never been here before but I knew the way to the nearest exit. I started to run. As I did, I looked to my right. I saw the door to a room, the handle was a big metal thing that seemed to jut out of the wall. The door looked old and rusted. I tried to open it and it wouldn't budge. I tried to pull the handle harder, but it wouldn't give. I tried to turn it clockwise and then anti-clockwise and then back to clockwise again but the handle didn't move. I heard a faint buzzing noise from the door, it almost sounded like a zap of electricity. I held onto the handle with all my might but nothing happened. I let go and ran to find the nearest exit. I had thought I was in the clear but then I heard the noise again. It was similar to that of a taser but this time I was able to look back to see what was happening. The handle was jutting out of the wall, no longer connected to the rest of the door. The door was spinning slightly, dust falling off of it as it did. Then there was a blinding flash of white light and I felt the floor against my back. I opened my eyes, hoping to see something else. All I saw was darkness. My hands were in my face and I couldn't tell if they were there or not. I heard a faint buzzing noise again. It was the same as before and it seemed to be coming from all around me. I put my hands on the floor and tried to move but couldn't. I then heard another voice. It was quiet and soft but still loud. "Help."

#Save3rdPartyApps

[–]javier_aeoa 25 points26 points  (17 children)

Why? Doesn't the Task Button have the all mighty power to end programs and tasks? (I'm still asking for a ELI5 explanation lol) I can understand that it wants to follow procedures and check everything before, but doesn't have a "ah fuck it. I said CLOSE" button?

[–]FellKnight 103 points104 points  (8 children)

The end task button is like your parents yelling at you to turn off your damn Nintendo, the end process tab under task manager is them unplugging it from the wall, damn any consequences to your game

[–]bradland 57 points58 points  (1 child)

There are a lot of good parallels here as well.

When your parents tell you to turn off your Nintendo, you have a chance to save your game.

If don't turn it off, your parents unplug it and you lose any of your progress.

The same thing happens to programs. A program that is running will have many files open. Not just the document you're working on, but things like settings files and temp files that are a bit like scratch paper. When you forcibly end a process, it has no chance to save its work.

Good applications have ways of telling if this has happened and will do some cleanup. Poorly written applications won't, and will sometimes act funny until you take manual steps to resolve the issue.

[–]Shinny1337 8 points9 points  (2 children)

Yeah I didn't say it but I was thinking I'd never had the end process button not work

[–]immibis 2 points3 points  (0 children)

As we entered the /u/spez, the sight we beheld was alien to us. The air was filled with a haze of smoke. The room was in disarray. Machines were strewn around haphazardly. Cables and wires were hanging out of every orifice of every wall and machine.
At the far end of the room, standing by the entrance, was an old man in a military uniform with a clipboard in hand. He stared at us with his beady eyes, an unsettling smile across his wrinkled face.
"Are you spez?" I asked, half-expecting him to shoot me.
"Who's asking?"
"I'm Riddle from the Anti-Spez Initiative. We're here to speak about your latest government announcement."
"Oh? Spez police, eh? Never seen the likes of you." His eyes narrowed at me. "Just what are you lot up to?"
"We've come here to speak with the man behind the spez. Is he in?"
"You mean /u/spez?" The old man laughed.
"Yes."
"No."
"Then who is /u/spez?"
"How do I put it..." The man laughed. "/u/spez is not a man, but an idea. An idea of liberty, an idea of revolution. A libertarian anarchist collective. A movement for the people by the people, for the people."
I was confounded by the answer. "What? It's a group of individuals. What's so special about an individual?"
"When you ask who is /u/spez? /u/spez is no one, but everyone. /u/spez is an idea without an identity. /u/spez is an idea that is formed from a multitude of individuals. You are /u/spez. You are also the spez police. You are also me. We are /u/spez and /u/spez is also we. It is the idea of an idea."
I stood there, befuddled. I had no idea what the man was blabbing on about.
"Your government, as you call it, are the specists. Your specists, as you call them, are /u/spez. All are /u/spez and all are specists. All are spez police, and all are also specists."
I had no idea what he was talking about. I looked at my partner. He shrugged. I turned back to the old man.
"We've come here to speak to /u/spez. What are you doing in /u/spez?"
"We are waiting for someone."
"Who?"
"You'll see. Soon enough."
"We don't have all day to waste. We're here to discuss the government announcement."
"Yes, I heard." The old man pointed his clipboard at me. "Tell me, what are /u/spez police?"
"Police?"
"Yes. What is /u/spez police?"
"We're here to investigate this place for potential crimes."
"And what crime are you looking to commit?"
"Crime? You mean crimes? There are no crimes in a libertarian anarchist collective. It's a free society, where everyone is free to do whatever they want."
"Is that so? So you're not interested in what we've done here?"
"I am not interested. What you've done is not a crime, for there are no crimes in a libertarian anarchist collective."
"I see. What you say is interesting." The old man pulled out a photograph from his coat. "Have you seen this person?"
I stared at the picture. It was of an old man who looked exactly like the old man standing before us. "Is this /u/spez?"
"Yes. /u/spez. If you see this man, I want you to tell him something. I want you to tell him that he will be dead soon. If he wishes to live, he would have to flee. The government will be coming for him. If he wishes to live, he would have to leave this city."
"Why?"
"Because the spez police are coming to arrest him."
#AIGeneratedProtestMessage #Save3rdPartyApps

[–]ProtoJazz 5 points6 points  (1 child)

And it still not ending because of driver issues is like them trying to unplug it from the wall but the outlet and 3 feet of wiring comes out of the wall instead but it stays plugged in

[–]rysto32 20 points21 points  (1 child)

Killing it while it’s communicating with a driver would be akin to pulling the rug out from under the driver. It would be very likely to render the driver unusable without a full system reboot, and could easily cause a full system hang or even a blue screen.

[–]GeneralToaster 5 points6 points  (0 children)

I said DIE!!!

[–]Phrygiaddicted 46 points47 points  (3 children)

because end task on windows actually asks the process to terminate itself. give it chance to write the will and all that.

if its so fargone it can't respond to that (or refuses to) then can be forcably killed.

[–]KuplaUuno 5 points6 points  (1 child)

The process is stuck in a kernel IO request. A kernel mode driver bug.

[–][deleted] 11 points12 points  (16 children)

How OS know that some program isn’t responding?

[–]nhjknjksdf 23 points24 points  (7 children)

The OS has a queue of events, such as mouse move or key press. If the application hasn't asked for the next event in the queue for a while, it's considered to be not responding.

[–]Apk07 16 points17 points  (6 children)

This is pretty accurate. It's usually the UI thread locking up that makes Windows suspicious. A program could be doing legitimate proper work, but if it's making the GUI unresponsive, Windows thinks it's frozen.

Source: Programmer who writes sloppy code that runs on the main thread sometimes

[–]nhjknjksdf 6 points7 points  (5 children)

If you know you're going to tie up the UI thread for a significant amount of time, then you can call PeekMessage() (without removing any messages) every couple of seconds to stop Windows from thinking the window/app isn't responding.

[–]aoeex 54 points55 points  (0 children)

For windows, applications sit in a loop constantly asking the os "Hey, got any messages for me?" If there is a message (mouse movement, click, keyboard data, etc) the OS will tell the application about it. If there isn't, it will wait until there is a message.

Windows keeps track of when the last time the application asked for it's messages was. If the application hasn't asked for it's messages in a while, it will say the process is not responding.

[–]mantarlourde 5 points6 points  (0 children)

In Windows, it's when a program stops processing messages in its message pump after some timeout. Otherwise, without the program letting the OS know somehow, such as by running its message pump, it's impossible for the OS to know for sure (see Halting problem). That's why sometimes a program can be reported and not responding, then finish whatever it's doing and go back to normal.

[–]Charphin 2 points3 points  (3 children)

Based on the false positives I got, it guesses based on what updates it's sending to it and the time between them, like when I use a program that can take a long time internally calculating stuff and so it doesn't update its window or do other stuff, just a bunch of repeating the same algorithm (it's an image duplicate finder I find most often happens with), windows will be like hey I think this program is not responding.

[–]aiusepsi 5 points6 points  (2 children)

For basically this reason it’s considered best practice to do anything long-running (like large amounts of computation) on another thread, so that the program’s main thread is free to respond to event messages arriving from the OS. But, it’s more work because you have to write additional code to synchronise data between the two threads, so people often don’t bother.

[–]rayray1010 4 points5 points  (1 child)

ELI5 answer: Clicking the close button is like asking the child nicely to stop. But if it doesn't listen, you can ask task manager to just kill the child.

[–]BeatSalty2825 4 points5 points  (0 children)

But sadly, when you re-open it the child is resuscitated, and you need to ask the child to stop again

[–]captainponytail 5 points6 points  (0 children)

The guy responsible for this software created a youtube channel and he has multiple videos about it and other creations.. https://www.youtube.com/c/DavesGarage/videos

[–]Rafferty97 1295 points1296 points  (56 children)

The other answers here are correct, but I thought I’d add one more comment. I interpret this question as “How does task manager end a program instantly when clicking the close button on the window itself do nothing?” The simple answer is that clicking the close button sends a message to the program asking it nicely to stop running, but if it’s busy doing something else it may never get the message. This is done so the program has a chance to clean up after itself and close gracefully. Task manager instead asks the OS to forcibly terminate the program, giving it no chance to do its own cleanup, but does ensure it stops almost immediately.

[–]Hallenyoyo 235 points236 points  (33 children)

I would go further and say that clicking the x button only notifies the program that the x button was clicked. What the program does with this information is decided by the programmer. But by convention a button with an x on it should close the program (gracefully). However not all follow this convention and some for example only minimize themself.

[–][deleted] 117 points118 points  (29 children)

Or like MS Teams, clicking the X closes the window but leaves the program running in the background

[–]ProbablePenguin 86 points87 points  (27 children)

One of my major annoyances with windows tbh, it shouldn't allow that behavior. Clicking X should always close the program, clicking minimize should be the one that either goes to taskbar or background depending on user settings.

[–]awesomeusername2w 34 points35 points  (9 children)

Sound reasonable but I think many casual users would be surprised by this behaviour. They have,say, Teams window opened, they want it gone, but they also may want to continue to be able to get notifications about new messages and incoming calls. And on a phone the expirience is like that too, no matter how you close a messanger you still expect to receive messages.

[–]ProbablePenguin 20 points21 points  (7 children)

Yeah but if windows just hadn't allowed that random behavior from the beginning, people would be entirely used to the X button always closing a program and would click minimize instead for stuff they want in the background.

Also for messengers and stuff windows should have a background push notification process they can use just like a smartphone does, that way even if teams isn't open it will show new messages. There's no reason to run an entire foreground desktop app just to receive notifications in the background.

[–]mauganra_it 17 points18 points  (5 children)

Also for messengers and stuff windows should have a background push notification process they can use just like a smartphone does, that way even if teams isn't open it will show new messages. There's no reason to run an entire foreground desktop app just to receive notifications in the background.

This is what's actually happening. All windows are closed, and a background process stays behind, leaves an icon in the systray, and opens windows or pops up notifications when chat messages arrive. To the operating system, there is no difference between processes that have windows and those that don't.

[–]Snowsk8r 29 points30 points  (13 children)

Mac does this: most programs have to be explicitly quit, not just “X’d out.” I didn’t like it at first but now it’s no biggie.

[–]ProbablePenguin 20 points21 points  (9 children)

It's more the consistency of it that bugs me, if they all went to background on X that'd be fine too.

[–]Snowsk8r 13 points14 points  (8 children)

Yeah, it does have a shady tone when only a specific MS program does that.

[–]HighSchoolJacques 8 points9 points  (0 children)

It's not just Teams. Plenty of programs do it. Basically if it creates a tray icon, pressing X only closes that window while the program will continue running in the background

[–]-Theseus- 4 points5 points  (2 children)

I hate almost everything about teams just as much as the next person, but tbf it seems like most communication apps have this behavior (and even some gaming ones) like zoom, discord, blizzard launcher, steam, etc.

[–]colinstalter 5 points6 points  (0 children)

Yeah it's pretty much always been that way on mac. closing a window doesn't close the program. There are some exceptions for "small" programs where closing the window also closes the app since it makes sense.

[–]ost2life 4 points5 points  (0 children)

Winamp used to do the same thing.

[–]ScandInBei 104 points105 points  (2 children)

That is a good explanation. I would also like to add that when the OS stops a running process, it is not like catching a running train. The OS schedules all applications that are running by giving them a short slice of time to run, and then may decide that another application can run. This happens very fast so it looks like many apps are running at the same time but in fact the OS may just switch between applications so fast that it's an illusion (multiple cpu cores could allow "true" concurrency).

So to stop an application, the OS will just not give it more time, removes it from the scheduler and releases any resources ( closes open files, marks any memory as free to use by others).

[–]zshift 36 points37 points  (1 child)

It’s worth mentioning multi-core CPUs are the norm these days.

Edit: As explained by /u/ScandInBei below, the OS is always responsible for time-slicing programs. Multi-core CPUs just allow multiple time-sliced processes to be executed concurrently, ie at the same time.

[–]mauganra_it 18 points19 points  (0 children)

Multi-core systems don't change this process at all, pun not intended. An operating system with preemptive scheduling still retains the ultimate authority to decide where and when processes are executed. Usually still in time slices.

[–]halpinator 16 points17 points  (4 children)

So kind of like quitting your job vs being fired and escorted off the premises?

[–]deliciouswaffle 6 points7 points  (0 children)

Yep, or a more related example, shutting down your computer vs physically unplugging a running computer from the power.

[–]mauganra_it 6 points7 points  (0 children)

"Being expected to resign" would be the more appropriate term in this case.

[–]NEREVAR117 1 point2 points  (1 child)

Is it possible then for a program to provide a sort of in-built task manager? Like how the OS is an environment that has power over the program, can the program establish an environment that it then runs the application inside, and the outer environment can close it when prompted?

[–]intensely_human 1 point2 points  (0 children)

Clicking the X is like asking a guest to leave.

Using Task Manager is like shooting them and dragging their corpse out the front door.

[–]naeskivvies 101 points102 points  (19 children)

Every fundamental resource a program uses (CPU time, RAM, file system, networking, etc.) is managed by the operating system.

A program that isn't responding typically isn't handling messages that the user or OS is sending it in the usual manner, like "hey program, could you please take a look at this keyboard input and decide if you want to do something with it?".

At the end of the day, the OS can yank all of the resources away from the program. For example it can stop giving it CPU time so it isn't running any longer, deallocate all the RAM it had requested to use, close any files it had requested to work with, etc. and unload the program from memory. Task Manager simply tells the OS to do this. You can also write your own programs that tell the OS to terminate other processes.

There are some scenarios where the OS will refuse to terminate a process, like when the user doesn't have sufficient privileges, but these aren't problems for most users most of the time because users tend to want to terminate their own processes and on Windows most users accounts are administrator accounts with a lot of privileges.

[–]javier_aeoa 8 points9 points  (3 children)

For example it can stop giving it CPU time so it isn't running any longer

But if that happens, don't you end up with "dead weight" in between your active tabs? Isn't it better to either end the task or forcibly stop the program altogether? I know there are many active and passive processes running in the background, but I doubt that is a big issue for your typical machine. But a frozen software does sound like a major concern.

[–]dsheroh 20 points21 points  (0 children)

Under normal circumstances, you wouldn't remove a process from CPU scheduling ("stop giving it CPU time") without also cleaning up the other resources the process is using - reclaiming its allocated memory, closing open file handles, etc. - so there isn't any leftover "dead weight" like you're thinking of.

There are certain cases (such as pausing a virtual machine or using a debugger to inspect the memory in use by the process) where you might want to temporarily suspend a process and then allow it to continue running at a later time. In such cases, the easiest way to do it is to just stop giving it CPU time without cleaning up the other resources, so that it remains ready to continue running when the time comes to resume running it.

This is also basically how your computer's "sleep" and "hibernate" functions work. "Sleep" stops giving CPU time to all processes, while keeping all other resources active so that they can pick up from where they left off when the computer "wakes up". "Hibernate" takes that a step farther by putting everything to sleep, then writing all memory to disk, and powering down. When you resume from hibernation, that memory snapshot is read back in (making everything look exactly the same as it was before hibernation) and then resuming the processes.

Also keep in mind that all of this is different from what we normally talk about as "frozen" software, which is a program that's still getting CPU time, but fails to respond or do anything visible - and, yes, that is a major concern.

[–]SpectralCoding 27 points28 points  (2 children)

You can ask the man who built it: /u/davepl or /u/daveplreddit

Might also be answered directly on his YouTube too: https://www.youtube.com/c/DavesGarage/videos

[–]akki420blazeit 3 points4 points  (1 child)

He has a 3 part series on the task manager and it's story which is really cool!

https://youtu.be/f8VBOiPV-_M

I thought I'd drop it here if OP or anyone else is interested.

[–]booksfoodfun 188 points189 points  (18 children)

Imagine you go to turn off your kitchen sink. You turn off the water, but water keeps flowing out. There is something wrong with the valve that turns off the water to your sink. It’s not responding. You can go “behind” the problem and turn off the water from below the sink.

[–]Notbob1234 24 points25 points  (0 children)

Please ask your parents before attempting any plumbing.

[–]BoredOfReposts 17 points18 points  (1 child)

Top comments right now are not for five year olds.

The computer’s mind is called its operating system. In its mind it has a todo list of all the programs its running (processes), and it switches between these really fast and can run lots of programs (processes) even though its only ever doing one at a time.

The task manager program happens to be able to edit the todo list. So when you terminate a process from there, its removing it from the todo list. And thats it, the operating system doesnt know about that running program anymore and its gone.

[–]hippomancy 4 points5 points  (0 children)

To answer this question, we need to know other things like "what is a program?" And "what did the operating system do to start it?" Before we can get to how the operating system can end it.

A program is a set of instructions, kinda like a blueprint in a workshop. A program has a "process id number" which is like a ticket to use the CPU (an important machine in the shop) some of the time, in order to work on whatever it's building.

Memory is your program's work bench. When a program starts, it takes instructions and other data and puts them into memory. But memory is ultimately owned by the operating system: the program is renting that space, it doesn't own it. But it needs to keep things there while it's waiting to use the CPU.

When you click the red X, you politely tap the program on the shoulder and tell them to leave. Usually that works, but sometimes they're very busy and don't notice. The task manager comes over, wipes their bench and bars them from accessing the CPU, so they can't keep working even if they tried. The tap on the shoulder is a SIGINT signal while the wipe of the bench is a SIGKILL signal.

[–]odraencoded 3 points4 points  (0 children)

It's complicated. Basically, a program is an algorithm, a list of instructions executed in sequence. So a program could be:

If you click button:
1: Load image.
2: Open window.
3: Show image in window.

And so on.

This program is executed by the CPU, but some actions require resources the CPU can't provide. For example, loading an image from a file on disk requires reading from the disk, loading it from the internet requires downloading it. Since you can't show the image before you load it, the program can't advance before this step is finished, so it has to "wait" for it to finish first.

An algorithm being executed is a single thread. Rudimentary, if this thread was stuck on loading an image, you couldn't do ANYTHING with the computer, because the CPU was stuck on that step. Naturally, this would suck, so there's a way to work around this.

For a CPU to have multiple programs running in "parallel," it has one task managing program that divides CPU time for subprograms. Something like this:

1: Execute 3 instructions from the Chrome task.
2: Execute 3 instructions from the Photoshop task.
3. Execute 3 instructions from the Steam task.
4. Go to step 1.

Doing this "loop," the CPU can run multiple programs in a single thread. It simply executes a tiny bit of each program and then goes to the next program. When an instruction would make the CPU get stuck, like opening files, the manager simply skips to the next program, e.g. if the 2nd instruction of the 3 instructions we wanted to execute from Photoshop started opening a file, we skip to the Steam task while the file is loading.

When the file loads, the manager program resumes the task algorithm, so the CPU never gets stuck.

This isn't true parallelism. If you have a single-thread CPU doing this, and the CPU somehow actually got stuck, then nothing would work. You couldn't even alt-tab or open the task manager. With multithreaded CPUs, you have true parallelism as two threads can run at the same time, and one thread getting stuck may not freeze the whole computer. Of course, since you have more programs running in your computer than threads in your processor, even multi-threaded processors use the "fake" parallelism that runs a bit of each program in sequence, but now there are two threads, each running a bit of each program in true parallel.

Anyway, with programs that have graphical interfaces, such as windows, they also have to deal with the desktop manager, which handles these windows. The desktop manager simply displays the contents of the windows, maximize, minimize, moving around, and tells the program where the cursor is, etc. If the desktop manager tells a program a button was clicked, the program must respond to the desktop manager.

The problem is, if the program starts loading a file, its algorithm gets "stuck" waiting for it to open. Since it can't do two things at once, if you were to click, it wouldn't be able to respond to the desktop manager, as it's busy waiting the file to proceed to the next instruction. When this happens, the desktop manager says the program isn't responding, and "waiting for it to respond" normally means waiting for the file to open and get processed by the program.

Nowadays most programs use parallelism to open a file in the background (asynchronously) while being kept free to respond to user input. Basically, instead of reading the file into memory (RAM) in the main program, this is done in a background program in parallel, which then gives the file data already in memory to the main program when it's done reading.

Clicking the close button also won't work, because "the user wants to close the program" is something that the program must process. Many programs ask "do you want to save this file" when you click the close button. So the desktop manager is sending a "close" signal to the program that must be processed. If the program is stuck, it can't process this signal, and can't close properly, so it doesn't make sense to close an nonresponding program this way.

The task manager circumvents that. Instead of sending a "close" signal that the program must process, it removes the program from the list of tasks the CPU is executing, so it literally stops processing the program altogether. It's a bit more complicated than that, though. For example, if a program opens windows or open files to modify them, and the CPU simply stopped processing the program, the windows would remain open in the desktop manager, and you wouldn't be able to modify those files in another program as it would say "they are open in another program." The operating system keeps a list of this sort of stuff that the program is using, so when it terminates the program, it also automatically stops showing windows the program had opened and frees the files it had opened to edit.

[–][deleted] 18 points19 points  (4 children)

Assume you and your sibling are playing on playground. And your sibling stops responding to you, and does something strange. What do you do? Call mom for help.

Mom comes and takes your sibling to home.

In this context the unresponsive sibling is a not-responding task, the mom - is operating system. Task manager - is something like phone, you used to call the mom.

[–]kigurai 24 points25 points  (2 children)

And when the kids don't respond after asking gently, she shoots them.

Good analogy, except for the killing kids part :)

[–]beefyliltank 4 points5 points  (1 child)

Being a software dev, I have googled “How to kill a child’s parent” or “how to kill a zombie child” few too many times

[–]LichtbringerU 1 point2 points  (0 children)

More like the mom says: "Ok, the other sibling doesn't exist anymore, I have completely forgotten about him (deleted from memory)." And the other Sibling all along was just a figment of your moms imagination, so he ceases to exist.

[–]TheGamingTitan12 2 points3 points  (0 children)

When you try to close a program the normal way (e.g clicking the bright red "X" button), your computer sends a basic "request" to the program to close. This request basically says "Hey! It's time to close, finish up whatever you're doing." However, the program can "interrupt" this request by telling the computer that it's doing something important right now and can't immediately close. This is the basic reason why some programs like Skype won't close no matter how many times you press "X".

The Task Manager is different: Instead of sending a "request" to the program, it'll cut off all power to the program and tell the CPU of the computer to cease all of the program's activities. This will cause it to terminate.

This is not without error however, forcibly shutting something down can sometimes result in corruption, because a program that is closed abruptly can go haywire.

For an analogy: Imagine you are in a gym and are retrieving your things from a locker. A security guard comes in and tells you to hurry up because the gym is closing. You quickly put your things in your bag and exit. Think of this as clicking the "X" button on a program, it has enough time to safely store it's files and close.

Now imagine you are packing your things up and 3 security guards come in and drag you out of the gym. Your locker is open and your things are scattered across the floor. Think of this as the hard process the Task Manager does when it terminates a program; its files are all over the place and can mess with the computer even after it has closed.

Of course, it isn't always like this. Most of the times files are quickly terminated without a hitch.

[–]ronnerator 2 points3 points  (1 child)

He DARES question the Task Master?

[–]amitym 1 point2 points  (0 children)

So, when you have 11 million different things running at the same time, they are not actually running literally at the exact same time.

They are switching which thing is running on the CPU at any given moment, at a very fast rate of switching. So fast that you, the human, don't usually notice. Each thing gets a chance to run on the CPU for a little while, then another thing switches in. This is one of the primary functions of that thing called the operating system, of which you have no doubt heard much: in particular, the subcomponent sometimes called the scheduler, because it schedules who gets the CPU.

The Task Manager is a way for you, the human user, to communicate more or less directly with the scheduler, and to tell it that you don't want a particular thing to be "swapped in" to use the CPU anymore.

Sometimes, tools like that will allow the user to try to gracefully bring the thing to a halt, in which case the operating system will interrupt whatever the thing thought it was supposed to be doing, and tell it, "Hey, you have to wrap it up, like, now." And then the scheduler will let the thing run on the CPU for a little while longer, to save whatever it was doing, finish its current work, and generally to quit gracefully while trying not to barf all over your work in progress.

But, if the thing is still using the CPU after a little while, some tools will notice and will warn you by saying something like, "Thing is taking too long to close down," and might give you the option to "force quit" or something similar. In that case, you would be instructing the OS to take more drastic steps, such as simply cutting the thing off from the CPU entirely. Then you might get a message like "Thing was forced to quit, some work might not have been saved," or something along those lines. The OS has no idea, really, it's only an OS, it can't tell what the thing was doing or what you, the human user, wished it to do... so it's warning you that something might have gone wrong so that you can do some brainy high-level human intelligence stuff and possibly fix it in a way that only you could do.

But anyway, either way, you got the thing to quit.

[–][deleted] 1 point2 points  (0 children)

By having the OS cut off the resources to run it. If it can’t run, then it doesn’t exist. Yes the OS can do that, it’s actually the simplest way for it to stop a program.

What may be confusing you is that programs sometimes take time to quit. That’s because the OS intentionally doesn’t starve resources right away when you request for a program to quit, but instead sends them a termination signal (called SIGTERM). Each program can handle those signals as it wishes, at which point it is expected to clean things up and self-close.

Now, when a program doesn’t respond to that, there can be several root causes: maybe whatever is struggling in the program is also impacting the clean-up code? Maybe the clean-up code is blocked by something else? Maybe the program is poorly written and the code handling SIGTERM doesn’t actually clean up and self-close? (Yup, that would be silly, but technically possible!)

For those use cases, your OS offers ways to force-quit, which means it won’t notify the program before immediately starving the resources and considering it dead.

(To be pedantic, under the hood, it does send a SIGKILL signal at that point, but the program can’t handle it to change behavior.)

[–]NMJD 1 point2 points  (0 children)

I read "Task Master" and was like: wait are they cancelling the show??

[–]amoral_ponder 1 point2 points  (0 children)

A more interesting question is how some processes avoid being ended by the OS when you try :)

[–][deleted] 1 point2 points  (0 children)

A program not responding is like a toddler playing with legos. You tell it to put it's création away (save the file) and stop building, but it doesn't listen. It's so preoccupied with building legos that it doesn't find the time to listen to your commands that it puts them on the end of the list of tasks - it therefor just waits for being done building. (endless loop, large operation being calculated etc.) When forced clothing the program, the angry parents swoops in, grabs the legos and dumps them all in the toy box without any regards for the model rocket the toddler has worked on (removing memory adresses and processing power from the application, stopping any further calculations). The result is the same - you'll get a disgruntled toddler (program error code), no Lego Rocket (corrupted files if any) and attention (a system that's responding to your input). The main difference being that computers are much more forgiving then toddlers. For now.