Last semester, I took Computer Networking and did some Linux C-programming (using gcc) for my projects. One very tedious thing that I came across was that if my program crashed or died out (I would then have to press Ctrl + C to kill it), the network port would still remain open for a minute or so. Therefore, if I want to run the program again, I will have to first go to the header file, change the port, redo the program and then run it. Obviously, this is very tiring very fast.
Is there a way to configure it when the port is immediately freed as soon as the process is killed? Either through some tweaking in linux, or in the makefile for my program, or even programmatically in C?
Edit: I mean when writing a server and choosing a specific port for hosting the program.
source share