トップ «前の日記(2010-10-02) 最新 次の日記(2010-10-04)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2010-10-03 :-)

_ [NetBSD][翻訳]hubertf's NetBSD blog - Look who's talking, or: how to find which process listens on a given socket (Updated)

ソケットを使用しているプロセスを探す方法

From the "learn something new every day" department: I've wondered how to find a process listening on a given socket in the past. While there is "lsof" in pkgsrc, here is a solution using NetBSD's on-board tools, netstat(1) and fstat(1).

「毎日のドリル集」より: 先日、ソケットを使用しているプロセスを調べる方法を知って感動した。pkgsrc の lsof を使えば出来るのだけど、ここでは NetBSD に予め入っているツール netstat(1) と fstat(1) を使って同じことをやる。

netstat(1)'s "-A" switch can be used to show a protocol control block (PCB) associated with a socket in its output, for TCP and Unix domain sockets:

netstat(1) の -A スイッチは、TCP と Unix ドメインソケットのソケットに割り当てられているプロトコル制御ブロック (PCB) を表示する:

 % netstat -Aa
 Active Internet connections (including servers)
 PCB      Proto Recv-Q Send-Q  Local Address      Foreign Address    State
 c15ce1f4 tcp        0      0  10.0.0.178.ssh     mini.52788         ESTABLISHED
 c15ce5dc tcp        0      0  *.ftp              *.*                LISTEN
 c15ce7d0 tcp        0      0  *.https            *.*                LISTEN
 ...
 Active Internet6 connections (including servers)
 PCB      Proto Recv-Q Send-Q  Local Address      Foreign Address    (state)
 c15ce3e8 tcp6       0      0  *.ftp              *.*                LISTEN
 c15cedac tcp6       0      0  *.ssh              *.*                LISTEN
 Active UNIX domain sockets
 Address  Type   Recv-Q Send-Q    Inode     Conn     Refs  Nextref Addr
 c1602480 stream      0      0 cb9e6f20        0        0        0 private/scache
 ...

Questions arising from the above output may be what process is handling the TCP/ssh connection and who is responsible for the "private/scache" Unix domain socket.

上記の出力からは、TCP/ssh コネクションを確立しているプロセスと、"private/scache" の Unix ドメインソケットを使用しているプロセスが分かる。

In NetBSD, a PCB identifies a certain network connection, and from that more information on the processes using that PCB can be determined. This can be done using NetBSD's fstat(1) command as follows.

NetBSD では、PCB 識別子はネットワークコネクションの確立を表しており、プロセスが使用している PCB を調べることにより詳しい情報を得ることができる。NetBSD では fstat(1) を使えばよい。

The TCP ssh connection lists PCB "c15ce1f4":

PCB "c15ce1f4" の TCP ssh 接続のリストはこう:

% fstat | head -1
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
% fstat | grep c15ce1f4
feyrer   sshd       23305    5* internet stream tcp c15ce1f4 10.0.0.178:22 <-> 10.0.0.2:52788
root     sshd       26059    5* internet stream tcp c15ce1f4 10.0.0.178:22 <-> 10.0.0.2:52788

So it's two processes here, one SSH daemon running as root, and one under my user-id. The reason behind this is the SSH daemon's splitting of privileges across multiple processes.

ここでは 2 つのプロセスが見える。1 つは root によって走っている SSH デーモンで、もう 1 つは私の ID で走っているものだ。これは、SSH デーモンが複数プロセスにまたがるアクセスを許していることを意味する。

The answer to who is listening on Unix domain socket "private/scache" can be found in a similar fashion:

Unix ドメインソケット "private/scache" を使用しているプロセスを調べる方法はこう:

% fstat | grep c1602480
root     master       511   80* unix stream c1602480
% locate /master | grep 'master$'
/usr/libexec/postfix/master

If a program "master" is not too obvious (a virus?!), looking for its place on the file system, e.g. using locate(1), may help. In this case, it shows that the socket is used by the Postfix mail server.

"master" というプログラムが何なのかいまいち分からないならば( ウィルスかも!? )、例えば locate(1) を使うなどしてファイルシステムを探そう。この場合は、Postfix mail server が使っているソケットが表示されている。

Update: Geert Hendricks mentioned "sockstat -al" as well... one for the category "NetBSD commands you didn't know yet" :-) Thanks Geert!

更新: Geert Hendricks が「"sockstat -al" はまだあなたは知ってないはずでしょ :-) 」というツッコミをくれた。おっと、ありがとう Geert !

_ ほぼ完全に一致

キャプチャ画像。左がサイト1、右がサイト2

文章の全角半角、空白を正規化したうえで diff してキャプチャ。左がサイト1、右がサイト2

_ きょうの検索さん

今野宏美 胸 - Google 画像検索
こやまきみこ 胸 - Google 画像検索
阿澄佳奈 胸 - Google 画像検索
佐藤利奈 胸 - Google 画像検索

コノヤロウ