When the parent process dies it will take its children with it. Some terminal emulators might give the shell some time to do clean shut down, others don’t.
@samfrmd … my application is a menu driven application where user inout is required at different level hence i cannot run it through nohup as a background process .
Is there any other way to handle the closure of the parent process (terminal in this case)
If the terminal is killed abprubtly, it depends on your terminal how your program will be killed, most terminals just kill their children as a kill -9 $pid would do. Your program has no chance to deal with those events.
Your program is alive until it keeps running. Once it killed through system the program plus all children will be closed so there is nothing to handle your future functions.
As I says above, you can monitor your application with special designed tools for this. On Linux for example it’s a program named monit which can start and restart an application or a process, by a set of rules, without counting how or from where you started or why the process closed. You can also send emails on events and so on. But this is not a matter of programming but application administration.
I don’t see the point, if the Terminal is closed the application is closed too. Monitoring any of them by file, pid or whatever can trigger an event and send a mail…
monit is used for applications which are required to be up and running . in this case the application will bee executed by the user only when required hence i don’t think its possible to configure monit for such scenario