ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Am trying to control the users in my Java application. For that i need to know how to launch a few commands when the user clicks the exit button or presses the X on the upper Right corner of the app. And If there could be some help on how to know if the program terminated unexppectedly the last time the user was logged on it would be very helpful!
Use something like a log file. Write something like 'yyyy-mm-dd hh:mm:ss program started, pid=....' to it when the app starts.
Write something like 'yyyy-mm-dd hh:mm:ss program terminated normally, pid=....' just before the program terminates normally.
If the latter does not show up in the logfile, you know it did not terminate normally.
Or write a pid to a file when the app starts and remove this file when the app terminates normally (often used to check if an app is already running) On startup, check the file. If the pid-file is there at next startup, there was an unexpected termination.