-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
44 lines (36 loc) · 893 Bytes
/
utils.sh
File metadata and controls
44 lines (36 loc) · 893 Bytes
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
#!/bin/bash
# ABOUT:
# Collection of util functions
# returns the name of the current script, without the extension.
function scriptname() {
local filename="$(basename \"$0\")"
echo "${filename%.*}"
}
# runs self with changed niceness
renice_self() {
local target_niceness=10
local pid=$BASHPID
# echo "my pid is ${pid}"
local niceness=$(ps -x -o pid,ni | rg ${pid} | awk '{print $2}')
# echo "my niceness is ${niceness}"
if ! [ ${niceness} -eq ${target_niceness} ]; then
renice +${target_niceness} -p ${pid} >/dev/null
local new_niceness=$(ps -x -o pid,ni | rg ${pid} | awk '{print $2}')
# echo "my (new) niceness is ${new_niceness}"
fi
echo ">> running with niceness 10"
}
# 1 -> 01
# 10 -> 10
function padded() {
local i=$1
if [ "$i" -lt 10 ]; then
echo "0${i}"
else
echo "${i}"
fi
}
# echo to stderr instead of stdout
function echoerr() {
echo "$@" 1>&2
}