10 Awọn apẹẹrẹ Aṣẹ Aṣẹ ni Linux


Eyi ni jara ti nlọ lọwọ ti awọn aṣẹ Linux ati ninu nkan yii a yoo ṣe atunyẹwo aṣẹ lsof pẹlu awọn apẹẹrẹ iṣe. lsof ti o tumọ si 'Awọn faili Open LiSt' ni a lo lati wa iru awọn faili ti o ṣii nipasẹ ilana wo. Gẹgẹ bi gbogbo wa ṣe mọ Linux/Unix ṣe akiyesi ohun gbogbo bi awọn faili kan (awọn paipu, awọn iho, awọn ilana, awọn ẹrọ abbl). Ọkan ninu idi lati lo pipaṣẹ lsof ni nigbati a ko le yọ disk kuro bi o ti sọ pe awọn faili nlo. Pẹlu iranlọwọ ti aṣẹ yii a le ṣe idanimọ awọn faili ti o wa ni lilo ni irọrun.

Ninu apẹẹrẹ ti o wa ni isalẹ, yoo fihan atokọ gigun ti awọn faili ṣiṣi diẹ ninu wọn ti fa jade fun oye ti o dara julọ eyiti o han awọn ọwọn bi Command, PID, USER, FD, TYPE ati bẹbẹ lọ.

# lsof

COMMAND    PID      USER   FD      TYPE     DEVICE  SIZE/OFF       NODE NAME
init         1      root  cwd      DIR      253,0      4096          2 /
init         1      root  rtd      DIR      253,0      4096          2 /
init         1      root  txt      REG      253,0    145180     147164 /sbin/init
init         1      root  mem      REG      253,0   1889704     190149 /lib/libc-2.12.so
init         1      root   0u      CHR        1,3       0t0       3764 /dev/null
init         1      root   1u      CHR        1,3       0t0       3764 /dev/null
init         1      root   2u      CHR        1,3       0t0       3764 /dev/null
init         1      root   3r     FIFO        0,8       0t0       8449 pipe
init         1      root   4w     FIFO       0,8       0t0       8449 pipe
init         1      root   5r      DIR       0,10         0          1 inotify
init         1      root   6r      DIR       0,10         0          1 inotify
init         1      root   7u     unix 0xc1513880       0t0       8450 socket

Awọn apakan ati pe o jẹ awọn iye jẹ alaye ti ara ẹni. Sibẹsibẹ, a yoo ṣe atunyẹwo awọn ọwọn FD & TYPE diẹ sii ni deede.

FD - duro fun apejuwe Oluṣakoso ati pe o le rii diẹ ninu awọn iye bi:

    itọsọna liw lọwọlọwọ cwd
  1. rtd liana root
  2. ọrọ eto txt (koodu ati data)
  3. faili ti ya aworan iranti mem

Paapaa ninu awọn nọmba iwe FD bii 1u jẹ apejuwe faili gangan ati atẹle nipa u, r, w ti ipo rẹ bi:

  1. r fun iraye si kika.
  2. w fun iraye si kikọ.
  3. u fun iwọle ka ati kọ.

TYPE - ti awọn faili ati idanimọ rẹ.

  1. DIR - Itọsọna
  2. REG - Faili deede>
  3. CHR - Faili pataki ohun kikọ.
  4. FIFO - Akọkọ Ni Akọkọ Jade

Aṣẹ isalẹ yoo ṣe afihan atokọ ti gbogbo awọn faili ṣiṣi ti tecmint olumulo.

# lsof -u tecmint

COMMAND  PID    USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
sshd    1838 tecmint  cwd    DIR      253,0     4096      2 /
sshd    1838 tecmint  rtd    DIR      253,0     4096      2 /
sshd    1838 tecmint  txt    REG      253,0   532336 188129 /usr/sbin/sshd
sshd    1838 tecmint  mem    REG      253,0    19784 190237 /lib/libdl-2.12.so
sshd    1838 tecmint  mem    REG      253,0   122436 190247 /lib/libselinux.so.1
sshd    1838 tecmint  mem    REG      253,0   255968 190256 /lib/libgssapi_krb5.so.2.2
sshd    1838 tecmint  mem    REG      253,0   874580 190255 /lib/libkrb5.so.3.3

