Linux命令使用大杂侩

Published: 2015-08-20

Tags: linux

本文总阅读量
  1. 进程/网络乱乱弹
  2. 磁盘的魔法空间
  3. 网络的时空隧道

1. 进程/网络乱乱弹

(1)查看进程间的父子关系
ps auxfww

部分输出:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
sincere+  2933  0.0  0.9 989200 73412 tty2     Sl+  08:55   0:09 ss-qt5
sincere+  3129  0.0  0.0 178708  4788 tty2     Sl+  08:56   0:00 /usr/libexec/dconf-service
sincere+  3402  0.0  0.0 248072  7060 tty2     Sl+  08:59   0:00 /usr/libexec/gvfsd-metadata
sincere+  4019  0.0  0.0  21396  2924 tty2     S+   09:22   0:00 /usr/libexec/bluetooth/obexd
sincere+  8445  0.0  0.1 489448  9976 tty2     Sl+  11:31   0:00 /usr/libexec/gvfsd-trash --spawner :1.6 /org/gtk/gvfs/exec_spaw/0
sincere+  9338  0.0  0.3 644032 24964 tty2     Sl+  12:41   0:00 /usr/libexec/gvfsd-recent --spawner :1.6 /org/gtk/gvfs/exec_spaw/1
sincere+ 13115  0.1  0.6 984712 54960 tty2     Sl+  15:30   0:04 /usr/bin/nautilus --gapplication-service
sincere+ 13133  2.3  1.2 1683820 100904 tty2   Sl+  15:31   1:00 /usr/bin/totem --gapplication-service
sincere+ 13173  0.2  0.6 794264 48956 tty2     Sl+  15:33   0:05 /usr/libexec/gnome-terminal-server
sincere+ 13212  0.0  0.0   8464  1752 tty2     S+   15:33   0:00  \_ gnome-pty-helper
sincere+ 13218  0.0  0.0 118492  4992 pts/0    Ss   15:33   0:00  \_ bash
sincere+ 14133  0.0  0.0  22104  2452 pts/0    S+   15:37   0:00  |   \_ redis-cli
sincere+ 14256  0.0  0.0 118392  4740 pts/1    Ss+  15:44   0:00  \_ bash
sincere+ 15098  0.0  0.0 118392  4776 pts/2    Ss   15:59   0:00  \_ bash
sincere+ 15541  0.0  0.0 153568  4244 pts/2    R+   16:15   0:00      \_ ps auxfww
sincere+ 13288  4.2  4.3 2105676 350432 tty2   SLl+ 15:33   1:43 /opt/google/chrome/chrome 
sincere+ 13296  0.0  0.0 109664   792 tty2     S+   15:33   0:00  \_ cat
sincere+ 13297  0.0  0.0 109664   748 tty2     S+   15:33   0:00  \_ cat
sincere+ 13299  0.0  0.0   6464   840 tty2     S+   15:33   0:00  \_ /opt/google/chrome/chrome-sandbox /opt/google/chrome/chrome --type=zygote
sincere+ 13301  0.0  0.5 519620 46904 tty2     S+   15:33   0:00  |   \_ /opt/google/chrome/chrome --type=zygote
sincere+ 13305  0.0  0.0   6464   756 tty2     S+   15:33   0:00  |       \_ /opt/google/chrome/chrome-sandbox /opt/google/chrome/nacl_helper
sincere+ 13306  0.0  0.1 138704  8404 tty2     S+   15:33   0:00  |       |   \_ /opt/google/chrome/nacl_helper
sincere+ 13308  0.0  0.1 527816 13868 tty2     S+   15:33   0:00  |       \_ /opt/google/chrome/chrome --type=zygote

  • VSZ(Vritual Memory Size): 指进程可以占用的内存地址空间的大小
  • RSS(Resident Set Size): 指进程实际占用的内存地址空间的大小
(2)查看端口号占用
netstat -tunlp | grep 80

输出

[sincerefly@init-smile ~]$ sudo netstat -tunlp | grep 80
tcp        0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      2933/ss-qt5         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      779/nginx: master p 
udp        0      0 127.0.0.1:1080          0.0.0.0:*                           2933/ss-qt5
(3)查看占用端口号的程序路径
lsof -p 15986

