-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini-process-controller.sh
executable file
·59 lines (49 loc) · 1.25 KB
/
mini-process-controller.sh
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
#!/bin/bash
while [ -n "$1" ]; do
case "$1" in
-h|--help)
echo "[-t] or [--time] Enter time period"
echo "[-n] or [--name] Enter process name"
echo "[-p] or [--priority] Enter process priority"
exit 0;;
-n|--name)
process_name="$2"
shift 2;;
-p|--priority)
process_priority="$2"
shift 2;;
-t|--time)
time_sleep="$2"
shift 2;;
*)
echo "Unknown parameter: $1"
exit 1;;
esac
done
if [ -z "$process_name" ]; then
echo "Error: Process name (-n) not specified"
exit 1
fi
if [ -z "$process_priority" ]; then
echo "Error: Priority (-p) not specified"
exit 1
fi
if [ -z "$time_sleep" ]; then
echo "Error: time period (-t) not specified"
exit 1
fi
while true; do
valid_processes=$(ps -e -o comm)
if echo "$valid_processes" | grep -qw "$process_name"; then
process_pid=$(pidof $process_name)
for pid in $process_pid; do
sudo renice $process_priority -p $pid
done
echo "Priority $process_priority set for $process_name"
printf '%*s\n' 20 | tr ' ' '*'
sleep $time_sleep
else
echo "$process_name: Process not found"
break
fi
done