Lati wa gbogbo ilana ṣiṣe ti ibudo kan pato, kan lo aṣẹ atẹle pẹlu aṣayan -i. Apẹẹrẹ ti isalẹ yoo ṣe atokọ gbogbo ilana ṣiṣe ti ibudo 22.

# lsof -i TCP:22

COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd    1471    root    3u  IPv4  12683      0t0  TCP *:ssh (LISTEN)
sshd    1471    root    4u  IPv6  12685      0t0  TCP *:ssh (LISTEN)

Ni apẹẹrẹ ni isalẹ fihan awọn faili nẹtiwọọki IPv4 ati IPv6 nikan ṣii pẹlu awọn ofin lọtọ.

# lsof -i 4

COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1203     rpc    6u  IPv4  11326      0t0  UDP *:sunrpc
rpcbind   1203     rpc    7u  IPv4  11330      0t0  UDP *:954
rpcbind   1203     rpc    8u  IPv4  11331      0t0  TCP *:sunrpc (LISTEN)
avahi-dae 1241   avahi   13u  IPv4  11579      0t0  UDP *:mdns
avahi-dae 1241   avahi   14u  IPv4  11580      0t0  UDP *:58600

# lsof -i 6

COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1203     rpc    9u  IPv6  11333      0t0  UDP *:sunrpc
rpcbind   1203     rpc   10u  IPv6  11335      0t0  UDP *:954
rpcbind   1203     rpc   11u  IPv6  11336      0t0  TCP *:sunrpc (LISTEN)
rpc.statd 1277 rpcuser   10u  IPv6  11858      0t0  UDP *:55800
rpc.statd 1277 rpcuser   11u  IPv6  11862      0t0  TCP *:56428 (LISTEN)
cupsd     1346    root    6u  IPv6  12112      0t0  TCP localhost:ipp (LISTEN)

Lati ṣe atokọ gbogbo ilana ṣiṣe ti awọn faili ṣiṣi ti Awọn sakani Ibudo TCP lati 1-1024.

# lsof -i TCP:1-1024

COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 1203     rpc   11u  IPv6  11336      0t0  TCP *:sunrpc (LISTEN)
cupsd   1346    root    7u  IPv4  12113      0t0  TCP localhost:ipp (LISTEN)
sshd    1471    root    4u  IPv6  12685      0t0  TCP *:ssh (LISTEN)
master  1551    root   13u  IPv6  12898      0t0  TCP localhost:smtp (LISTEN)
sshd    1834    root    3r  IPv4  15101      0t0  TCP 192.168.0.2:ssh->192.168.0.1:conclave-cpp (ESTABLISHED)
sshd    1838 tecmint    3u  IPv4  15101      0t0  TCP 192.168.0.2:ssh->192.168.0.1:conclave-cpp (ESTABLISHED)
sshd    1871    root    3r  IPv4  15842      0t0  TCP 192.168.0.2:ssh->192.168.0.1:groove (ESTABLISHED)
httpd   1918    root    5u  IPv6  15991      0t0  TCP *:http (LISTEN)
httpd   1918    root    7u  IPv6  15995      0t0  TCP *:https (LISTEN)

Nibi, a ti yọ olumulo olumulo gbongbo kuro. O le ṣe iyasọtọ olumulo kan pato nipa lilo ‘^’ pẹlu aṣẹ bi o ti han loke.

# lsof -i -u^root

COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1203     rpc    6u  IPv4  11326      0t0  UDP *:sunrpc
rpcbind   1203     rpc    7u  IPv4  11330      0t0  UDP *:954
rpcbind   1203     rpc    8u  IPv4  11331      0t0  TCP *:sunrpc (LISTEN)
rpcbind   1203     rpc    9u  IPv6  11333      0t0  UDP *:sunrpc
rpcbind   1203     rpc   10u  IPv6  11335      0t0  UDP *:954
rpcbind   1203     rpc   11u  IPv6  11336      0t0  TCP *:sunrpc (LISTEN)
avahi-dae 1241   avahi   13u  IPv4  11579      0t0  UDP *:mdns
avahi-dae 1241   avahi   14u  IPv4  11580      0t0  UDP *:58600
rpc.statd 1277 rpcuser    5r  IPv4  11836      0t0  UDP *:soap-beep
rpc.statd 1277 rpcuser    8u  IPv4  11850      0t0  UDP *:55146
rpc.statd 1277 rpcuser    9u  IPv4  11854      0t0  TCP *:32981 (LISTEN)
rpc.statd 1277 rpcuser   10u  IPv6  11858      0t0  UDP *:55800
rpc.statd 1277 rpcuser   11u  IPv6  11862      0t0  TCP *:56428 (LISTEN)

