-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswappiness
More file actions
executable file
·19 lines (17 loc) · 989 Bytes
/
swappiness
File metadata and controls
executable file
·19 lines (17 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
for dir in `ls -ad /proc/{1..9}*`;
do
# check to see if the smaps file is there and if the 'Swap' variable is in the file
# I wanted to check if the file was not empty but all smaps files show a size of 0
if [ -f "$dir/smaps" -a -n "`grep -i swap $dir/smaps | head -1`" ]; then
pid=`echo $dir | cut -d / -f3`
process=`ps -p $pid -o comm --no-headers`
echo -n "$process : "
awk '/Swap/{sum+=$2}END{print sum}' $dir/smaps | column -t
fi
done
# Show the total from all the processes running at the end.
echo -en "\nTotal : "
awk '/Swap/{sum+=$2}END{print sum}' /proc/*/smaps | column -t
## One Liner
# for dir in `ls -ad /proc/{1..9}*`; do if [ -f "$dir/smaps" -a -n "`grep -i swap $dir/smaps | head -1`" ]; then pid=`echo $dir | cut -d / -f3`; process=`ps -p $pid -o comm --no-headers`; echo -n "$process : "; awk '/Swap/{sum+=$2}END{print sum}' $dir/smaps | column -t; fi; done; echo -en "\nTotal : "; awk '/Swap/{sum+=$2}END{print sum}' /proc/*/smaps | column -t