Strange as it seems, I can't find information how I can set a default nice value for a program (not for a user or a group!). I would like to start all chrome and firefox instances with a nice value of 10. What would be the most appropriate solution?
Asked
Active
Viewed 4,081 times
3 Answers
4
You have to work around a bit.
First get the full path of the firefox binary:
which firefox
/usr/bin/firefox
Now, move that to, for example, firefox-original:
mv /usr/bin/firefox /usr/bin/firefox-original
Now, create a small handler script called /usr/bin/firefox
that will be called instead of the original firefox binary:
cat /usr/bin/firefox
#!/bin/bash
exec nice - n 10 /usr/bin/firefox-original "$@"
Finally make the script executable:
chmod 755 /usr/bin/firefox
Now everytime firefox is started, that script executes the binary with a nice value of 10. The $@
just means to pass all the arguments of the script to the binary.
chaos
- 1,445
- 1
- 14
- 21
-
This should work. But what happens when I upgrade my firefox package (deb in my case)? – helcim Apr 17 '15 at 09:09
-
Yes, thats the problem you have to write the script again in that case, it doesn't survive a package update. – chaos Apr 17 '15 at 09:10
-
@helcim another attempt whould be to edit the file `/usr/share/applications/firefox.desktop`: the `Exec=` line. But that only works when you start firefox in a gui. That whould survive an update. – chaos Apr 17 '15 at 09:12
-
1@helcim: For Debian (and derivatives), you should use `dpkg-divert` to have the package manager put the packaged version elsewhere. – Cameron Kerr Apr 17 '15 at 09:23
-
"put elsewhere" is probably not what I want. I would like to set default nice value for a program once AND be able to upgrade as usual. – helcim Apr 17 '15 at 09:27
-
2@CameronKerr Good point, didn't think of that. It could be made by `dpkg-divert --local --rename --add /usr/bin/firefox --divert /usr/bin/firefox-original`. Then the package software places all new versions of the file to /usr/bin/firefox-original, so the problem of an update would be solved. – chaos Apr 17 '15 at 09:33
-
@chaos I see. It seems like the right solution, although I really hate to mess up with the package system more than it's absolutely necessary. – helcim Apr 17 '15 at 10:26
-
Unless firefox/chrome themselves don't provide configuration options to define a nice value, then unfortunately you have to do it that way. – chaos Apr 17 '15 at 10:28
3
Instead of messing up your /usr/bin
and getting hosed every update, why not use a ~/.local/bin
?
## one-time setup
mkdir -p ~/.local/bin
# prepend new path to PATH to give it priority
echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
# then open new terminal or
source ~/.bashrc
## create a wrapper script
# $@ is there to passthrough args.
echo 'nice -10' `which firefox` '$@' > ~/.local/bin/firefox
# make it executable
chmod +x ~/.local/bin/firefox
# check sanity
which firefox
cat `which firefox`
webb
- 154
- 3
-2
Create a keyboard short-cut that will execute the following command:
nohup firefox & renice +15 $(pgrep firefox)
This should work regardless of whether you upgrade.
Flaunk
- 9
- 1