
Cygwin에서 실행하면 top
다음을 얻습니다.
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
스위치와 스위치를 조합하여 사용하면(한 번 실행) 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
영감을 주신 agtoever에게 감사드립니다.