I wrote a posture sensing code in edison device in c. I have succeeded in invoking the application at power up. But I need a shell script to close this application at power down.
I have tried kill {pid}
command line operation. Even though I killed the command, during power down device need an extra 5 min to stop that application. Am I missing something here..
Your application should explicitly handle some signal(7)-s, in particular SIGTERM
which is sent (by some system program doing a kill(2)) at shutdown.
Sending a SIGKILL
(e.g. kill -9
or kill -KILL
) is unsafe (in particular to server maintaining some state on disk, e.g. database servers, but also any software having some kind of persistent state, or configuration, or logs...) because the killed program has no opportunity to clean its mess, flush its buffers, and save a consistent state on the disk.
So the robust policy is to kill -TERM
, then a few seconds later kill -QUIT
and a few seconds later kill -KILL
. Hence, robust applications should handle SIGTERM
and SIGQUIT
(but SIGKILL
cannot be caught)...
You might handle SIGPWR
(but not every system has it or manage it properly; some UPS hardware & software do).
Perhaps your system uses systemd and you could take advantage of that (e.g. D-bus things).