Advertisement
devinteske

psrogues

Oct 6th, 2023 (edited)
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/bin/sh
  2. ps axo pid,ppid,comm | awk '
  3.     BEGIN {
  4.         getline # remove header
  5.         ign["containerd-shim"]
  6.         ign["sge_execd"]
  7.         ign["sge_shepherd"]
  8.         ign["squashfuse_ll"]
  9.     }
  10.     $2 == 1 && !($3 in ign) { print (pid = $1) }
  11. ' | xargs -r ps o pid,command | awk -v skip=$$ '
  12.     BEGIN {
  13.         getline # header
  14.         match($0, /COMMAND/) # column
  15.         comm = RSTART # position
  16.     }
  17.     function pstree(pid,        cmd, line, child, sp)
  18.     {
  19.         sp = ""
  20.         cmd = sprintf("pstree -ap %d", pid)
  21.         while (cmd | getline line > 0) {
  22.             if (sp != "") {
  23.                 if (substr(line, 1, length(sp)) == sp) continue
  24.                 else sp = ""
  25.             }
  26.             if (!match(line, /,[0-9]+/)) continue
  27.             child = substr(line, RSTART + 1, RLENGTH - 1)
  28.             if (child == skip) {
  29.                 skip = 0
  30.                 sp = line
  31.                 gsub(/[`-].*/, "", sp)
  32.             } else print child
  33.             line = substr(line, RSTART + RLENGTH)
  34.         }
  35.         close(cmd)
  36.     }
  37.     { print pstree(pid = $1) }
  38. ' | xargs -r ps fo pid,uid | awk '
  39.     BEGIN { getline } # remove header
  40.     $2 > 1000 { print $1 }
  41. ' | xargs -r ps ${*:-uf}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement