-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_scan
executable file
·127 lines (105 loc) · 2.78 KB
/
ps_scan
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
enable $( enable_ate )
source $( ate_sources ate_exit_on_error )
source $( ate_sources ate_print_formatted_table )
enable $( enable_pwb )
source $( pwb_sources pwb_exit_on_error )
get_proc_file_contents()
{
local -n gpfc_target="$1"
gpfc_target="StArTiNg"
local path="$2"
if [ -f "$path" ]; then
# gpfc_target=$(tr $'\000' $'\n' <$path)
# gpfc_target=$(<"$path")
IFS= read -r gpfc_target <"$path"
if [ "$?" -ne 0 ]; then
echo "Error reading contents of '${path:5}'"
fi
else
gpfc_target="?"
fi
}
# Called by get_cur_procs() for each process
get_proc_info()
{
local -n gpi_array="$1"
local proc_path="$2"
local procid="${file:6}"
local comm cmdline sessid
get_proc_file_contents cmdline "${proc_path}"/cmdline
get_proc_file_contents sessid "${proc_path}"/sessionid
get_proc_file_contents comm "${proc_path}"/comm
gpi_array=( "$procid" "$comm" "$sessid" "$cmdline" )
}
# Empty, then fill the table's array with the current processes
get_cur_procs()
{
local gcp_table="$1"
local gcp_arr_name
ate get_array_name "$gcp_table" -v gcp_arr_name
ate_exit_on_error
local -n gcp_array="$gcp_arr_name"
gcp_array=()
local -a proc_contents=( /proc/* )
local -a curproc
local file
for file in "${proc_contents[@]}"; do
if [[ "$file" =~ /proc/[[:digit:]]+$ ]]; then
get_proc_info curproc "$file"
echo "Adding: ${curproc[*]}"
gcp_array+=( "${curproc[@]}" )
fi
done
ate index_rows "$gcp_table"
ate_exit_on_error
}
display_print_line()
{
local -i index="$1"
local tname="$2"
local -i char_limit="$3"
local -a row
ate get_row "$tname" "$index" -a row
ate_exit_on_error
printf -v trow "%5d %-${char_limit}s" "${row[0]}" "${row[1]}"
printf "${trow:0:$char_limit}"
}
display_print_head()
{
local -i index="$1"
local tname="$2"
local -i char_limit="$3"
local -a row
ate get_row "$tname" "$index" -a row
ate_exit_on_error
printf -v trow "%5d %-${char_limit}s" "${row[@]:0:4}"
printf "${trow:0:$char_limit}"
}
display_info()
{
local -i row_count
local tname="$1"
ate get_row_count "$tname" -v row_count
ate_exit_on_error
local -a pwb_declare_args=(
"$tname"
"$row_count"
display_print_line
-t display_print_head
)
local di_display
pwb declare di_display "${pwb_declare_args[@]}"
pwb_exit_on_error
pwb set_margins di_display 3 10 0
pwb start di_display
}
# Establish variable 'proc_list' at global scope
declare proc_table
ate declare proc_table 4
ate_exit_on_error
# Fill table with process' information
get_cur_procs proc_table
pwb init
display_info proc_table
pwb restore