Freeman
Freeman

Reputation: 121

How to make thread crash will not lead to process crash?

My project language is C and will just run one process and multiple threads.

One of thread always crash, it will case process crash.

The stability of the process is very very important. So I want to know whether it is possible to "isolation" this thread. For example, if we can intercept SIGSEGV signal, we can just restart this thread.

Upvotes: 0

Views: 433

Answers (3)

Roy Segal
Roy Segal

Reputation: 11

Depends on the cause of the crash. It could be memory related resulting in corrupt data thus leading to the process crash. If the program does crash and it is critical, use Monit to restart it.

Upvotes: 0

Stephen C
Stephen C

Reputation: 718768

The stability of the process is very very important.

Then it is very very important that you find and fix the cause of the SIGSEGV rather than "papering over the cracks" by trying to recover crashed threads.

Why?

  • Because the root cause of the SIGSEGV could be bug that will be retriggered in the restarted thread, leading to endless crashing/restarting of threads.
  • Because the root cause of the SIGSEGV could be a problem in a different thread ... which could continue triggering the problem.
  • Because in the execution steps leading up to the SIGSEGV, the thread could have corrupted shared data structures or done other things that may cause other threads to crash, get stuck or behave incorrectly in other ways.

Upvotes: 1

dbush
dbush

Reputation: 223739

If one thread does something that could cause a crash it might be affecting another thread since they share the same memory space, so there's no way to isolate them.

You need to fix your program so it doesn't crash in the first place. Start by using a memory checker such as valgrind.

Upvotes: 1

Related Questions