开发者

C# (Mono): Restarting process on program failure

开发者 https://www.devze.com 2023-04-08 16:38 出处:网络
I\'m fairly new with working in Mono and would like to kn开发者_StackOverflowow how I can force my console application to restart upon exception under a linux environment. How would I go about doing t

I'm fairly new with working in Mono and would like to kn开发者_StackOverflowow how I can force my console application to restart upon exception under a linux environment. How would I go about doing this?


If the process dies, you can use something like Monit to keep it running. Brief description:

Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources.

Typically, coding an application to "be able to restart itself" is never reliable enough. It someone were to terminate the application using kill -9, your application would have no ability to respond to that. Thus, the need of some type of daemon or watchdog is required.


I'm not sure if this would work under Linux since I've never used Mono, but what I would try is to hook into the Process.Exited event. (I'm assuming you're starting your application with the Process class)

Process.Exited http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited.aspx

So you could do something like...

-start process -hook into exited event

-wait till exited event is called

-start process -hook into exited event

Good Luck!


I'll recommend this get moved to superuser.

There is nothing inherently in Mono you want to use. You could create a Watchdog application in Mono that will check and ensure your process is always running but there are plenty of Linux scripts and applications to already do this. Monit is an example.

Or you can go into /etc/inittab and find the rows called respawn and add your daemon there. init will ensure that process is always running.

Here is an example daemon startup script for Java which you can modify for mono. http://shrubbery.homeip.net/c/display/W/Java+Daemon+Startup+Script

0

精彩评论

暂无评论...
验证码 换一张
取 消