From owner-freebsd-hackers Wed Jun 19 2:43:18 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from south.nanolink.com (south.nanolink.com [217.75.134.10]) by hub.freebsd.org (Postfix) with SMTP id D50D037B403 for ; Wed, 19 Jun 2002 02:43:07 -0700 (PDT) Received: (qmail 76590 invoked by uid 85); 19 Jun 2002 09:54:09 -0000 Received: from unknown (HELO straylight.ringlet.net) (212.116.140.125) by south.nanolink.com with SMTP; 19 Jun 2002 09:54:06 -0000 Received: (qmail 27809 invoked by uid 1000); 19 Jun 2002 09:41:54 -0000 Date: Wed, 19 Jun 2002 12:41:53 +0300 From: Peter Pentchev To: Varshavchick Alexander Cc: hackers@FreeBSD.ORG Subject: Re: Getting pid of listening process Message-ID: <20020619094153.GE369@straylight.oblivion.bg> Mail-Followup-To: Varshavchick Alexander , hackers@FreeBSD.ORG References: <20020619084411.GD369@straylight.oblivion.bg> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NtwzykIc2mflq5ck" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.99i X-Virus-Scanned: by Nik's Monitoring Daemon (AMaViS perl-11d ) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --NtwzykIc2mflq5ck Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2002 at 12:52:54PM +0400, Varshavchick Alexander wrote: > On Wed, 19 Jun 2002, Peter Pentchev wrote: > > On Wed, Jun 19, 2002 at 12:40:30PM +0400, Varshavchick Alexander wrote: > > > On Wed, 19 Jun 2002, Peter Pentchev wrote: > > >=20 > > > > Date: Wed, 19 Jun 2002 11:02:33 +0300 > > > > From: Peter Pentchev > > > > To: Varshavchick Alexander > > > > Cc: hackers@FreeBSD.ORG > > > > Subject: Re: Getting pid of listening process > > > >=20 > > > > On Wed, Jun 19, 2002 at 11:01:19AM +0300, Peter Pentchev wrote: > > > > > On Wed, Jun 19, 2002 at 11:48:56AM +0400, Varshavchick Alexander = wrote: > > > > > > Hi gurus, > > > > > >=20 > > > > > > can anybody make a hint as how pid of a process listening on a = specified > > > > > > tcp port can be determined? Of cause there are major utilities = like lsof > > > > > > or sockstat but they gather a lot of extra information and work= not too > > > > > > fast. What I need ideally would be a small C program which outp= uts pid > > > > > > given a port number as a parameter, can anybody help? > > > > >=20 > > > > > Very few things could work faster than lsof(1) with appropriate > > > > > command-line options. I would suggest that you take the time to = read > > > > > the lsof manual page carefully, then try something like: > > > > >=20 > > > > > lsof -nPli 4tcp:25 > > > > >=20 > > > > > Of course, depending on your needs, you may want to drop the -P, = -l or > > > > > -n options. > > > >=20 > > > > Hit 'send' too fast; if you are only interested in pid's, take a lo= ok at > > > > the -t option, too :) > > >=20 > > > lsof seems to have problems on the server in question, it takes all c= pu > > > time and never returns for a long time... Installing the latest lsof > > > release didn't help :( > >=20 > > Have you actually tried the -n option? If it hangs with -n, try -b, > > too. > > Yes, it hangs in either cases, here is exactly how I try running it: > lsof -t -nbPli 4tcp:80 >=20 > If anybody could suggest what source code in lsof is dealing with tcp > ports it would save a lot of time browsing through all lsof sources... Could you try using ktrace or truss on it, to see just where it hangs? Running lsof under ktrace and then running kdump | tail might give a pretty good indication.. G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 If you think this sentence is confusing, then change one pig. --NtwzykIc2mflq5ck Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iD8DBQE9EFHh7Ri2jRYZRVMRAiIrAJ9m5D/YEGNo2W/w5qO2jMn/KeqX/gCfRGY/ I6TfsheNt7qZwYdxmTLqgpU= =cQ90 -----END PGP SIGNATURE----- --NtwzykIc2mflq5ck-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message