0

I am using a c++ opensource code, which is made as an ".so" and placed in a server. From Java client I will call this ".so" through the JNI package.

Now my problem is, the "opensource C++" code which I am using , doesnt handle any errors. So if something happens in the C++ part the server is getting crashed. So I cant use my application until I start the server again.

My question here is , is there any way to stop the server crash because of the ".so" (C++ code) failure? Right now I am also not in a position to modify the Opensource C++ code as I am in a tight schedule.

Can some one provide me some ideas or work arounds to stop the server getting crashed because of ".so" failure?

1 Answers1

1

I assume that you get SIGSEG or similar.

You could try to catch the signal and do some special handling. I don't recommend this because it's hard the get the code to exit cleanly (memory leaks, and so on).

A better way would be to start a new process and run the ".so" there. This way, no matter how bad the code gets, it's a separate process. If it crashes your main server will be fine, with only a broken pipe (closed file/communication channel) to deal with.

Sorin
  • 11,863
  • 22
  • 26
  • Thanks for your reply. I calling the ".so" from Java client. it would be great if I get an example to do this in Java. – user2881263 Dec 03 '13 at 20:27
  • Check out http://stackoverflow.com/questions/287633/java-c-like-fork @user2881263 – Sorin Dec 03 '13 at 21:33
  • @Sorin I've done this in past, by having the secondary process expose the native library via RMI. Works well. – Samhain Dec 04 '13 at 12:47