Association b/w sockets & processes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Association b/w sockets & processes
# 1  
Old 08-06-2003
Data Association b/w sockets & processes

Hi,

Is there any way i can know the association between sockets and the processes which created them.

Smilie
# 2  
Old 08-06-2003
You can look at the man page for netstat and then get the program lsof. These together should be able to give you what you are looking for.

See this thread for more info.
# 3  
Old 08-06-2003
Where i can get the lsof utility. I want it to use for HP-UX 11 machine. I found one lsof utility in HP-UX10.2 machine,copied to HP-UX 11. It gives a warning that lsof was compiled for HP-UX 10.2

then it gives an error,can't read namelist frm /stand/vmunix

Can I get the source code for this utility?? Smilie
# 4  
Old 08-06-2003
Example of lsof use:

If you also use solaris, you can get the package from:

http://www.sunfreeware.com/

Example of use lsof:

You can schedulle the data collection in your crontab:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/scripts/reports/lsof_TCP.sh 1>/dev/null
Code:
### Begin of  lsof_TCP.sh

#!/bin/ksh
wdate=`date +"%Y%m%d"`
whour=`date +"%H:%M"`
HDIR=/usr/local/scripts/reports

detailed_lsof="/var/reports/"$wdate"/"$wdate"_detailed_lsof.txt"
brief_lsof="/var/reports/"$wdate"/"$wdate"_brief_lsof.txt"

if [ ! -d /var/reports ]
then
   mkdir /var/reports
fi

if [ ! -d /var/reports/$wdate ]
then
   mkdir /var/reports/$wdate
fi

if [ ! -f $brief_lsof ]
then
    echo "Hour , TCP_State , connections_number " >> $brief_lsof
fi

if [ ! -f $detailed_lsof ]
then
    echo "HOUR, COMMAND, PID, CONN_SRC, PORT_SRC, CONN_DST, CONN_PORT  , STATE"
>> $detailed_lsof
fi

/usr/local/bin/lsof -i TCP |grep -v "COMMAND" |nawk -v wfecha="$wdate" -v whora=
"$whour" -f  $HDIR/lsof_TCP.nawk

### End of  lsof_TCP.sh

Code:
## Begin of lsof_TCP.nawk

detailed_lsof="/var/reports/"wfecha"/"wfecha"_detailed_lsof.txt"
brief_lsof="/var/reports/"wfecha"/"wfecha"_brief_lsof.txt"
( $10 !~ "LISTEN"  && $10 !~ "IDLE" ) {
split($9,conn, "->")
split( conn[1], conn_src ,":" )
split( conn[2], conn_dst ,":" )
conn_state[$10]++
print whora", " $1", " $2", "conn_src[1]" , " conn_src[2]", " conn_dst[1]", " conn_dst[2]", " substr($1
0,2,length($10)-2) >> detailed_lsof
}END {
for (cstate in conn_state) {print whora", " substr(cstate, 2,length(cstate)-2 ) ", ",conn_state[cstate] >> brief_lsof }
}

## End of lsof_TCP.nawk

Ouput example:

::::::::::::::
20030806_brief_lsof.txt
::::::::::::::
20:10, ESTABLISHED, 372
20:10, CLOSE_WAIT, 392
20:10, BOUND, 9

