What Alt+f4 actually does? Will using it frequently cause any harm to the system?

Solution 1:

Alt-F4 is the windows command to close an application.

The application itself has the ability to execute code when ALT-F4 is pressed.

You should know that alt-f4 will never terminate an application while being in a read/write sequence unless the application itself knows it is safe to abort.

When talking about games, developers often do not keep in mind that people press the ALT-F4 to quickly exit a game. If the game is saving at that moment (often seen by an indicator of some sorts with a message: do not power off the computer if you see this indicator) and you press ALT-F4, the chances are high that the profile will become corrupt and your savegame is lost.

As for implementation, it works the other way around. Since this is a windows shortcut key, unless a program/game explicitly prevent ALT-F4 to not exit its program, it will always work.

Solution 2:

alt+f4 is a built-in OS shortcut which, when triggered, will send a SIGINT signal to the process managing the active window. SIGINT (as for signal interrupt) is a signal meant to tell the process that is has been requested to stop. When developing an application, you can define in it's behavior that it can "catch" a signal, meaning that you modify the course of action automatically defined by the application when it receives such signal.

A good example of this would be a text editor. Any application receiving a SIGINT will exit, however, developers of text editors will preferably override this behavior to ask the user if it wants to save the current opened file before exiting. In that case developers tell the program not to exit when receiving the SIGINT, but instead prompting the user, and depending on the user choice, manually exit (for example, in Microsoft Word, if the user chooses cancel, the program won't exit, even if it received a SIGINT).

There are several signals with different uses, and there even are several signals regarding exiting an application. Theoritically, you can choose the behavior you want for any of these. SIGINT, for example, could be considered a "soft" exit signal. SIGKILL, on the other hand, is the hardest exit signal that exists, and should never be overriden, as if it is sent, it is usually because the user wants immediate interruption of the program, no questions asked. I could bet, for example, that if you sent a SIGKILL to Microsoft Word, it would exit immediately, even if you have unsaved changes.