Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happen if thread crashes, which is better thread or process?

I am writing a server application with one connection at a time, I receive a TCP request which has symbol names of function and name of shared libraray.

My server needs to load the shared library using the dlsym system call and call the function using symbol name received.

Right now loading the shared lib and executing the function I am doing in separate thread. My doubt is when thread crashed due to segmentation fault or any signals will my process gets affected ?

Which one is better whether to run in separate thread or process.

Please ask me question If my question is not clear.

like image 756
Bhavith C Acharya Avatar asked Apr 05 '16 10:04

Bhavith C Acharya


1 Answers

A crash in a thread takes down the whole process. And you probably wouldn't want it any other way since a crash signal (like SIGSEGV, SIGBUS, SIGABRT) means that you lost control over the behavior of the process and anything could have happened to its memory.

So if you want to isolate things, spawning separate processes is definitely better. Of course, if someone can make your process crash it's pretty close to them owning your computer anyway. I sure hope that you don't intend to expose this to untrusted users.

like image 126
Art Avatar answered Sep 29 '22 10:09

Art