LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Paolo_P

Notification in Event Structure When Linux is Shuting down

Status: New

Hi,

 

The Event Structure is able to catch the information when Windows is shutting down is the event "Application Instance Close?".

That event don't work in Linux OS. It exist a workaround in Linux with CIN code, but since CIN has been deprecated with LV 2011, the is no actual workaround.

http://digital.ni.com/public.nsf/allkb/C2470DFFFC71D47F86256F70005891C6?OpenDocument

 

Paolo_P
Certified TestStand Architect
Certified LabVIEW Architect
National Instruments France

17 Comments
wiebe@CARYA
Knight of NI

I still don't see why a cin would be preferred over a dll?

 

I kudo'd the idea, simply because LabVIEW is advertised as working on Linux.

 

How is this not a bug? Either remove the event and document it, or make it work.

rolfk
Knight of NI

It's a bug for sure, but one which may be not so easy to fix. I suppose adding a somehow working implementation might be actually possible, since LabVIEW already does catch the sigterm signal to then terminate itself and obviously also knows when a user selects the Close menu or an application executes the Application Exit node. But it is probably not going to cover every possible corner case.

 

For that matter there exists or at least existed (didn't test it in recent versions) a problem even under Windows. If you use the Application Close? event to intercept a LabVIEW shutdown for some cleanup operation and you tell LabVIEW to disregard that event through the event filter node you can keep calling Application Exit after that as often as you like but LabVIEW will not quit anymore.

Rolf Kalbermatter
My Blog
dadreamer
Active Participant

wiebe@CARYA wrote:
I still don't see why a cin would be preferred over a dll?

It wouldn't in the most cases (99,9% or so), we clarified that in many various threads on this subject. Of course, there are still "decorative" pros of CINs but they are not enough to beat traditional DLL communication. I was just crossing the T's and dotting the I's here to complete CINs tech description for historical reasons.


@rolfk wrote:

For that matter there exists or at least existed (didn't test it in recent versions) a problem even under Windows. If you use the Application Close? event to intercept a LabVIEW shutdown for some cleanup operation and you tell LabVIEW to disregard that event through the event filter node you can keep calling Application Exit after that as often as you like but LabVIEW will not quit anymore. 

I checked that in LabVIEW 2018 64-bit under Windows. Seems to work okay in both IDE and RTE modes. Don't have access to my VMs with Linux and Mac currently, but will try to check the described issue later.

rolfk
Knight of NI

Have you kept the VI running while trying to call the Application Exit node? Because once the last top level VI goes idle LabVIEW will eventually quit anyways. But in the situation where I run into this it was not desirable to trust that there was no other top level VI still running. This was a background deamon that was managing all kinds of resources for a library and the typical user had no idea about this deamon at all. I wanted to be able to intercept shutdown in order to cleanup everything and then ensure that the shutdown proceeded even if the user had some other stray top level hierarchies in his application that were still running. The workaround I used was to not delegate the cleanup to another already existing cleanup state in my state machine but to duplicate the cleanup processing inside the event case itself and to not discard the event.

Rolf Kalbermatter
My Blog
dadreamer
Active Participant

@rolfk wrote:
Have you kept the VI running while trying to call the Application Exit node? Because once the last top level VI goes idle LabVIEW will eventually quit anyways.

I did a simple "one VI" test with a single Event Structure in a While Loop. Like this one:App_Inst_Close.png

 

 

In Application Instance Close? I just discard the event and pass True to both shift registers. So, when I choose File -> Exit menu entry or shutdown Windows, the program waits a half of a second, writes some string to a text file and quits. I checked out and the file is written in all 4 cases: File -> Exit for IDE / RTE and OS shutdown for IDE / RTE. Of course, I cannot see if my process is still alive, when OS is going to shutdown, because Windows switches to "Shutting Down" screen, but it seems to terminate without any problem. Does that matter really?

rolfk
Knight of NI

Does it matter? Well I have a workaround as explained above so it's not something that keeps me awake at night. Smiley Very Happy Does it matter when the system shutdowns? No, not really either! But the Application Close ? event in my case is usually not issued as a result of shutting down the OS, but by the user terminating the application. And I needed a way to cleanup everything that was created in the background during the life time of the application as I do not like to assume that the OS will be able to cleanup everything properly. So intercepting this event and discarding it to then delegate everything to the already existing cleanup state seemed like an elegant solution but after that I needed to make LabVIEW exit again in order to not mess with the user intended action. If Windows (or any other OS) after that is going to shutdown anyways, I don't really care if LabVIEW exits from itself or is just kicked out of memory by the OS Smiley Very Happy

Rolf Kalbermatter
My Blog
dadreamer
Active Participant

@dadreamer wrote:

Don't have access to my VMs with Linux and Mac currently, but will try to check the described issue later. 


Had a similar check on macOS (Sierra) and Linux (Ubuntu) with the app made in LV 2018. On macOS the behavior is identical to that on Windows. On Linux it has a little difference - when compiled binary is running and the user shuts the OS down, the app doesn't have a chance to do something (e.g., to perform a cleanup), it's just killed immediately by the OS. Don't know if it's supposed to be so on Linux or something should be tweaked. All the other things are the same.