Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've done some searching on this topic, and haven't found anything relevant that I could see. Hopefully someone here has an idea where I should be looking.

I'm wondering if there's a way to forcibly terminate another program's socket and/or "unbind" it from a particular TCP/IP port on Win32.

For example, it really looks like program X is occupying port 110 locally (even though I told it not to). I need program X to do other things, so I can't just terminate program X in it's entirety, and the makers of program X are of no help whatsoever on this issue.

I need another program to use port 110, but obviously it won't work if program X is still bound to that port and is blocking all other attempts to use it...

Is there a way to do this programmatically through Perl or via some other means (other than a sledgehammer :) )?

Thanks,

Glenn

  • Comment on forcibly closing sockets/unbinding ports - win32

Replies are listed 'Best First'.
Re: forcibly closing sockets/unbinding ports - win32
by McD (Chaplain) on Jun 08, 2003 at 21:08 UTC
    Win32 or otherwise, I don't think there's a way to force a process to relinquish a port it's listening on, short of terminating the process.

    However, you might be able to work around it. You could write a small app that binds to port 110 itself, then spawns/executes/otherwise launches program X, then relinquishes port 110.

    This depends on program X successfully going on it's merry way if it fails to bind to port 110, which may or may not be the case.

    Good luck.

    Peace,
    -McD
Re: forcibly closing sockets/unbinding ports - win32
by waswas-fng (Curate) on Jun 09, 2003 at 10:43 UTC
    Well to tell if it really that proccess that is binding, checkout http://www.foundstone.com/ they have a util called fport which is like a lsof for windows -- will tell you what proccess is bound to what port.

    -Waswas
Re: forcibly closing sockets/unbinding ports - win32
by true (Pilgrim) on Jun 09, 2003 at 07:28 UTC
    Sorry, i have no answer for you but another question. I've had similar probs with Win32. Especially when dealing with pre-existing Apache. I ended up finding the pid of the apache process (with ps.exe) and killing that process from perl. I had to know the name of the application though in order to kill it. Sounds like you do, so try to kill it. Which leads to a more direct question. Can you map a port owner's pid? Or...
    Is there a way to detect which process is binding the port you want?

    jtrue