I am making a C++ wxWidgets application, my desktop program is an interface for an LLM chat external command-line application, called Ollama.

Ollama is a lightweight, extensible framework for building and running language models on the local machine. It provides a simple API for creating, running, and managing models, as well as a library of pre-built models that can be easily used in a variety of applications.

It works like this, 
1. First, we run in one terminal: "ollama serve", which in that terminal starts a server that listen all the commands and works as a webserver inside localhost, and the only way to turn it off is by killing the process.
2. Second, in another terminal, we can use "ollama run MODEL_NAME", to start a chat with said model, communicating with the server using HTTP and JSON.

Now, I am in the part of the starting the server, so calling this command-line application with "serve" so I can start the server inside my wxWidget application. So far, I manage to made much of the code and got up to the point of finishing my entire GUI and even start and stop server buttons, actually deal with the external process.

But then something happened when dealing with this external process, I tried several things and I couldn't manage to get it to work. I get to the point I could call the "ollama serve" process and start it up, but when killing the process is when things went south, whether it was because a Segmentation fault, or my interface gets frozen, or even killing my main process.

Here is what I tried and what was the problem I encounter:
1. I tried calling the external process inside my main process which lead to making my own process or interface hang or freeze, since "ollama serve" doesn't end as a normal process but stays listening until killed. 
2. Then I moved to using threads and call the server in another thread but this gave me several errors too.
2.a Using wxThread: This was my first approach, and couldn't finish since I had many compilation errors and also, the wxWidgets documentation recommends using C++11 standard library threads, so I ended up switching the method, maybe this could be an alternative if I could put the time to fix the errors.
2.b Using standard threads: Then I moved to standard threads, this is the option I am dealing with now, but didn't work at first, so I had to make two more alternatives here.
2.b.a First I tried, moving all the thread code to its own process, but then I couldn't make it to work at all because wxExecute only works in the main process.
2.b.b Then, the alternative I am now, I made an extra class, called ProcessThread, which uses mutex, and other things to deal with it, but instead of moving everything to it's own process, I create the thread process inside my own process, and then I moved the logic like pointers and other variables to the ProcessThread and I reached to the part of running the server, and I could check it is really working in the Task Manager, but at the moment of killing this thread, I couldn't and I tried several ways to kill it in different parts. I don't know how to fix this, if I run the program normally, it kills my father process or sometimes don't even kill and leaves the children process alive even after closing my application, if I debug it my debugging shows it works correctly but then it goes into a frenzy of internal calls that ends up in an error, If I run the program from the terminal, it returns a Segmentation fault error.

Do you understand this? So I can paste my code and we can go from there how to solve my errors?