asaenko
asaenko

Reputation: 235

What are the ways application may die?

I develop linux daemon working with some complex hardware, and i need to know ways how application may exit (normal or abnormal) to create proper cleanup functions. As i read from docs application may die via:
1. Receive signal - sigwait,sigaction, etc.
2. exit
3. kill
4. tkill

Is there is some other ways how application may exit or die?

Upvotes: 0

Views: 47

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283793

In your comments you wrote that you're concerned about "abnormal ways" the application may die.

There's only one solution for that1 -- code outside the application. In particular, all handles held by the application at termination (normal or abnormal) are cleanly closed by the kernel.

If you have a driver for your special hardware, do cleanup when the driver receives notification that the device fd has been closed. If you don't already have a custom driver, you can use a second user-mode process as a watchdog. Just connect the watchdog to the main process via a pipe... it will receive a signal when the main application closes.


In addition to things the programmer has some degree of control over, such as wild pointer bugs causing segmentation fault, there's always the oom-killer, which can take out even a bug-free process. For this reason the application should also detect unexpected loss of its watchdog and spawn a new one.

Upvotes: 1

user4011964
user4011964

Reputation:

Your app should finish by itself when the system or the user doesnt need it.

Using an external commando like a kill -9 PROCESS could give you some bugs on your application because you don't know what is your application doing in that moment.

Try to imeplement over your app a subsystem to control your application status... like a real daemon to allow something like this:

yourapp service status  or  /etc/init.d/yourapp status
yourapp service start  or  /etc/init.d/yourapp start
yourapp service stop  or  /etc/init.d/yourapp stop

In that way your app could finish normally everytime and the users could control it easily.

Regards

Upvotes: 0

Related Questions