Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > checking that process binds a port, fuser functionality

Reply
Thread Tools

checking that process binds a port, fuser functionality

 
 
Zdenek Maxa
Guest
Posts: n/a
 
      08-02-2010
Hello,

I need to start a process (using subprocess.Popen()) and wait until the
new process either fails or successfully binds a specified port. The
fuser command seems to be indented exactly for this purpose. Could
anyone please provided a hint to a handy Python library to do this or
would the advice be to parse fuser command output?

This needs to happen on Linux and Python 2.4.

Thanks a lot in advance.

Zdenek
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      08-03-2010
On Mon, 02 Aug 2010 23:27:37 +0200, Zdenek Maxa wrote:

> I need to start a process (using subprocess.Popen()) and wait until the
> new process either fails or successfully binds a specified port. The
> fuser command seems to be indented exactly for this purpose. Could
> anyone please provided a hint to a handy Python library to do this or
> would the advice be to parse fuser command output?
>
> This needs to happen on Linux and Python 2.4.


fuser (when applied to a TCP socket) scans /proc/net/tcp to obtain the
inode number, then scans /proc/[1-9]*/fd/* for a reference to the inode.
This requires sufficient privileges to enumerate the /proc/<pid>/fd
directories (i.e. if you aren't running as root, fuser will ignore any
processes which you don't own).

If you just need to wait until *something* is listening on that port, you
could try connect()ing to it. Alternatively, you can monitor /proc/net/tcp
until the relevant port appears.

If you know which process will be using the port, you can just scan the
/proc/<pid>/fd directory for that process, rather than checking all
processes. You still need to use /proc/net/tcp to obtain the inode number.

 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      08-03-2010
In article <(E-Mail Removed)>,
Nobody <(E-Mail Removed)> wrote:

> On Mon, 02 Aug 2010 23:27:37 +0200, Zdenek Maxa wrote:
>
> > I need to start a process (using subprocess.Popen()) and wait until the
> > new process either fails or successfully binds a specified port.

>
> If you just need to wait until *something* is listening on that port, you
> could try connect()ing to it.


This certainly seems like the logical way to me. It's straight-forward,
simple, and portable.
 
Reply With Quote
 
Zdenek Maxa
Guest
Posts: n/a
 
      08-03-2010
-------- Original Message --------
Subject: Re: checking that process binds a port, fuser functionality
From: Roy Smith <(E-Mail Removed)>
To: http://www.velocityreviews.com/forums/(E-Mail Removed)
Date: Tue Aug 03 2010 13:06:27 GMT+0200 (CEST)

> In article <(E-Mail Removed)>,
> Nobody <(E-Mail Removed)> wrote:
>
>> On Mon, 02 Aug 2010 23:27:37 +0200, Zdenek Maxa wrote:
>>
>>> I need to start a process (using subprocess.Popen()) and wait until the
>>> new process either fails or successfully binds a specified port.

>> If you just need to wait until *something* is listening on that port, you
>> could try connect()ing to it.

>
> This certainly seems like the logical way to me. It's straight-forward,
> simple, and portable.


Yes, but I need a check that certain known process's PID listens on a
defined port.
connect() would certainly work, but I may end up connecting to a
different process.
I forgot to mention that my master daemon starts processes in question
as external
applications, defines port they should bind but starts them via
different user via sudo,
which makes checking /proc/net/tcp not possible.
Well, seems it's turning out not straight-forward, but thanks a lot for
your thoughts anyway!

Zdenek
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      08-03-2010
On Aug 3, 10:32*am, Zdenek Maxa <(E-Mail Removed)> wrote:

> Yes, but I need a check that certain known process's PID listens on a
> defined port. connect() would certainly work, but I may end up
> connecting to a different process.


Then you need to define your protocol such that the client and server
engage in some sort of identification / authentication exchange when
they connect.

Client: Who are you?
Server: I am PID 12345
Client: That's not who I was expecting, I'm going away!

Depending on how secure you need this to be, the exchange might
include some kind of cryptographic signature.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Fuser for LaserJet 3600n wanted PeeCee NZ Computing 0 04-12-2010 10:41 AM
laserjet iii fuser replacement? trigon NZ Computing 8 05-24-2006 04:14 AM
Recover Fuser Roller.. CSE NZ Computing 4 05-24-2005 07:14 PM
filtering records a control binds to MattB ASP .Net 3 09-02-2004 09:20 PM



Advertisments