4 export I_WANT_A_BROKEN_PS
12 cat >/tmp/awk.xxx$$ <<'!'
14 state["D"] = "Spinwait";
18 state["O"] = "Running";
20 state["T"] = "Stopped";
21 state["Z"] = "Zombie";
23 state["X"] = "Moribund";
26 function statestr(s, wchan)
28 if(wchan != s && wchan != "?" && wchan != "-")
30 t = state[substr(s, 1, 1)];
36 # rsc 36706 starttime 0:00.17 1076 Is+ -bash (bash)
42 if(start ~ /^[A-Z][a-z][a-z]$/){
43 start = start "-" $i; i++
50 if(ENVIRON["all"] == "yes"){
59 sub(/\.[0-9][0-9]$/, "", cputime); # drop .hundredths of second
60 if(cputime ~ /..:..:../){ # convert hh:mm:ss into mm:ss
61 split(cputime, a, ":");
62 cputime = sprintf("%d:%02d", a[1]*60+a[2], a[3]);
64 if(start ~ /..:..:../){ # drop :ss
65 sub(/:..$/, "", start);
67 sub(/[ ]+$/, "", cmd);
68 line[0+nline++] = sprintf("%s\001%d\001%s\001%s\001%dK\001%s\001%s",
69 user, pid, start, cputime, mem, statestr(stat, wchan), cmd);
73 for(i=0; i<nline; i++){
74 split(line[i], a, "\001");
76 if(length(a[j]) > max[j])
77 max[j] = length(a[j]);
79 for(i=0; i<nline; i++){
80 split(line[i], a, "\001");
81 printf("%-*s %*s %*s %*s %*s %-*s %s\n",
82 max[1], a[1], max[2], a[2], max[3], a[3], max[4], a[4],
83 max[5], a[5], max[6], a[6], a[7]);
88 case "${SYSNAME:-`uname`}" in
90 /bin/ps -aA -o 'user,pid,stime,time,rss,s,s,args' | sed 1d |
91 nawk -f /tmp/awk.xxx$$ | sort -n +1
94 /bin/ps -axww -o 'user,pid,start,time,rss,stat,wchan,command' | sed 1d |
95 awk -f /tmp/awk.xxx$$ | sort -n +1