QUESTION: How Do I determine the PID associated with a Socket

  • Permalink
  • submit to reddit
  • Email
  • Follow


Is there a way to determine the PID associated with a socket ?

I have examined the /etc/services file and grepped thru the /etc/init.d
dir for the Port in use w/o success.

Thanks in  advance for any assistance in this matter.

0
Reply mark.m.lloyd (2) 10/20/2005 3:48:48 PM

See related articles to this posting


mark.m.lloyd@ae.ge.com wrote:
> Is there a way to determine the PID associated with a socket ?


"lsof" should help you

ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/

blastwave.org has solaris binaries of lsof.

Rob

-- 
Rap it up for the common good
Let us enlist the neighbourhood
It's OK, I've overstood
This is a wordy rappinghood. OK, bye.

                   Tomtomclub, 1980.
0
Reply Rob 10/20/2005 4:21:05 PM

mark.m.lloyd@ae.ge.com wrote:
> Is there a way to determine the PID associated with a socket ?

Or using native commands without using lsof is to use pfiles.

cd /proc
pfiles * > /tmp/pfiles.out

search through pfiles.out for the process that has the socket open you 
are interested in. i.e. there will be entries such as:

3771:   /export/home/archiver/bin/myprocess
   Current rlimit: 256 file descriptors
    0: S_IFCHR mode:0666 dev:85,0 ino:191320 uid:0 gid:3 rdev:13,2
       O_RDONLY|O_LARGEFILE
    1: S_IFCHR mode:0666 dev:85,0 ino:191397 uid:0 gid:0 rdev:24,2
       O_RDWR|O_LARGEFILE
    2: S_IFREG mode:0644 dev:85,5 ino:17 uid:104 gid:1 size:139436
       O_WRONLY|O_LARGEFILE
    3: S_IFDOOR mode:0444 dev:293,0 ino:58 uid:0 gid:0 size:0
       O_RDONLY|O_LARGEFILE FD_CLOEXEC  door to nscd[200]
    4: S_IFSOCK mode:0666 dev:287,0 ino:19574 uid:0 gid:0 size:0
       O_RDWR
         sockname: AF_INET 10.1.1.1  port: 9001
         peername: AF_INET 10.1.1.2  port: 9001

pid 3771 has port 9001 open locally.

--
Michael
0
Reply Michael 10/20/2005 9:06:02 PM

Michael's pfiles suggestion is probably the best way of doing this.
We're thinking about better ways; it's tricky, since
a single open socket can be shared amongst many processes.
You can also use DTrace to do this on Solaris 10 if the problem is
repeatable, but it's not trivial.

- Bart

0
Reply barts 10/21/2005 6:09:43 AM
comp.unix.solaris 25797 articles. 88 followers. Post

3 Replies
736 Views

Similar Articles

[PageSpeed] 3


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

[VxW] Question : How to close the Socket descriptor associated with a Port ?
=20 Hai, =20 I have a problem with the Socket closure. When the application crashes then it fails to close the sock fd and so the port is in use and so when I launch the application next time it fails saying that the Port is already in use. What can I do to close the socket binded to a port which I know the port number ? Please help me by sending ur valuable comments. =20 Hoping to get a lot of suggestions.. =20 =20 =20 Regards, A beginner in VxWorks Programming=20 =20 =20 Ganesh Namboothiri ganesh.vasudevan@wipro.com <mailto:ganesh.vasudevan@wipro.com>=20 Tel Off...