::::::::::::::
20030630_detailed_lsof.txt
::::::::::::::
20:10, Xvnc, 646, localhost , 6001, localhost, 42235, CLOSE_WAIT
20:10, Xvnc, 646, localhost , 6001, localhost, 34575, CLOSE_WAIT
20:10, Xvnc, 646, localhost , 6001, localhost, 46259, CLOSE_WAIT
20:10, Xvnc, 646, localhost , 6001, localhost, 39321, ESTABLISHED
20:10, opmn, 12127, www.adomain.com , 36657, www.adomain.com, 80, ESTABLISHED
20:10, opmn, 12127, www.adomain.com , 6202, www.adomain.com, 33587, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39089, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39165, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39244, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39237, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39243, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39249, ESTABLISHED
20:10, opmn, 12127, localhost , 6102, localhost, 39250, ESTABLISHED
20:10, opmn, 12144, localhost , 6100, localhost, 39094, ESTABLISHED
20:10, opmn, 12144, www.adomain.com , 36415, www.adomain.com, 7777, ESTABLISHED
20:10, opmn, 12144, www.adomain.com , 33587, www.adomain.com, 6202, ESTABLISHED
20:10, opmn, 12144, localhost , 6100, localhost, 39113, ESTABLISHED
20:10, opmn, 12144, localhost , 6100, localhost, 39140, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 39286, www.adomain.com, 3004, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 41840, www.adomain.com, 3002, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 41841, www.adomain.com, 3003, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 41842, www.adomain.com, 3005, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 41843, www.adomain.com, 3004, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 41845, www.adomain.com, 3000, ESTABLISHED
20:10, httpd, 14022, www.adomain.com , 46546, www.adomain.com, 3002, ESTABLISHED
20:10, oracle, 18140, www.adomain.com , 1521, www.adomain.com, 48801, ESTABLISHED
20:10, oracle, 18142, www.adomain.com , 1521, www.adomain.com, 48802, ESTABLISHED
20:10, httpd, 23814, www.adomain.com , 64650, www.adomain.com, 3001, ESTABLISHED
20:10, oracle, 23877, www.adomain.com , 1521, www.adomain.com, 60788, ESTABLISHED
20:10, oracle, 23879, www.adomain.com , 1521, www.adomain.com, 60789, ESTABLISHED
20:10, oracle, 23881, www.adomain.com , 1521, www.adomain.com, 60790, ESTABLISHED
20:10, httpd, 23888, www.adomain.com , 35680, www.adomain.com, 3001, ESTABLISHED
20:10, oracle, 24072, www.adomain.com , 1521, www.adomain.com, 61219, ESTABLISHED
20:10, dis51ws, 24073, localhost , 61225, localhost, 39271, ESTABLISHED
20:10, dis51ws, 24073, www.adomain.com , 61224, www.adomain.com, 61226, ESTABLISHED
20:10, dis51ws, 24073, www.adomain.com , 33335, aserver7.so.ded.ba1, 1521, ESTABLISHED

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 12:12 PM..
# 5  
Old 08-06-2003
Purdue has it under B.11.11 in binary only

And Asknet also has it (source and binary) or hpux.connect.org.uk which seems to be a different version of lsof but at the same site.

Quick search on the 'Net will find you more that you can decide if you want it from there.
# 6  
Old 08-06-2003
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What is the use of "finger" command & how to use it to kill the online processes ?

Hi there, I am eager to know what exactly is the use of "finger" command & how to use it to kill the online processes ? :b: (1 Reply)
Discussion started by: abhijitpaul0212
1 Replies

2. UNIX for Dummies Questions & Answers

File association

Hi, I'm using unix solaris 2.8 with CDE and I would modify the file association in my desktop. I found the file /usr/dt/appconfig/types/C/datatypes.dt from this topic : File Extension association in CDE | Unix Linux Forums | UNIX for Dummies Questions & Answers but this file can only be... (3 Replies)
Discussion started by: Toug
3 Replies

3. Programming

Two player game, forking & sockets

Hi. I am just making first steps in Linux POSIX programming. I have read some tutorials on processes, signals and sockets (thanks Beej!), so some basic knowledge I have already got. I want to write some very basic game server. My idea is to have main process, which is waiting for new players. If... (7 Replies)
Discussion started by: Shang
7 Replies

4. Shell Programming and Scripting

how to use the filehandle stored in a variable without knowing its file association

how to use the filehandle stored in a variable without knowing its file association i.e. the filename code my $logFH = $connObj->get('logFH'); infoPrint("Variable is of type IO \n") if(UNIVERSAL::isa($logFH, 'IO')); infoPrint("$logFH\n"); output == INFO :: Variable is of type... (0 Replies)
Discussion started by: rrd1986
0 Replies

5. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

6. HP-UX

fd passing between Independent processes using unix domain sockets

Hi, I am having some error handling issues with and fd passed between Independent processes using unix domain sockets (On HPUX). Here is the scnerio ================= Step 1: TPC/Client (connect()) ---Connects to ------TCP/Server(Gateway) (server gets fd) Step 2: ... (2 Replies)
Discussion started by: Debasisb2002
2 Replies

7. UNIX for Dummies Questions & Answers

File Extension association in CDE

Hi, Any idea how to define the file extension association within CDE. I need to tell dtfile (the file manager) to open *.log files as text documents and not emails... Thanks! (2 Replies)
Discussion started by: me2unix
2 Replies
Login or Register to Ask a Question