How can I solve this problem?

I'm now designing a server application which can serve large number of clients' request. I've a question to ask, that is, main process will block when invoke the "accept" function, if a client request comes, main process should be separated into 2 processes by invoking "fork" function, the parent goes on with accept function, the child to serve the connected client's request. My question is, if there are large number of clients want to get connected with the server, the server application should be forked many times, is this harmful to our server resources?

In case a thread library is available on your system, you may wish to use it instead of fork()ing because process switching is a more resource intensive than that of threads.

I've got your answer and now I want to make the confirmation. You mean that I should use thread instead of process to deal with clients' request, is that right?

Correct. But be sure to use POSIX threads (Pthreads)

There are plenty of examples available on the Web
showing how to use POSIX pthreads to listen for
and handle incoming connections.

  • Finnbarr

Roger that.
If you have interest in Threading process, we can discuss the ThreadPool architecture. You can contact me via email. My address is acqy@163.com, by the way, I'm also a novice.