myforwik myforwik - 1 year ago 116
C Question

C program that can receive shutdown/terminate requests from linux/upstart/ubuntu

I have a coded a program in C for linux. At the moment I am using ubuntu upstart to run as a background service.

I want to be able to have the program gracefully shutdown when commanded instead of just being killed off. Can someone please point me to the functions used to receive such a command?

(edit: can't answer own post but it seems I am meant to use signal.h signal function to put callbacks on


Answer Source

You want to use sigaction(2) to define a handler to be run when SIGTERM is caught.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download