上面的PID是我们查询端口号获取到的,通过这个进程ID,我们就可以找出这个程序的位置

COMMAND   PID       USER   FD      TYPE  DEVICE SIZE/OFF     NODE NAME
node    15986 sincerefly  cwd       DIR   253,2     4096 14944574 /home/sincerefly/Works/Projects/simple-blog
node    15986 sincerefly  rtd       DIR   253,1     4096        2 /
node    15986 sincerefly  txt       REG   253,1  1178736  2894545 /usr/bin/node
node    15986 sincerefly  mem       REG   253,1    61896  2892277 /usr/lib64/libnss_files-2.21.so
node    15986 sincerefly  mem       REG   253,2    69016   786983 /home/sincerefly/Works/Projects/simple-blog/node_modules/mongodb/node_modules/bson/build/Release/bson.node
node    15986 sincerefly  mem       REG   253,1   459584  2892335 /usr/lib64/libpcre.so.1.2.5
node    15986 sincerefly  mem       REG   253,1   142112  2891583 /usr/lib64/libselinux.so.1
node    15986 sincerefly  mem       REG   253,1   114536  2892407 /usr/lib64/libresolv-2.21.so
node    15986 sincerefly  mem       REG   253,1    15456  2892175 /usr/lib64/libkeyutils.so.1.5
node    15986 sincerefly  mem       REG   253,1    62304  2891030 /usr/lib64/libkrb5support.so.0.1
node    15986 sincerefly  mem       REG   253,1   206384  2891019 /usr/lib64/libk5crypto.so.3.1
node    15986 sincerefly  mem       REG   253,1    15664  2891858 /usr/lib64/libcom_err.so.2.1
node    15986 sincerefly  mem       REG   253,1   948280  2891029 /usr/lib64/libkrb5.so.3.3
node    15986 sincerefly  mem       REG   253,1   318736  2890911 /usr/lib64/libgssapi_krb5.so.2.2
node    15986 sincerefly  mem       REG   253,1 25340568  2892131 /usr/lib64/libicudata.so.54.1
node    15986 sincerefly  mem       REG   253,1  1634032  2892138 /usr/lib64/libicuuc.so.54.1
node    15986 sincerefly  mem       REG   253,1  2455880  2892132 /usr/lib64/libicui18n.so.54.1
node    15986 sincerefly  mem       REG   253,1    43096  2892421 /usr/lib64/librt-2.21.so
node    15986 sincerefly  mem       REG   253,1    19336  2891894 /usr/lib64/libdl-2.21.so
node    15986 sincerefly  mem       REG   253,1  2095008  2891806 /usr/lib64/libc-2.21.so
node    15986 sincerefly  mem       REG   253,1   140952  2892370 /usr/lib64/libpthread-2.21.so
node    15986 sincerefly  mem       REG   253,1    92816  2885317 /usr/lib64/libgcc_s-5.1.1-20150618.so.1
node    15986 sincerefly  mem       REG   253,1  1164944  2892202 /usr/lib64/libm-2.21.so
node    15986 sincerefly  mem       REG   253,1  1566576  2891289 /usr/lib64/libstdc++.so.6.0.21
node    15986 sincerefly  mem       REG   253,1  1994856  2890477 /usr/lib64/libcrypto.so.1.0.1k
node    15986 sincerefly  mem       REG   253,1   455568  2890729 /usr/lib64/libssl.so.1.0.1k
node    15986 sincerefly  mem       REG   253,1  5652064  2894536 /usr/lib64/libv8.so.3.14.5
node    15986 sincerefly  mem       REG   253,1   116616  2894544 /usr/lib64/libuv.so.0.10
node    15986 sincerefly  mem       REG   253,1    74160  2891818 /usr/lib64/libcares.so.2.1.0
node    15986 sincerefly  mem       REG   253,1    23344  2894541 /usr/lib64/libhttp_parser.so.2.0
node    15986 sincerefly  mem       REG   253,1    89992  2892662 /usr/lib64/libz.so.1.2.8
node    15986 sincerefly  mem       REG   253,1   158840  2891643 /usr/lib64/ld-2.21.so
node    15986 sincerefly    0u      CHR   136,3      0t0        6 /dev/pts/3
node    15986 sincerefly    1u      CHR   136,3      0t0        6 /dev/pts/3
node    15986 sincerefly    2u      CHR   136,3      0t0        6 /dev/pts/3
node    15986 sincerefly    3r     FIFO     0,9      0t0  1921501 pipe
node    15986 sincerefly    4w     FIFO     0,9      0t0  1921501 pipe
node    15986 sincerefly    5u  a_inode    0,10        0     9632 [eventpoll]
node    15986 sincerefly    6r     FIFO     0,9      0t0  1921502 pipe
node    15986 sincerefly    7w     FIFO     0,9      0t0  1921502 pipe
node    15986 sincerefly    8u  a_inode    0,10        0     9632 [eventfd]
node    15986 sincerefly    9r      DIR   253,1     4096        2 /
node    15986 sincerefly   10w      REG   253,2    71193 14944577 /home/sincerefly/Works/Projects/simple-blog/access.log
node    15986 sincerefly   11w      REG   253,2        0 14944586 /home/sincerefly/Works/Projects/simple-blog/error.log
node    15986 sincerefly   12u     IPv4 1919513      0t0      TCP *:terabase (LISTEN)
node    15986 sincerefly   13u     IPv4 1919515      0t0      TCP localhost.localdomain:59946->localhost.localdomain:27017 (ESTABLISHED)
node    15986 sincerefly   14u     IPv4 1919516      0t0      TCP localhost.localdomain:59947->localhost.localdomain:27017 (ESTABLISHED)
node    15986 sincerefly   15u     IPv4 1919517      0t0      TCP localhost.localdomain:59948->localhost.localdomain:27017 (ESTABLISHED)
node    15986 sincerefly   16u     IPv4 1919518      0t0      TCP localhost.localdomain:59949->localhost.localdomain:27017 (ESTABLISHED)
node    15986 sincerefly   17u     IPv4 1919519      0t0      TCP localhost.localdomain:59950->localhost.localdomain:27017 (ESTABLISHED)

