Wikipedia: Gallows humor
"Gallows humor is a type of humor that arises from stressful, traumatic or life-threatening situations such as wartime events, hostilities, mass murder; often in circumstances where death is perceived as impending and unavoidable. It is similar to black comedy but differs in that it is made by the person affected."