0

I have an embedded application, running as a single process on Linux.

I use sigaction() to catch problems, such as segmentation fault, etc.

The process has a few threads, all of which, like the app, should run forever.

My question is whether (and how) I should detect if one of the threads dies.

Would a seg fault in a thread be caught by the application’s sigaction() handler?

I was thinking of using pthread_cleanup_push/pop, but this page says “If any thread within a process calls exit, _Exit, or _exit, then the entire process terminates”, so I wonder if a thread dying would be caught at the process level …

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551

1 Answers1

1

It is not a must that you need to check whether the child thread is completed. If you have a need of doing something after the child thread completes its processing you can call thread_join() from the main thread, so that it will wait till the child threads completes execution and you can do the rest after this. If you are using thread_exit in the main thread it will get terminated once it is done, leaving the spawned threads to continue execution. The process will get killed only after all the threads completes execution.

If you want to check the status of the spawned threads you can use a flag to detect whether it is running or not. Check this link for more details

How do you query a pthread to see if it is still running?

Community
  • 1
  • 1
Twinkle
  • 514
  • 3
  • 8