structure thermal devices
[metriccd.git] / client / meter / process
blobbb4105f0d54cebecb306f7082b4fd01d6f84aa48
1 #!/usr/bin/env perl
3 require "common.pl";
5 %psState = (
6 'D' => "io-wait",
7 'R' => "running",
8 'S' => "sleeping",
9 'T' => "stopped",
10 'W' => "paging",
11 'X' => "dead",
12 'x' => "dead",
13 'Z' => "zombie",
14 'I' => "idle",
15 't' => "tracing-stop",
16 'K' => "wakekill",
17 'P' => "parked",
20 %states = map {$_=>0} values %psState;
21 %Processes = ('state' => \%states);
23 opendir my $dir, '/proc';
25 while(my $pid = readdir $dir)
27 if($pid =~ /^\d+$/)
29 $Processes{'count'}++;
30 my %procprop = ();
32 open my $fh, '<', "/proc/$pid/status";
33 while(<$fh>)
35 if(/^Threads:\s*(\d+)/)
37 $Processes{'threads'} += $1;
39 elsif(/^(Tgid|VmLck):\s*(\d+)/)
41 $procprop{$1} = $2;
44 close $fh;
46 open my $fh, '<', "/proc/$pid/stat";
47 my $stat = <$fh>;
48 close $fh;
50 if(my ($state, $pgrp, $session, $tpgid, $flags, $priority, $nice, $nlwp) =
51 $stat =~ /\) (.) -?\d+ (-?\d+) (-?\d+) -?\d+ (-?\d+) (-?\d+) (?:-?\d+ ){4}(?:-?\d+ ){4}(-?\d+) (-?\d+) (-?\d+)[ \d-]*$/)
53 $Processes{'state'}{$psState{uc$state} || $state}++;
54 $Processes{'hi_prio'}++ if $nice < 0;
55 $Processes{'lo_prio'}++ if $nice > 0;
56 $Processes{'locked-pages'}++ if $procprop{'VmLck'} > 0;
57 $Processes{'session-leader'}++ if $session == $procprop{'Tgid'};
58 $Processes{'multithreaded'}++ if $nlwp > 1;
59 $Processes{'foreground'}++ if $pgrp == $tpgid;
64 svlhk_dump(\%Processes);