Processes in linux(Fork())

Asked

Viewed 114 times

0

I am creating a client/server type server using sockets tcp, a client connects to the server, when it closes the client application, the server closes the connection command close (related), but the process on the server that opened that port is still connected to that port, even after close.

How can I close this door without killing the process?

Obs: I tried to create a child process and from there close the door using fuser -k porta/tcp, but with this command it kills any process that is connected to the port it received Kill for Fuser, so he kills the father and the son and the program ends(Dead).

If use thread and give pthread_exit in thread that opened the connection socket at that door, the program also closes(Dead).

Someone’s got a clue what to do?

  • Take this example: https://stackoverflow.com/questions/13669474/multiclient-server-using-fork

  • Thank you Pleo contact Isalamon. In fact, in my code so far I can support many clients through an array of sockets, the problem is that if the client closes its application and enters again, as the port is blocked it will not be able to connect, which will force me to repeat the server, and that’s what I want to get around, as soon as a client closes his connection, the server kills the process that was using that port and opens again!

  • Isalamon, in the example you gave me, does anyone comment that " Can and / or should the child also process the closure? I ask because I’m running into the problem where I have a child process running on a loop and then kills the father and try to restart it, however, can’t link the socket since the child process still has the server socket linked"and that my problem, as the socket is tied to the son and the father, both die, as I do this disconnection without anyone needing to die, or just one?

  • Look at this other example, at the end there is a full server file using Fork: http://www.cs.rpi.edu/~Moorthy/Courses/os98/Pgms/socket.html

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.