I have a console app that is daemonized and running on a raspberry pi 4. It appears to stop running at unpredictable times. As part of the investigation, we put some code in the destructor method to show the stack and other variables. However the most important thing is, we want to know if that method is firing and when it fires (the log will show that if the Destructor method is fired) .
Trying to test this to make sure that the code in the destuctor method actually runs. Since it is a daemon, we use init,d to manage the app. What would be the best way to test this? Using the Kill PID command kills it, but the destructor does not appear to run since there are not records created.
When we try to kill the app when in the debug build mode, the Destructor does not fire either…
Your app has to exit gracefully for the Destructor to fire. A KILL signal is not a graceful exit, so the Destructor is not expected to fire then. Similarly, closing the app from the debugger side is not a graceful exit.
I believe sending a SIGHUP allows for a graceful exit externally.
A kill -sigkill should end immediately skipping ending procedures, but a -sigterm (default) SHOULD (depends on the implementation of the system) end gracefully all tasks and those tasks should end and free their objects firing their destructors. A -sighup is a “disconnect the app from the console” (that could or not end it…) and probably it could not affect a daemonized process running in background. I’m not aware about the correct way of intercepting a termination and handling it in Xojo, but in your case you should check the event UnhandledException for “some crashs stopping it”.
One thing I have been battling to understand, is why doesn’t the Run Event Loop ever get a time slice- I can literally put a quit command in there, but the app never gets to it!?
While StayAlive = True
Quit
DoEvents
wend
The app has Module that is made up of several classes including a Serial object class. There is a loop inside of it that polls remotes and then processes their incoming data; then resumes polling for the next remote device.
It’s not a tight loop, and it has timers that go off too.
I even tried to put a quit command there - nothing. I have it call a method on the App to quit, no go either. Also, I did try to set the StayAlive = False, but again that app.run event never gets focus again.
What may be the issue?
On one hand it behaves as intended since under normal conditions, I do not want it to ever stop. But in this case, trying to find out what’s going on, I do need to exit gracefully so I can collect the Profiling info.
Use a flag (or just expose the property) to change the value of StayAlive so the loop exits and the Run event completes.
The return value of the Run event tells the system whether your app exited as gracefully as you expected. Return something other than 0 to indicate an issue to the system.