BEGIN {
fhdr = fdst = pidst = 0;
access = dev = devch = fd = inode = lock = name = offset = "";
proto = size = state = stream = type = "";
cmd = login = pgrp = pid = ppid = uid = "";
}
/^p/ {
val = substr($0, 2);
if (pidst) {
printf "COMMAND PID PGRP PPID USER\n";
printf "%-9.9s %6d %6d %6d", cmd, pid, pgrp, ppid;
if (login != "") { printf " %s\n", login }
else { printf " %s\n", uid }
pidst = 0;
cmd = login = pgrp = pid = uid = "";
}
if (fdst) {
if (fhdr == 0) {
printf " FD TYPE DEVICE SIZE/OFF INODE NAME\n";
}
printf " %4.4s%1.1s%1.1s %4.4s", fd, access, lock, type;
t = dev; if (devch != "") { t = devch }
printf(" %10.10s", t);
t = size; if (offset != "") { t = offset }
printf " %10.10s", t;
t = inode; if (proto != "") { t = proto }
printf " %10.10s", t;
t = stream; if (name != "") {t = name }
printf " %s", t;
if (state != "") { printf " %s)\n", state } else { printf "\n" }
access = dev = devch = fd = inode = lock = name = offset = "";
proto = size = state = stream = type = "";
fdst = fhdr = 0
}
pidst = 1;
pid = val;
}
/^g|^c|^u|^L|^R/ {
id = substr($0, 1, 1);
val = substr($0, 2);
if (id == "g") { pgrp = val; next } if (id == "c") { cmd = val; next } if (id == "u") { uid = val; next } if (id == "L") { login = val; next } if (id == "R") { ppid = val; next } }
/^f|^a|^l|^t|^d|^D|^s|^o|^i|^P|^S|^T|^n/ {
id = substr($0, 1, 1);
val = substr($0, 2);
if (id == "f") {
if (pidst) {
printf "COMMAND PID PGRP PPID USER\n";
printf "%-9.9s %6d %6d %6d", cmd, pid, pgrp, ppid;
if (login != "") { printf " %s\n", login }
else { printf " %s\n", uid }
pidst = 0;
cmd = login = pgrp = pid = uid = "";
}
if (fdst) {
if (fhdr == 0) {
printf " FD TYPE DEVICE SIZE/OFF INODE NAME\n";
}
fhdr = 1;
printf " %4.4s%1.1s%1.1s %4.4s", fd, access, lock, type;
t = dev; if (devch != "") { t = devch }
printf(" %10.10s", t);
t = size; if (offset != "") { t = offset }
printf " %10.10s", t;
t = inode; if (proto != "") { t = proto }
printf " %10.10s", t;
t = stream; if (name != "") {t = name }
printf " %s", t;
if (state != "") { printf " %s)\n", state } else { printf "\n" }
access = dev = devch = fd = inode = lock = name = offset = "";
proto = size = state = stream = type = "";
}
fd = val;
fdst = 1;
next;
}
if (id == "a") { access = val; next } if (id == "l") { lock = val; next } if (id == "t") { type = val; next } if (id == "d") { devch = val; next } if (id == "D") { dev = val; next } if (id == "s") { size = val; next } if (id == "o") { offset = val; next } if (id == "i") { inode = val; next } if (id == "P") { proto = val; next } if (id == "S") { stream = val; next } if (id == "T") { if (state == "") {
state = sprintf("(%s", val);
} else {
state = sprintf("%s %s", state, val);
}
next
}
if (id == "n") { name = val; next } }
END {
if (pidst) {
printf "COMMAND PID PGRP PPID USER\n";
printf "%-9.9s %6d %6d %6d", cmd, pid, pgrp, ppid;
if (login != "") { printf " %s\n", login }
else { printf " %s\n", uid }
}
if (fdst) {
if (fhdr == 0) {
printf " FD TYPE DEVICE SIZE/OFF INODE NAME\n";
}
printf " %4.4s%1.1s%1.1s %4.4s", fd, access, lock, type;
t = dev; if (devch != "") { t = devch }
printf(" %10.10s", t);
t = size; if (offset != "") { t = offset }
printf " %10.10s", t;
t = inode; if (proto != "") { t = proto }
printf " %10.10s", t;
t = stream; if (name != "") {t = name }
printf " %s", t;
if (state != "") { printf " %s)\n", state; } else { printf "\n"; }
}
}