Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quick perl sigint handler

Tags:

perl

What is the most convenient and clear way to handle program cleanup when receiving a Ctrl+C?

For example when my socket server gets killed this way, the TCP socket never gets closed. I would like a nice one liner I can put at the top of the program to set a sigint handler (or something like atexit) to close certain sockets (or doing any other kind of cleanup) before terminating the program.

like image 527
Steven Lu Avatar asked Sep 01 '25 10:09

Steven Lu


2 Answers

It's easy to handle signals by assigning signal handlers via the %SIG hash. More details can be found at perlipc.

like image 187
musiKk Avatar answered Sep 03 '25 23:09

musiKk


Can't be quicker, more convenient or clearer than sigtrap.

like image 39
daxim Avatar answered Sep 03 '25 22:09

daxim