Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Last active March 20, 2020 03:18
Show Gist options
  • Save bugcy013/12c15414e7e2c6e9cf6813c36b727f1a to your computer and use it in GitHub Desktop.
Save bugcy013/12c15414e7e2c6e9cf6813c36b727f1a to your computer and use it in GitHub Desktop.
Change Process scheduling to Realtime scheduler
#!/usr/bin/env bash
print_usage() {
echo "Usage: $( basename $1 ) <process name> <SCHED_FIFO | SCHED_RR> <priority (1-99)>"
}
if [ $# != 3 ]; then
print_usage $0
exit 1
fi
process_name=$1
sched_policy=$2
let priority=$3
if [ "$sched_policy" == "SCHED_FIFO" ]; then
sched_flag="-f"
elif [ "$sched_policy" == "SCHED_RR" ]; then
sched_flag="-r"
else
print_usage $0
exit 2
fi
if [ $priority -lt 1 ] || [ $priority -gt 99 ]
then
print_usage $0
exit 3
fi
PIDS=$( ps -e | grep $process_name | grep -o '^[[:space:]]*[[:digit:]]\+\>' )
for i in $PIDS; do
echo "$1 PID: $i"
chrt $sched_flag -p $priority $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment