사이트 지원할 때 파일 디스크립터(File Descriptor)를 종종 확인해야 할 경우가 있습니다.
이럴 때 사용할 수 있는 툴로는 pfiles나 lsof가 대표적입니다.
아래 사이트에서 lsof 바이너리를 각 플랫폼별로 다운 받을 수 있습니다.
사용법은 간단하게 lsof만 수행하시면 시스템 전체의 file descriptor사용내역을 보여주고
lsof -p [PID] 를 하면 해당 PID에 대한 file descriptor를 보여줍니다.
[01] lsof란 무엇인가?
LiSt Open File의 약자로서, 이름이 말하는 것들을 그대로 수행하는 프로그램이다.
좀 더 구체적으로, 현재 System에서 돌아가는 모든 Process에 의해서 Open된 파일들에 대한 정보를 보여준다.
옵 션 |
설 명 |
-t |
현재 동작되고 있는 프로세서의 PID를 출력한다. |
-p [pid] |
해당 pid가 참조하고 있는 프로그램과 파일들과 라이브러리가 출력된다. |
-i[:port] |
현재 열려있는 소켓들에 대해서 출력한다. -i[:port] 특정포트에 대해 출력 |
-i@<ip> |
해당 아이피가 접속 정보를 출력한다. -i@<도메인>으로도 가능. 대신 도메 인은 resolve되어서 IP로 변환이 가능해야 한다. |
-T |
현재 열려있는 소켓들 중에서 TCP에 대한 것만을 출력 |
-U |
현재 열려있는 소켓들 중에서 UDP에 대한 것만을 출력 |
-l |
로그인 계정대신에 UID로 표시 |
-n |
호스트네임대신에 IP로서 출력 |
-r [초] |
losf의 명령을 -r 다음에 지정한 시간을 주기로 반복 실행한다. |
-v |
lsof에 대한 정보를 출력한다. |
-u<user> |
특정 사용자에 의해서 실행되고 있는 프로그램과 참조하고 있는 파일을 출력한다. -u<uid>를 사용해도 같은 결과를 얻는다. |
-c<데몬> |
특정 데몬들이 참조하고 있는 파일들을 출력한다. |
그 외 다른 옵션들은 “lsof -h“를 통해서 확인할 수 있다.
[예제 1-1] 어떤 따식(프로세서)이 어떤 포트를 사용하고 있는가?
[root@localhost ~]# lsof -i | more
[예제 1-2] 어떤 따식(프로세서)이 어떤 파일을 사용하고 있는가 ?
[root@localhost ~]# lsof [어떤 파일] // 예로 httpd라고 가정한다.
[예제 1-3] httpd에 억세스 하고 있는 모든 놈들을 보고 싶다.
[root@localhost ~]# lsof -c httpd
[예제 1-4] root 유저가 뭐하나?
[root@localhost ~]# lsof -u root
[예제 1-5] 누가 내 서버에 찝적꺼리지? ^_^;
[root@localhost ~]# lsof -i@localhost
(01) 어떤 특정한 파일을 사용하고 있는 프로세스들에 대한 정보를 알고 싶을 때
# lsof <expected file name with path>
(02) # lsof /etc/passwd
실행하면 /etc/passwd를 억세스하고 있는 프로세스들을 점검할수 있으며, 이 파일을 가지고 장난치는 프로세스들도 발견할 수 있다.
(03) lsof는 모든 네트워크 Socket 들을 찾아낼수 있다.
(04) # lsof –p <PID>
해당 프로세스가 열고 있는 파일들을 열람할 수 있게 된다.
(05) lsof는 어떤 유저가 열고 있는 모든 파일들을 열거해 볼 수도 있다.
# lsof –u <loginname> 혹은 lsof –u <UID>
-u 옵션에는 인자를 “,”로 구분하여 여러 인자를 한꺼번에 넘길 수 있다.
# lsof –u doom,user01,user02
[출처] lsof|작성자 소류하
FD is the File Descriptor number of the file or:
cwd current working directory;
Lnn library references (AIX);
err FD information error (see NAME column);
jld jail directory (FreeBSD);
ltx shared library text (code and data);
Mxx hex memory-mapped type number xx.
m86 DOS Merge mapped file;
mem memory-mapped file;
mmap memory-mapped device;
pd parent directory;
rtd root directory;
tr kernel trace file (OpenBSD);
txt program text (code and data);
v86 VP/ix mapped file;
FD is followed by one of these characters, describing the mode under which the file is open:
r for read access;
w for write access;
u for read and write access;
space if mode unknown and no lock
character follows;
'-' if mode unknown and lock
character follows.
The mode character is followed by one of these lock characters, describing the type of lock applied to the
file:
N for a Solaris NFS lock of unknown type;
r for read lock on part of the file;
R for a read lock on the entire file;
w for a write lock on part of the file;
W for a write lock on the entire file;
u for a read and write lock of any length;
U for a lock of unknown type;
x for an SCO OpenServer Xenix lock on part of the file;
X for an SCO OpenServer Xenix lock on the entire file;
space if there is no lock.
See the LOCKS section for more information on the lock information character.
The FD column contents constitutes a single field for parsing in post-processing scripts.
'컴퓨터 과학 & 영상처리 관련 > 리눅스' 카테고리의 다른 글
pipe (0) | 2011.12.23 |
---|---|
man 1,2,3,4,5 (0) | 2011.12.14 |
gcc 명령어 option의 뜻 (0) | 2011.09.20 |
facebook pidgin 사용법 (0) | 2011.06.29 |
deb, rpm, bin 설치법 (0) | 2011.06.28 |