title: Catch a forced exit from terminal (x button on top OR ctrl+Z)
body: <p>im making a chat in C using TCP connection between client and server.
  Im running that on linux terminal.</p>
  
  <p>First of all i run the server on one terminal, and then every client on another one.
  Everything is done except one thing.</p>
  
  <p>I want that the client program will catch a click on the X button on the terminal or closing the program with CTRL+C ,and before the process die send a message to the server.</p>
  
  <p>There is a way to do such thing?</p>
  
  <p>Thank you, Dudu.</p>