Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
Created September 26, 2012 01:40
Show Gist options
  • Save ryo1kato/3785504 to your computer and use it in GitHub Desktop.
Save ryo1kato/3785504 to your computer and use it in GitHub Desktop.
A wrapper to allow sudo chrt for synergys
#!/bin/bash
#
# Give sudo right to run chrt for giving RT prio for synergys
# (relatively) safely to avoid delay of cursor or
# keyboard input in remote end.
#
# So far scheduler (SCHED_RR) and prio (50) is hard-coded.
synergys_exepath="/usr/bin/synergys"
targetpid="$1"
DIE () {
echo "ERROR: $*" >&2
exit 1
}
# Check if argument is numeric
if [ -z "$targetpid" -o -n "${targetpid//[0-9]/}" ]
then
DIE "Invalid PID number: $targetpid"
fi
if [ ! -d /proc/$targetpid ]
then
DIE "No process with PID=$targetpid running"
elif [ ! -r /proc/$targetpid/exe ]
then
DIE "You are not the owner of process PID=$targetpid"
elif [ "$(readlink /proc/$targetpid/exe)" != "$synergys_exepath" ]
then
DIE "The PID you gave ($targetpid) is not for synergys"
fi
echo sudo /usr/bin/chrt --rr -p 50 $targetpid
@ryo1kato
Copy link
Author

USERNAME ALL=NOPASSWD:/usr/local/bin/chrt-synergys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment