- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
#!/bin/bash
ps -eo pid,ppid,comm > data
#treeNet[0]=1
depth=0
init=0
tree()
{
#echo $1
let depth=depth+1
treeNet[$depth]=1
for ((i=1;i<depth-1;i++))
do
# echo ${treeNet[$depth]}
if [[ ${treeNet[$i]} -eq 0 ]]
then
echo -n " "
fi
if [[ ${treeNet[$i]} -eq 1 ]]
then
echo -n "¦ "
fi
done
if [[ $init -ne 0 ]]
then
echo -n '¦====='
else
init=1
fi
#let depth=depth+1
# treeNet[depth]=1
#prints process name
echo $(cat data | awk '{ if ($1 == '$1') print $3}' )
#printing branches
local count=0 #amount of child branches
for i in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
do
let count=count+1
#echo $i
done
#recursive call tree()
local n=0;
for child in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
do
let n=n+1
# echo -n " # child no $n of $count depth $depth debug ${treeNet[1]} ${treeNet[2]} ${treeNet[3]} ${treeNet[4]}";
if [[ $n -eq $count ]]
then
#echo -n " last "
treeNet[$depth]=0
fi
# echo
# let n=n+1
tree $child
done
treeNet[$depth]=0
let depth=depth-1
return 0
}
tree 1
Dummy00001 21.10.2011 18:14 # +3
если так сильно хотелось процесы деревцом показывать, могли бы и pstree из psmisc проинсталировать.
guest 29.10.2011 16:43 # 0
guest 21.10.2011 19:35 # +2
istem 21.10.2011 20:15 # +2
guest 21.10.2011 20:30 # +2
guest 29.10.2011 16:25 # 0