-
Notifications
You must be signed in to change notification settings - Fork 1
/
ps.bash
29 lines (24 loc) · 1.07 KB
/
ps.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# ps.bash by Derek Callaway < decal [AT] ethernet [D0T] org >
# Sun Sep 5 15:37:05 EDT 2010 DC/SO
#
# Displays variable values stored in the kernel's process table data structure and is
# capable of exposing PID's being hidden by infected bytecode in /bin/ps binaries.
alias uname='cat /proc/version' hostname='cat /proc/sys/kernel/hostname'
alias domainname='cat /proc/sys/kernel/domainname' vim='vi'
function uptime() {
declare loadavg=$(cat /proc/loadavg | cut -d' ' -f1-3)
let uptime=$(($(awk 'BEGIN {FS="."} {print $1}' /proc/uptime) / 60 / 60 / 24 ))
echo "up $uptime day(s), load average: $loadavg"
}
function ps() {
local file base pid state ppid uid
echo 'S USER UID PID PPID CMD'
for file in /proc/[0-9]*/status
do base=${file%/status} pid=${base#/proc/}
{ read _ st _; read _ ppid; read _ _ _ _ uid; } < <(egrep '^(State|PPid|Uid):' "$file")
IFS=':' read user _ < <(getent passwd $uid) || user=$uid
printf "%1s %-6s %5d %5d %5d %s\n" $st $user $uid $pid $ppid "$(tr \ \ <"$base/cmdline")"
done
}
#EOF#