suppose there is a piece of code on the server side with two threads open, one to process the client connection and one to read the message sent by the client.
m_fd = socket(AF_INET, SOCK_STREAM, 0);
bind(...);
listen(...);
pid_t pid;
while (1)
{
m_client_fd = accept(m_server_fd, (sockaddr*)&client_addr, &len);
pid = fork();
if (pid == 0) //
{
close(m_fd); //
do_read_from_client(m_client_fd); // m_client_fd
close(m_client_fd); //
exit(EXIT_SUCCESS);
}
else
{
close(m_client_fd); //
}
}
/*************************************************/
close(m_fd); //
/****************************************************************/
how to turn off the file descriptor fd, correctly when it comes to multithreading?