还有另一种方法,当获取PID后使用ll查询

 ll /proc/15986/
dr-xr-xr-x 2 sincerefly sincerefly 0 8月  20 16:24 attr
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 autogroup
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 auxv
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 cgroup
--w------- 1 sincerefly sincerefly 0 8月  20 16:30 clear_refs
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:24 cmdline
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 comm
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 coredump_filter
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 cpuset
lrwxrwxrwx 1 sincerefly sincerefly 0 8月  20 16:26 cwd -> /home/sincerefly/Works/Projects/simple-blog
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 environ
lrwxrwxrwx 1 sincerefly sincerefly 0 8月  20 16:24 exe -> /usr/bin/node
dr-x------ 2 sincerefly sincerefly 0 8月  20 16:24 fd
dr-x------ 2 sincerefly sincerefly 0 8月  20 16:26 fdinfo
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 gid_map
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 io
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 limits
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 loginuid
dr-x------ 2 sincerefly sincerefly 0 8月  20 16:30 map_files
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:26 maps
-rw------- 1 sincerefly sincerefly 0 8月  20 16:30 mem
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 mountinfo
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 mounts
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 mountstats
dr-xr-xr-x 7 sincerefly sincerefly 0 8月  20 16:30 net
dr-x--x--x 2 sincerefly sincerefly 0 8月  20 16:30 ns
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 numa_maps
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 oom_adj
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 oom_score
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 oom_score_adj
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 pagemap
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 personality
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 projid_map
lrwxrwxrwx 1 sincerefly sincerefly 0 8月  20 16:26 root -> /
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 sched
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 sessionid
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 setgroups
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 smaps
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 stack
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:26 stat
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 statm
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 status
-r-------- 1 sincerefly sincerefly 0 8月  20 16:30 syscall
dr-xr-xr-x 8 sincerefly sincerefly 0 8月  20 16:30 task
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 timers
-rw-r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 uid_map
-r--r--r-- 1 sincerefly sincerefly 0 8月  20 16:30 wchan