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. 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.
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. 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. And these long running tasks should be able to be cleanly cancelled, otherwise you might end up in the situation where clicking the X doesn't work. If you force close a process, the OS doesn't politely request anything - it just kills the app, no questions asked.Ī well designed application should try to be responsive to user interaction even when it has a lot of work to do - show a progress bar, allow the user to move the window etc even if the current task will take minutes or hours. While that is often true, the app could just as easily be really busy scrambling to save your 10 GB file to disk before it quits. When you click the X the OS tells the process "please finish up what you need to and quit." After some allotted period of time, say 3 seconds, if that process hasn't exited then the OS says "hey looks like this might be locked up".
The trick there is that the operating system doesn't actually know the program is frozen, but is making an educated guess.