From owner-freebsd-questions Tue Nov 10 19:25:09 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id TAA29446 for freebsd-questions-outgoing; Tue, 10 Nov 1998 19:25:09 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA29418 for ; Tue, 10 Nov 1998 19:25:03 -0800 (PST) (envelope-from grog@freebie.lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.9.1/8.9.0) with ESMTP id NAA20861; Wed, 11 Nov 1998 13:54:26 +1030 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.9.1/8.9.0) id NAA20461; Wed, 11 Nov 1998 13:54:24 +1030 (CST) Message-ID: <19981111135424.E20374@freebie.lemis.com> Date: Wed, 11 Nov 1998 13:54:24 +1030 From: Greg Lehey To: Joe Gleason , freebsd-questions@FreeBSD.ORG Subject: Re: Finding the pid of a tcp connection References: <00aa01be0d1c$3d9d0aa0$fe90e8c6@bug.tasam.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1i In-Reply-To: <00aa01be0d1c$3d9d0aa0$fe90e8c6@bug.tasam.com>; from Joe Gleason on Tue, Nov 10, 1998 at 09:37:31PM -0500 WWW-Home-Page: http://www.lemis.com/~grog Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tuesday, 10 November 1998 at 21:37:31 -0500, Joe Gleason wrote: > How do I find the process that is doing a connection that is > listed in netstat? > Idealy, I would like to write a little shell script that will > give me the pid if I give it the local port. No need. Use lsof (in the ports collection). Here are some examples my current netstat: Active Internet connections Proto Recv-Q Send-Q Local Address Foreign Address (state) tcp 0 0 freebie.http port7-22.gettysb.1084 FIN_WAIT_2 tcp 0 0 freebie.http port7-22.gettysb.1083 FIN_WAIT_2 tcp 0 0 freebie.http port7-22.gettysb.1082 FIN_WAIT_2 tcp 0 0 freebie.945 h24-64-143-236.m.22 ESTABLISHED tcp 0 0 freebie.946 h24-64-143-218.m.22 ESTABLISHED tcp 0 0 freebie.6000 allegro.2596 ESTABLISHED tcp 0 0 freebie.3027 websitegarage.co.http CLOSE_WAIT tcp 0 0 freebie.2082 ctp.netradio.net.http CLOSE_WAIT tcp 0 0 freebie.2052 205.166.76.101.http CLOSE_WAIT tcp 0 0 freebie.6000 razzia.1024 ESTABLISHED tcp 0 0 freebie.1016 razzia.1021 ESTABLISHED tcp 0 0 freebie.1017 razzia.cmd FIN_WAIT_2 tcp 0 0 freebie.1047 yana.6000 ESTABLISHED tcp 0 0 freebie.1018 yana.1020 ESTABLISHED tcp 0 0 freebie.cmd yana.1021 CLOSE_WAIT tcp 0 0 freebie.6000 allegro.1141 ESTABLISHED tcp 0 0 freebie.1019 allegro.1021 ESTABLISHED tcp 0 0 freebie.1020 allegro.cmd FIN_WAIT_2 tcp 0 0 freebie.1021 freefall.FreeBSD.22 ESTABLISHED tcp 0 0 localhost.10000 localhost.1027 ESTABLISHED tcp 0 0 localhost.1027 localhost.10000 ESTABLISHED tcp 0 0 freebie.domain *.* LISTEN tcp 0 0 localhost.domain *.* LISTEN tcp 0 0 freebie.domain *.* LISTEN udp 0 0 freebie.domain *.* udp 0 0 localhost.ntp *.* udp 0 0 freebie.ntp *.* udp 0 0 localhost.domain *.* udp 0 0 freebie.domain *.* # lsof -i tcp:http COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 266 root 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) netscape 717 yana 28u inet 0xf8a59f00 0t0 TCP freebie.lemis.com:2052->205.166.76.101:http (CLOSE_WAIT) netscape 717 yana 30u inet 0xf8a58ba0 0t0 TCP freebie.lemis.com:3027->websitegarage.com:http (CLOSE_WAIT) netscape 717 yana 33u inet 0xf8a593c0 0t0 TCP freebie.lemis.com:2082->ctp.netradio.net:http (CLOSE_WAIT) httpd 17003 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 17694 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20193 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20195 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20196 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20197 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20198 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20203 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20204 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) httpd 20398 nobody 15u inet 0xf8a54180 0t0 TCP *:http (LISTEN) You have new mail in /var/mail/grog # lsof -i udp:domain COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME named 125 root 20u inet 0xf89bcea0 0t0 UDP freebie.lemis.com:domain named 125 root 22u inet 0xf89bce40 0t0 UDP localhost.lemis.com:domain named 125 root 24u inet 0xf89bc960 0t0 UDP freebie.lemis.com:domain Greg -- See complete headers for address, home page and phone numbers finger grog@lemis.com for PGP public key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message