Associating client PIDs with backend PIDs
All, This is a pretty obvious question, but I can't find an answer in the standard docs/archive: if I have an installation in which there are a number of long-running client processes interacting (one-on-one) with backend processes, how do I find the associations? I can see the client PIDs in an appropriate 'ps' (grepping on the client program name, for example), and the backend PIDs in the standard queries or pgmonitor. But I can't tell which goes with which (except by trying to infer the association by looking at the query that's running -- assuming I can catch it...

Associating client PIDs with backend PIDs
All, This is a pretty obvious question, but I can't find an answer in the standard docs/archive: if I have an installation in which there are a number of long-running client processes interacting (one-on-one) with backend processes, how do I find the associations? I can see the client PIDs in an appropriate 'ps' (grepping on the client program name, for example), and the backend PIDs in the standard queries or pgmonitor. But I can't tell which goes with which (except by trying to infer the association by looking at the query that's running -- assuming I can catch it...

Re: Associating client PIDs with backend PIDs
I use a separate command like lsof to map processes to tcp/unix ports on the client and server machines. --- On Mon 11/24, Rich Cullingford < rculling@sysd.com > wrote: From: Rich Cullingford [mailto: rculling@sysd.com] To: pgsql-admin@postgresql.org Date: Mon, 24 Nov 2003 11:55:07 -0500 Subject: [ADMIN] Associating client PIDs with backend PIDs All,<br>This is a pretty obvious question, but I can't find an answer in the <br>standard docs/archive: if I have an installation in which there are a <br>number of long-running client processes interacting (one-on-one...

Question about Streams and UDP sockets using GNAT.Sockets
Hi. I'm using GNAT GPL 2006 (20060522-34) on Windows XP. I'm trying to broadcast an UDP packet, with the following test code: ---------------------------------------------------------------------- with GNAT.Sockets; use GNAT.Sockets; procedure Test is Local_Port : constant Port_Type := 20769; Remote_Port : constant Port_Type := 20770; Address : Sock_Addr_Type; Socket : Socket_Type; Channel : Stream_Access; Local_Host : String := "127.0.0.1"; begin Initialize; Create_Socket (Socket, Family_Inet, Socket_Datagram); Set_Socket_Option (Sock...

Sockets question
Hi, One of the exercises in front of me is: "Write a server in perl that will send the client a sleepy string of "ZZZZZZZZZ" whenever it connects using port 54321 from the same host using a socket in the UNIX domain." Can someone possibly re-phrase the question? I have no idea about sockets - just found a chapter on it in Prog. Perl but have not read it yet :(. Any links out there I can get ideas/learn from? Thanks in advance. John wrote: > > One of the exercises in front of me is: > "Write a server in perl that will send the client a sleepy string of &...

sockets question
Hi all, we have a project where we'd like to interface with a C++ program, possibly residing on another machine. Sockets seem to be the best method to do this. The project requires 10's of kilobytes of information to be passed in both directions. Mostly this is numerical data (int / floating point) with some strings, and some larger arrays of numerical data. Speed is not critical. Security is of little importance (we won't need encryption). Ease of programming (quick ramp up) is very important. Would you have any recommendations as to: 1) a good sockets library. Preferabl...

Some questions about sockets
Hi all, I am practicing socket programming in Ruby, and I have some questions. Hopefully someone here might be able to clarify them for me: 1. Must a connection always be from a TCPServer to a TCPSocket? Can there be a TCPSocket - TCPSocket connection? 2. What are the possible values to the second argument of TCPSocket#send? The Ruby Book included with the one click installer says the possible values can be found in page 478, but it's a little hard to find page 478 inside a .chm file! 3. Must the first argument to TCPSocket#send always end with "\n" for TCPSe...

Socket question..
I've have been using the following test for a socket connection breaking in a tcl client if {[eof $sock] || [catch { gets $sock line}]} { .. .. .. I've tested this by killing the server. The expression is evaluated true, a procedure is called and the client goes into a wait mode and waits for the socket to be come available again. Last night the host on which the server runs croaked, but this time the above expression didn't evaluate to true, or it was never evaluated in the first place. I have a statement: fileevent $s readable [list tcp_client read $s] THe test above is the...

Sockets Question
If I succesfully create a Socket as follows: Socket sock = new Socket("192.168.1.55", 1000); Then, go to send data, and listen in on it as follows: BufferedWriter os = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); BufferedReader is = new BufferedReader(new InputStreamReader(sock.getInputStream())); try{ os.write("D0"); os.flush(); returnedString =is.readLine(); System.out.println(returnedString); }...

Socket question
When sending data over a socket and closing the socket right after send(MySocket,"Something",9,0); closesocket(MySocket); will the receiving end always receive the data, before detecting SOCKET_ERROR? while(MySocket != SOCKET_ERROR) { char buffer[1001]; long rc = recv(MySocket,buffer,1000,0); // process buffer } // exit or could it happen that the program exits before processing the data? Mark wrote: > When sending data over a socket and closing the socket right after > > send(MySocket,"Something",9,0); > closesocket(MySocket); > ...

Question about socket
Dear all, I have a question about socket. My OS is Solaris2.6. My concern is: is there a MAX socket(TCP) connnection limitation on every process? Or is there a MAX socket(TCP) connnection limitation on the whole system or the current user? I check getrlimit function, but there is no "MAX socket connection number limitaion" entry. Would you please give me some advice? Thanks! Cheers, Jennifer In article <bhsq7t$2mr$1@zcars0v6.ca.nortel.com>, Jennifer <kittyliu2002@sina.com> wrote: >I have a question about socket. My OS is Solaris2.6. > >My concern is: is...

Socket Question
I am in the process of teaching myself socket programming. I am "playing around" with some simple echo server-client programs for m the book TCP/IP Sockets in C. The Server program is: #include "TCPEchoServer.h" /* TCP echo server includes */ #include <pthread.h> /* for POSIX threads */ void *ThreadMain(void *arg); /* Main program of a thread */ /* Structure of arguments to pass to client thread */ struct ThreadArgs { int clntSock; /* Socket descriptor for client */ }; int main(int argc, char *argv[]) { int servSock...

Socket question
Hi I'm running a server a computer and i'm trying to connect to the that server from the computer. How can I use sockets to do this. I can connect to the server from the same computer its running from with this line of code Socker ss = new Socket("localhost", 8000) but can't figure out how to connect from a different computer in my house. Any help is apprecaited. Thank You PLEASE DISREGARD I FOUND THE PROBLEM!!!!!! "Jova" <jova@nospam.net> wrote in message news:kz%Vg.292$QW5.196@newsfe09.lga... > Hi I'm running a server a computer and...

sockets question
1. When reading from a socket, how does socket timeout work? Will an fgets wait for timeout length per attempt, or timeout is the time allowed for repeated fgets attempts, such as in a loop? 2. Does timeout have an effect if a socket is set to nonblocking, or does it apply to blocking sockets only? mydejamail@yahoo.co.uk wrote: > 1. When reading from a socket, how does socket timeout work? > Will an fgets wait for timeout length per attempt, or timeout is the > time allowed for repeated fgets attempts, such as in a loop? > Per attempt > 2. Does timeout have an effect if a ...

associativity question
Associativity in C takes two forms: left to right and right to left. I think the K&R book lacks something... For example, *p++, since the associativity is from right to left, do this expression means *(p++)? I think I am wrong. (so, associativity is not for operand?) But for *++p, right to left associativity means *(++p) is correct. So by definition of associativity, I guess it only applys on grouped operators but not on operand. Right? A more complicated example will be char* const *(*next++)() fdmfdmfdm@gmail.com said: > Associativity in C takes two forms: left to right and righ...

Socket question
When creating a socket with new Socket(host, port) the connection is made as part of the object creation process. If the remote host sends an initial login text, where does this go? I cannot seem to retrieve this text, as I create BufferedReader from the InputStream later? "GaryM" <garymcm@yahoo.com> wrote in message news:Xns9425708BF6E20R3344324357788499939@216.168.3.44... > When creating a socket with new Socket(host, port) the connection is > made as part of the object creation process. If the remote host sends > an initial login text, where does this go? I can...

Question about sockets
Hello, I have the following segment of code in a program: in = new BufferedReader(new InputStreamReader( mailSocket.getInputStream())); ,in which a mailSocket is an object of Socket class. Later on, i am using this expression: while ((serverOutput = in.readLine()) != null) System.out.println(serverOutput); /*other stuff here*/ ,wanting to print all the lines available on my end of the Socket at the time being. This readLine() method is blocking, thus preventing the program from getting on to the other stuff. How can i avoid this? Thank...

Socket question
Hi, If two clients contact a server, a fileevent is started on each one, then is it possible that both sockets become readable at the same time. If that happens then what is the sequence of functions based on the events being called. e.g. socket1 fileevent calls --> proc1 socket2 fileevent calls --> proc2 if both sockets become readable at the same time, does tcl fork and execute both in parallel, or it executes one after the other, like proc1 after proc2. Is tcl capable of parallel execution in this context. Or tcl does not even see them at the same time. Pandey shardendu@ten...

sockets question
hi; i have the following piece of code: ============= s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.bind(("",port)) s.sendto(data,(MY_GW,port)) data = s.recvfrom(1024) ============ data contains some instructions which i am sending to MY_GW. If the reply arrives from the MY_GW quickly then things fine, otherwise the program is going to freeze waiting for the reply. I want to do the following: 1- Be able to impose a timeout after which i want to stop executing the s.recvfrom statement. rgds; m.smadi On Sat, 26 Feb 2005 00:35:57 -0500, Mohammed Smadi wrote: >...

SOCKET QUESTIONS
when I run a program I everything works correctly. when i run a seperate session and run another instance of the program I get error 29 Descriptor socket is not valid if i open multiple sessions after that i get the same error as above. I am under the impression that socket can handle multiple connections system: unidata on Ibm aix On Apr 27, 12:22 am, MVGuru <aivaz...@cinci.rr.com> wrote: > when I run a program I everything works correctly. > when i run a seperate session and run another instance of the program > I get error 29 Descriptor socket is not valid...

Questions about sockets
Hello, I have two quick questions... 1) I have a socket server application which runs fine.. The problem I observe is that after I have created a few connections and exit the application, the next time I run I am unable to get the socket I opened before. I have to wait up to 2 minutes until the application can get the socket. I have a work-around which will keep retrying the socket until it is obtained.... But why is this happening? I notice it more under Linux than under Windows {I am developing on both platforms} 2) How can I get the IP address of a socket... I have code which...

Socket question
Hi, If I catch wxSOCKET_CONNECTION events from a wxSocketServer, should I call Accept( true ) or Accept( false )? Does it matter? I've been using Accept( true ), because I assumed that since Im responding to the connection event it wont have to wait - but I noticed that when I get new connections it blocks the gui for a few seconds. Thanks... Will McGugan --------------------------------------------------------------------- Please read http://www.wxwindows.org/mlhowto.htm before posting. To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwindows.org For addit...

Questions with sockets
1. Is there any obvious time difference between sending a packet of about 100 bytes in one 'send' call, and breaking this 100 byte packet into two and calling 'send' two time in a row? Is the Nagle/delayed ACK affecting here since the said 'send' is called continuously on the server side, which could be interrupted by 'recv' calls? 2. To make a server very responsive, what's lowest delay range could a server achieve? (Just some numbers for comparison since we know some factors affecting here, e.g. hardware) 3. How threading in a server could af...