1

I have a C++ server program running on Linux that receives data from client computers and stores them in a MySQL database. For efficiency, the incoming data is kept in an in-memory buffer and flushed periodically to the database (or when its size reaches a threshold). The flushing period can be long (eg: 3 minutes).

If a user terminates this program (by sending SIGTERM or SIGINT), it should ideally flush the buffers to the database before exiting (a graceful exit).

I have learned from these questions that signal handling is the way to go.

Linux C catching kill signal for graceful termination

Simple Linux Signal Handling

I want to clarify the following points;

  1. Is writing in-memory data to a database a valid thing to do after catching a signal?

  2. Is it better to use signalfd() rather than sigaction() as I can then receive the signals via an FD in the server's select() loop?

  3. Should I catch signals other than SIGTERM and SIGINT in this scenario for a graceful exit?

Community
  • 1
  • 1
Sunanda
  • 95
  • 1
  • 7

0 Answers0