- 论坛徽章:
- 0
|
below script will do the same thing as part of lsof, though I highly recommend lsof.\r\n\r\n#!/bin/ksh\r\n#\r\n# 7-30-2003\r\n# find from a port the pid that started the port\r\n#\r\nline=\'-------------------------------------------------------------------------\'\r\npids=`/usr/bin/ps -ef | sed 1d | awk \'{print $2}\'`\r\n\r\n# Prompt users or use 1st cmdline argument\r\nif [ $# -eq 0 ]; then\r\n read ans?\"Enter port you like to know pid for: \"\r\nelse\r\n ans=$1\r\nfi\r\n\r\n# Check all pids for this port, then list that process\r\nfor f in $pids\r\ndo\r\n /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q \"port: $ans\"\r\n if [ $? -eq 0 ] ; then\r\n echo \"$line\\nPort: $ans is being used by PID: \\c\"\r\n /usr/bin/ps -o pid -o args -p $f | sed 1d\r\n fi\r\ndone\r\nexit 0\n\n[ 本帖最后由 shyjack 于 2008-8-26 15:39 编辑 ] |
|