blob: 54678eb802bc520246d28678a7cfad1af2f897ad [file] [log] [blame]
rsc629864f2003-10-13 18:25:28 +00001#!/bin/sh
2
3I_WANT_A_BROKEN_PS=yes
4export I_WANT_A_BROKEN_PS
5all=no
6if [ "x$1" = "x-a" ]
7then
8 all=yes
9fi
10export all
11
12cat >/tmp/awk.xxx$$ <<'!'
13BEGIN{
14 state["D"] = "Spinwait";
15 state["I"] = "Idle";
16 state["J"] = "Jail";
17 state["R"] = "Ready";
18 state["S"] = "Sleep";
19 state["T"] = "Stopped";
20 state["Z"] = "Zombie";
21 state["W"] = "Fault";
22 state["X"] = "Moribund";
23}
24
25function statestr(s)
26{
27 t = state[substr(s, 1, 1)];
28 if(t == "")
29 return s;
30 return t;
31}
32
33# rsc 36706 starttime 0:00.17 1076 Is+ -bash (bash)
34{
35 i=1
36 user=$i; i++
37 pid=$i; i++
38 start=$i; i++
39 if(start ~ /^[A-Z][a-z][a-z]$/){
40 start = start "-" $i; i++
41 }
42 cputime=$i; i++
43 mem=$i; i++
44 stat=$i; i++
45 cmd=$i; i++
46 if(ENVIRON["all"] == "yes"){
47 for(; i<=NF; i++)
48 cmd = cmd " " $i;
49 }else{
50 sub(/.*\//, "", cmd);
51 sub(/:$/, "", cmd);
52 sub(/^-/, "", cmd);
53 s = " " cmd;
54 }
55 sub(/\.[0-9][0-9]$/, "", cputime); # drop .hundredths of second
56 if(cputime ~ /..:..:../){ # convert hh:mm:ss into mm:ss
57 split(cputime, a, ":");
58 cputime = sprintf("%d:%02d", a[1]*60+a[2], a[3]);
59 }
60 if(start ~ /..:..:../){ # drop :ss
61 sub(/:..$/, "", start);
62 }
63 printf("%-8s %11d %8s %8s %8dK %-8s %s\n",
64 user, pid, start, cputime, mem, statestr(stat), cmd);
65}
66!
67
68/bin/ps -axww -o 'user,pid,start,time,vsz,stat,command' | sed 1d |
rscdbd7b9a2003-11-23 18:29:08 +000069 awk -f /tmp/awk.xxx$$ | sort -n +1
rsc629864f2003-10-13 18:25:28 +000070
71rm -f /tmp/awk.xxx$$
72