Apẹẹrẹ isalẹ fihan tecmint olumulo ti nlo aṣẹ bi ping ati/ati be be liana.

# lsof -i -u tecmint

COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    1839 tecmint  cwd    DIR  253,0    12288   15 /etc
ping    2525 tecmint  cwd    DIR  253,0    12288   15 /etc

Atẹle atẹle pẹlu aṣayan '-i' fihan atokọ ti gbogbo awọn isopọ nẹtiwọọki 'TẸTẸ & Ṣeto'.

# lsof -i

COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind   1203     rpc    6u  IPv4  11326      0t0  UDP *:sunrpc
rpcbind   1203     rpc    7u  IPv4  11330      0t0  UDP *:954
rpcbind   1203     rpc   11u  IPv6  11336      0t0  TCP *:sunrpc (LISTEN)
avahi-dae 1241   avahi   13u  IPv4  11579      0t0  UDP *:mdns
avahi-dae 1241   avahi   14u  IPv4  11580      0t0  UDP *:58600
rpc.statd 1277 rpcuser   11u  IPv6  11862      0t0  TCP *:56428 (LISTEN)
cupsd     1346    root    6u  IPv6  12112      0t0  TCP localhost:ipp (LISTEN)
cupsd     1346    root    7u  IPv4  12113      0t0  TCP localhost:ipp (LISTEN)
sshd      1471    root    3u  IPv4  12683      0t0  TCP *:ssh (LISTEN)
master    1551    root   12u  IPv4  12896      0t0  TCP localhost:smtp (LISTEN)
master    1551    root   13u  IPv6  12898      0t0  TCP localhost:smtp (LISTEN)
sshd      1834    root    3r  IPv4  15101      0t0  TCP 192.168.0.2:ssh->192.168.0.1:conclave-cpp (ESTABLISHED)
httpd     1918    root    5u  IPv6  15991      0t0  TCP *:http (LISTEN)
httpd     1918    root    7u  IPv6  15995      0t0  TCP *:https (LISTEN)
clock-app 2362   narad   21u  IPv4  22591      0t0  TCP 192.168.0.2:45284->www.gov.com:http (CLOSE_WAIT)
chrome    2377   narad   61u  IPv4  25862      0t0  TCP 192.168.0.2:33358->maa03s04-in-f3.1e100.net:http (ESTABLISHED)
chrome    2377   narad   80u  IPv4  25866      0t0  TCP 192.168.0.2:36405->bom03s01-in-f15.1e100.net:http (ESTABLISHED)

Apẹẹrẹ ti o wa ni isalẹ nikan fihan ẹniti PID jẹ 1 [Ọkan].

# lsof -p 1

COMMAND PID USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
init      1 root  cwd    DIR      253,0     4096      2 /
init      1 root  rtd    DIR      253,0     4096      2 /
init      1 root  txt    REG      253,0   145180 147164 /sbin/init
init      1 root  mem    REG      253,0  1889704 190149 /lib/libc-2.12.so
init      1 root  mem    REG      253,0   142472 189970 /lib/ld-2.12.so

Nigba miiran o le ni lati pa gbogbo awọn ilana fun olumulo kan pato. Ni isalẹ aṣẹ yoo pa gbogbo awọn ilana ti olumulo tecmint.

# kill -9 `lsof -t -u tecmint`

Akiyesi: Nibi, ko ṣee ṣe lati fun apẹẹrẹ ti gbogbo awọn aṣayan to wa, itọsọna yii nikan ni lati fihan bi aṣẹ lsof ṣe le lo. O le tọka oju-iwe eniyan ti aṣẹ lsof lati mọ diẹ sii nipa rẹ. Jọwọ pin rẹ ti o ba rii pe nkan yii wulo nipasẹ apoti asọye wa ni isalẹ.