Causes
Hardware can cause a computer to hang, either because it is intermittent or because it is mismatched with other hardware in the computer (this can occur when one makes an upgrade). Hardware can also become defective over time due to dirt or heat damage.
A hang can also occur due to the fact that the programmer has incorrect termination conditions for a loop, or, in a co-operative multitasking operating system, forgetting to yield to other tasks. Said differently, many software-related hangs are caused by threads waiting for an event to occur which will never occur. This is also known as an infinite loop.
Another cause of hangs is a race condition in communication between processes. One process may send a signal to a second process then stop execution until it receives a response. If the second process is busy the signal will be forced to wait until the process can get to it. However, if the second process was busy sending a signal to the first process then both processes would wait forever for the other to respond to signals and never see the other’s signal (this event is known as a deadlock). If the processes are uninterruptible they will hang and have to be shut down. If at least one of the processes is a critical kernel process the whole system may hang and have to be restarted.
A computer may seem to hang when in fact it is simply processing very slowly. This can be caused by too many programs running at once, not enough memory (RAM), or memory fragmentation, slow hardware access (especially to remote devices), slow system APIs, etc. It can also be caused by hidden programs which were installed surreptitiously, such as spyware.
Read more about this topic: Hang (computing)