
Wenn ich es top
in Cygwin ausführe, erhalte ich:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
Ich möchte diese Spalten für alle Prozesse extrahieren:
PID PPID S COMMAND
ps
gibt PID, PPID und COMMAND an, aber wie erhalte ich die Spalte „S“ für alle Prozesse?
Bearbeiten:
Ich kann nicht verwenden, was ich unter GNU/Linux verwende:
$ 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
Antwort1
Standardmäßig top
wird die PPID nicht angezeigt (zumindest in CygWin). Außerdem kann man den Batch-Modus von top nutzen, indem man den -b
Schalter in Kombination mit dem -n 1
Schalter (einmal ausführen) verwendet. Ich habe immer awk
die ersten Zeilen übersprungen und eine grobe Auswahl der Spalten getroffen.
top -b -n 1 | awk 'NR>6 { print $1, $8, $12 }'
Antwort2
Sie könnenps -e -o pid,ppid,state,comm
Antwort3
Dies war die Lösung:
perl -ne '/Name/ and print"\n";/(Name|Pid|Ppid|State):\s+(\S+)/ and print "$2\t";' /proc/*/status
Vielen Dank schon mal für die Inspiration.