-
-
Save filipeamoreira/fc080f68ffbdc36e33e6f7dcb1fc2ae5 to your computer and use it in GitHub Desktop.
Renice a process and all of its children recursively, passing both the nice value and the pid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This can be run simply by passing it the outputs from pgrep: | |
# my_renice 10 $(pgrep application) | |
# | |
# You may also want to use pgrep to find more complex processes based on arguments | |
# my_renice 10 $(pgrep -f "bash.*$name") | |
function my_renice(){ | |
newnice=$1 | |
pid=$2 | |
# Return if pid not found | |
if [ -z $pid ]; then return; fi | |
# Renice pid right away in case we spawn more children | |
renice $newnice $pid | |
# Find children pids | |
children=$(pgrep -d ' ' -P $pid) | |
# Loop through children | |
for i in $children; do my_renice $newnice $i; done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment