Sharing

2012年4月10日 星期二

Find out files and processes


http://www.cyberciti.biz/faq/howto-linux-get-list-of-open-files/

List Open Files For Process

ls -l /proc//fd

lsof 似乎會更多一些, 包含了 loading 到 memory 中的 library
lsof -p 


What port is in use by which program
lsof -iTCP:80

http://www.cyberciti.biz/faq/what-process-has-open-linux-port/

  • netstat - a command-line tool that displays network connections, routing tables, and a number of network interface statistics.
  • fuser - a command line tool to identify processes using files or sockets.
  • lsof - a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.
  • /proc/$pid/ file system - Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.


netstat -tulpn
fuser 7000/tcp

lsof -i :portNumber
lsof -i tcp:portNumber
lsof -i udp:portNumber
lsof -i :80
lsof -i :80 | grep LISTEN

List File Descriptors in Kernel Memory

sysctl fs.file-nr
sysctl fs.file-max

More about /proc/PID/file & procfs File System

/proc/PID/cmdline : process arguments
/proc/PID/cwd : process current working directory (symlink)
/proc/PID/exe : path to actual process executable file (symlink)
/proc/PID/environ : environment used by process
/proc/PID/root : the root path as seen by the process. For most processes this will be a link to / unless the process is running in a chroot jail.
/proc/PID/status : basic information about a process including its run state and memory usage.
/proc/PID/task : hard links to any tasks that have been started by this (the parent) process.

http://www.cyberciti.biz/faq/find-out-which-service-listening-specific-port/

沒有留言: