SFU-Embedded-Cosplay / Halo-Suit-BeagleBone

2 stars 0 forks source link

Elegant shutdown #19

Open HamiltonChris opened 8 years ago

HamiltonChris commented 8 years ago

Need the system to shutdown elegantly by deallocating resources (sockets, dynamic memory) and closing all threads.

Tyler-R commented 8 years ago

We could add a signal handler that causes the while(1) loop in main.c to exit. How to do this is outlined in section 3.4 of the Advanced Linux Programming book. There is also an example just above section 3.4 in listing 3.5 of how to handle a signal. Although we would want to handle SIGTERM as the book outlines in section 3.1.3.

This should allow us to use Ctrl-c to gracefully exit the program and then this could be expanded to allow a specific command in a Bluetooth message to also exit the process.

Something to note is we may want to choose a different signal than Ctrl-c as capturing the Ctrl-c signal may cause issues in the future. For example when we want to quickly kill the process without a graceful shutdown, such as in situations when the process unexpectedly enters an infinite loop while still on the main thread.