Ok , so I have a question. I wrote some programs for some assignments where I have a server and a client/clients and they interact. One was a bulletin board system (very basic and primitive of course) the other a mail server-client and the other a chat...
I completed them but there is one thing bugging me; In all these the server goes into an endless loop where he accepts connections and creates new threads or processes that complete tasks. So my question is this: After the endless for loop I have some statements that detach shared memory from processes and delete it or destroys thread attributes and mutexes. But how do I get these commands to execute. I mean the only way to terminate the server is by ctrl-c. But when I press that doesnt the whole program closes at that point? I thought about doing it like normal programs - using a variable - and when catching the signal of ctrl-c after asking the user whether to exit the server or resume setting the variable so I can break from the for-loop i.ebut I want to end it instantly. With this way the program will most definitely accept another connection and THEN terminate because after a connection is accepted it will loop back and block at the accept statement waiting for an incoming connection.. So any ideas? [This is strictly curiosity from my part I dont need it right now for anything]Code:for (;;) { ... if (c) break; ... }
My code in the above always looks something like this
orCode:int main() { ... ... ... for (;;) { sd = accept(...); ... if (!fork()) { child process here } parent here }//I am talking about the following statements sem_unlink(...); shmctl(...); }
So m this is it.Code:int main() { ... ... ... for (;;) { sd = accept(...); ... pthread_create(...); }//I am talking about the following statements pthread_attr_destroy(...); pthread_mutex_destroy(...); }



LinkBack URL
About LinkBacks



