
top
Cygwin で実行すると次のようになります:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
すべてのプロセスについて次の列を抽出したいと思います。
PID PPID S COMMAND
ps
PID、PPID、COMMAND は表示されますが、すべてのプロセスの「S」列を取得するにはどうすればよいでしょうか?
編集:
GNU/Linux で使用しているものが使用できません:
$ ps -e -o pid,ppid,state,comm
ps: unknown option -- o
Try `ps --help' for more information.
$ ps --version
ps (cygwin) 1.7.33
Show process statistics
Copyright (C) 1996 - 2014 Red Hat, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ps --help
Usage: ps [-aefls] [-u UID] [-p PID]
Report process status
-a, --all show processes of all users
-e, --everyone show processes of all users
-f, --full show process uids, ppids
-h, --help output usage information and exit
-l, --long show process uids, ppids, pgids, winpids
-p, --process show information for specified PID
-s, --summary show process summary
-u, --user list processes owned by UID
-V, --version output version information and exit
-W, --windows show windows as well as cygwin processes
With no options, ps outputs the long format by default
procps
:
version: 3.2.8-3
答え1
デフォルトではtop
PPID は表示されません (少なくとも CygWin では)。それ以外に、スイッチをスイッチ (1 回実行)-b
と組み合わせて使用することで、top のバッチ モードを使用できます。私は最初の行をスキップして、列の大まかな選択を行っていました。-n 1
awk
top -b -n 1 | awk 'NR>6 { print $1, $8, $12 }'
答え2
使用できますps -e -o pid,ppid,state,comm
答え3
これが解決策となりました:
perl -ne '/Name/ and print"\n";/(Name|Pid|Ppid|State):\s+(\S+)/ and print "$2\t";' /proc/*/status
いつもインスピレーションをありがとう。