I want a launch-time script to find a game process after it starts and change its niceness. With Proton, the process I need to adjust may not be the launcher process. What approach is least likely to target the wrong thing?
What’s a safe way to renice a game when I don’t know its PID?
Answers
For a basic version, pass the process name as an argument, then poll for it for a few seconds with pgrep. Use pgrep -x "$name" for an exact process-name match, and only run renice -n -10 -p "$pid" if you found exactly one PID. If you find none, keep waiting until a timeout; if you find several, stop and report the ambiguity instead of changing all of them.
One catch: Linux process names can be truncated, and the game process name may differ from the title shown in the launcher. Check the matches manually first. Also, setting a negative nice value usually needs elevated privilege, so the script may fail unless it has an appropriate permission setup.
Reply to this answer
Before adding PID hunting, try launching the game through a wrapper that sets the nice value before starting the command. Child processes normally inherit their parent’s niceness, so this can cover more of the process tree without guessing a name. It may not help if a launcher or game changes its own niceness, which could explain why the behavior differs for some Proton setups.
If you do need renice afterward, treat the launcher's PID and the actual game PID as separate things. A wrapper can track the process it starts, but that process might only be a parent of the game, not the game itself.
Reply to this answer
Use pgrep as a way to inspect candidates, not as proof that a match is the right game. Matching the full command line with pgrep -f can accidentally match the search script itself or an unrelated process. A safer script checks one candidate at a time, prints what it found, and refuses to act when the match is not unique.
Also quote the supplied name as a normal argument and avoid eval. If you share the script with others, make the process name and timeout configurable, and show a clear error when the process never appears.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions