Cygwin:取得行程狀態

Cygwin:取得行程狀態

當我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 中)。除此之外,您還可以透過將開關-b與開關結合使用-n 1(運行一次)來使用top的批次模式。我曾經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

感謝agtoever 的啟發。

相關內容