16

I would like to monitor processes from a cygwin shell, using top or a variant. The reason for this is its realtime reporting and constant updates. However under cygwin, top will not report on windows processes.

Teh forums I have been to recommend using ps -W as an alternative, but this obviously has the drawback of no longer giving me realtime information, but just a static snapshot whenever I type the command.

Is there any way to get top to work in cygwin to display all my processes and not just cygwins processes?

1
  • 2
    Is there a reason it specifically has to be based in Cygwin? If you just want something that provides a detailed list of data on running windows processes in a tabular format (like top), try Process Explorer May 9, 2014 at 16:40

3 Answers 3

16

From a bash shell, you can monitor all windows processes with this command line:

watch "ps -W" # pipe to grep for filtering

To see all java processes, for example:

watch "ps -W | grep java"

Note that "ps -W" lists both cygwin and non-cygwin processes.

1
  • Either ps -W or ps --windows work, see ps --help
    – Timo
    Aug 22, 2017 at 14:45
3

You have to install the procps library for cygwin, this includes the top program, however that will only list processes running in cygwin. If you want to see all processes running on windows, refer to this answer: https://stackoverflow.com/questions/3503681/cygwin-top-command-see-processes-for-all-users

1

It seems you can do something like:

wmic process get ProcessId,Name,UserModeTime,KernelModeTime /EVERY:1

The User and Kernel mode times there seem to be expressed in 1/10,000,000th of second.

You should be able to post-process that output to get the CPU-usage per second.

Here using cygwin's perl:

wmic process get ProcessId,Name,UserModeTime,KernelModeTime /EVERY:1 |
  perl -lne '
    if (/\S/) {
      my ($k,$c,$p,$u) = split /\s{2,}/;
      $n{"$p\t$c"}=$k+$u;
    } else {
      my %c;
      for my $k (keys %n) {
        $c{$k} = $n{$k} - $o{$k} if defined $o{$k}
      }
      print "$_\t" . $c{$_}/1e5 for (sort {$c{$b}<=>$c{$a}} keys %c)[0..20];
      %o = %n; %n = undef; print ""
    }'

Outputs something like:

0       System Idle Process     588.12377
2196    sh.exe  107.00075
248     svchost.exe     85.80055
7140    explorer.exe    26.52017
[...]

every second.

Note that if the System Idle Process shows just under 800% on an idle system, that's because your system has 8 CPU cores (well at least 8 threads) as that counts the CPU time of all CPUs.

Also note that the EVERY:1 above is a lie. wmic doesn't seem to give that output every second. More likely, it sleeps roughly 1 second between each report and doesn't compensate for the time it takes to compute the report. So in practice, it will run every 1 second and a bit which means those percentages are not very accurate and slightly overestimated.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .