Credits: cron.daily/mlocate
, replace $$
with PID of process.
renice +19 -p $$ >/dev/null 2>&1
ionice -c2 -n7 -p $$ >/dev/null 2>&1
However, these days on distributions with systemd, nice value mostly works for interactive sessions, but it no longer works globally. See Revisiting Linux CPU scheduling.