LoginSignup
23
17

More than 5 years have passed since last update.

CentOS 7にしたらpgrepコマンドの仕様が変わっていた

Last updated at Posted at 2015-08-16

最近になって、ようやく手元の環境をCentOS 6系からCentOS 7系に移行しています。
ファイルシステムのデフォルトがext4からxfsになったとか、systemdとか色々と大きな変更点がありますが、自分が普段からよく使っているコマンドで結構な変更がされていて少し戸惑ったのでメモ。

プロセスのPID確認にpgrepコマンドを多用していました。

pgrep -fl postgres
$ pgrep -fl postgres
22727 su - postgres
22760 /usr/local/pgsql/9.5dev/bin/postgres
22761 postgres: logger process
22763 postgres: checkpointer process
22764 postgres: writer process
22765 postgres: wal writer process
22766 postgres: autovacuum launcher process
22767 postgres: archiver process
22768 postgres: stats collector process

fオプションでコマンドライン全体にマッチさせて、lオプションで出力結果にプロセス名をPIDとともに表示させてます。

ps aux | grep hoge | grep -v grepとか打つより断然早いし、出力がスッキリするので気にっていました。

ところが、CentOS 7にすると、

$ pgrep -fl postgres
25702 postgres
25703 postgres
25705 postgres
25706 postgres
25707 postgres
25708 postgres
25709 postgres
25710 postgres
31583 su

...( TДT)なにこれ

man読んでも今までと特に変わってないみたいだし、なんでプロセス名の一部しかでなくなったのか。。。

で、最終的にはググった結果、aオプションなるものが新たに追加されているらしいことを発見。

$ pgrep -a postgres
25702 /usr/local/pgsql/9.5dev/bin/postgres
25703 postgres: logger process
25705 postgres: checkpointer process
25706 postgres: writer process
25707 postgres: wal writer process
25708 postgres: autovacuum launcher process
25709 postgres: archiver process   last was 000000010000000000000017
25710 postgres: stats collector process

おお!これですこれです、望んていた出力は╭( ・ㅂ・)و
というか、manに書いておいてよ。。。

後から気づきましたが、pgrep --helpだとaオプションが記載されてますね。

 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line

こっちを見れば早かった(反省)


で、pgrepのバージョンを調べていて分かりましたが、CentOS 7(おそらくRHEL 7も)はpgrepを提供していたのが、procpsからprocps-ngというのに変わっているようです。

$ cat /etc/redhat-release
CentOS release 6.6 (Final)
$ pgrep -V
pgrep (procps version 3.2.8)
$ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
$ pgrep -V
pgrep from procps-ng 3.3.10

ngはNew Generationの略みたいですね。(https://gitlab.com/procps-ng/procps)
本家のprocpsの開発が遅くなったから、新たにforkして色々バグ改修と機能追加を行っているプロジェクトのようです。

History
This is a fork of procps. This fork was started by the maintainers of Debian, >Fedora and openSUSE and assisted by a small group of independent developers.

The aim of the procps fork, which is now the only maintained version of procps, was to remove the number of distribution-specific patches and differences between the distributions.

The import occurred in late 2010 and was then followed by a flurry of patching imports that was held back previously. Eventually the level of backlogged patches reduced and procps is now actively maintained.

procps-ngのwikiより引用(https://gitlab.com/procps-ng/procps/wikis/home)

ということで、そもそも元になっているプロジェクトが6系から7系で変わってしまっているので、互換性もクソもありません。

pgrepコマンド以外にもps, top, vmstat, killなどもっとよく使うコマンドも含まれているので、そのあたりの仕様変更もいっぱいありそうです。

23
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
17