星期三, 4月 12, 2017

How to find out all used ports for the specified process in Linux and AIX


1. For Linux:
    It's easy to use the following command:
    #netstat -tupln|grep pid_of_your_process

2. For AIX:
    You must combine several commands:
    #netstat -Aan|grep LISTEN|awk '{print $1}'|xargs -i rmsock {} tcpcb > a.txt
    #netstat -Aan|grep LISTEN|awk '{print $5"\t\t"}' > b.txt
    #paste b.txt a.txt > c.txt
    #grep pid_of_your_process c.txt

*** xargs -i can use the output of previous command to replace the {} as the argument of the next command.