mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
Some Plan 9 workalikes.
This commit is contained in:
parent
771ff2bc05
commit
629864f582
4 changed files with 107 additions and 0 deletions
6
bin/kill
Executable file
6
bin/kill
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
for i
|
||||
do
|
||||
psu | awk '$NF ~ /^('$i')$/ {printf("/bin/kill %d # %s\n", $2, $0);}'
|
||||
done
|
72
bin/ps
Executable file
72
bin/ps
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/sh
|
||||
|
||||
I_WANT_A_BROKEN_PS=yes
|
||||
export I_WANT_A_BROKEN_PS
|
||||
all=no
|
||||
if [ "x$1" = "x-a" ]
|
||||
then
|
||||
all=yes
|
||||
fi
|
||||
export all
|
||||
|
||||
cat >/tmp/awk.xxx$$ <<'!'
|
||||
BEGIN{
|
||||
state["D"] = "Spinwait";
|
||||
state["I"] = "Idle";
|
||||
state["J"] = "Jail";
|
||||
state["R"] = "Ready";
|
||||
state["S"] = "Sleep";
|
||||
state["T"] = "Stopped";
|
||||
state["Z"] = "Zombie";
|
||||
state["W"] = "Fault";
|
||||
state["X"] = "Moribund";
|
||||
}
|
||||
|
||||
function statestr(s)
|
||||
{
|
||||
t = state[substr(s, 1, 1)];
|
||||
if(t == "")
|
||||
return s;
|
||||
return t;
|
||||
}
|
||||
|
||||
# rsc 36706 starttime 0:00.17 1076 Is+ -bash (bash)
|
||||
{
|
||||
i=1
|
||||
user=$i; i++
|
||||
pid=$i; i++
|
||||
start=$i; i++
|
||||
if(start ~ /^[A-Z][a-z][a-z]$/){
|
||||
start = start "-" $i; i++
|
||||
}
|
||||
cputime=$i; i++
|
||||
mem=$i; i++
|
||||
stat=$i; i++
|
||||
cmd=$i; i++
|
||||
if(ENVIRON["all"] == "yes"){
|
||||
for(; i<=NF; i++)
|
||||
cmd = cmd " " $i;
|
||||
}else{
|
||||
sub(/.*\//, "", cmd);
|
||||
sub(/:$/, "", cmd);
|
||||
sub(/^-/, "", cmd);
|
||||
s = " " cmd;
|
||||
}
|
||||
sub(/\.[0-9][0-9]$/, "", cputime); # drop .hundredths of second
|
||||
if(cputime ~ /..:..:../){ # convert hh:mm:ss into mm:ss
|
||||
split(cputime, a, ":");
|
||||
cputime = sprintf("%d:%02d", a[1]*60+a[2], a[3]);
|
||||
}
|
||||
if(start ~ /..:..:../){ # drop :ss
|
||||
sub(/:..$/, "", start);
|
||||
}
|
||||
printf("%-8s %11d %8s %8s %8dK %-8s %s\n",
|
||||
user, pid, start, cputime, mem, statestr(stat), cmd);
|
||||
}
|
||||
!
|
||||
|
||||
/bin/ps -axww -o 'user,pid,start,time,vsz,stat,command' | sed 1d |
|
||||
awk -f /tmp/awk.xxx$$ | sort +1 -n
|
||||
|
||||
rm -f /tmp/awk.xxx$$
|
||||
|
23
bin/psu
Executable file
23
bin/psu
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/sh
|
||||
|
||||
flag=''
|
||||
if [ "x$1" = "x-a" ]
|
||||
then
|
||||
flag=-a
|
||||
shift
|
||||
fi
|
||||
|
||||
user=`whoami`
|
||||
case $# in
|
||||
0)
|
||||
user=`whoami`
|
||||
;;
|
||||
1)
|
||||
user=$1
|
||||
;;
|
||||
*)
|
||||
echo 'usage: psu [-a] [user]' 1>&2
|
||||
exit 1
|
||||
esac
|
||||
|
||||
ps $flag | grep "^$user "
|
6
bin/slay
Executable file
6
bin/slay
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
for i
|
||||
do
|
||||
psu | awk '$NF ~ /^('$i')$/ {printf("/bin/kill -9 %d # %s\n", $2, $0);}'
|
||||
done
|
Loading…
Reference in a new issue