I'm a writing a small webserver for personal use in c (not c++). I want to allow user input in the console like "shutdown server" or "restart server".
In order to allow this kind of input the server is running in a seperate thread (pthreads), so the console isn't blocked.
I also want this thread to print output in the console like "a new client connected" or "client requestet 'home.html'".
The problem is: If I'm typing something like "shutdown server" and at the same time the thread prints something like "a new client connected" everthing mixes up and I get something like "shuta new client connectedown server"
Is there an elegant way to print the output of the thread and at the same time allow the user to enter commands without both interfering?
Or is this a stupid idea to begin with? If yes: Is there a standard way to handle things like that (i.e. to control server).