Skip to main content
Topic: Nice value works only for low priority (Read 1131 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Nice value works only for low priority

Hello guys, trying to make a simple bash script and i want to set a higher priority for some process. For example i want to start my screen saver very fast to have my screen blanked as faster i can. So for this i have this command "xfce4-screensaver-command -a" but when i try to change nice value to (max) -20 ex. nice -n -20 gnome calculator i get permission denied. I can change priority to a lower value but for a higher value it gives me that. How can i start my commands with higher priority?

Re: Nice value works only for low priority

Reply #1
https://www.gnu.org/software/coreutils/manual/html_node/nice-invocation.html#nice-invocation

This is by design, otherwise normal users could clog the system with high priority processes.

You could run the script with privilege escalation program like sudo or doas (recommended). With doas, you can even specify that some users don't have to enter password for root access.

Re: Nice value works only for low priority

Reply #2
So i should start my screensaver with sudo? I think it will not light back again if i execute it as root. Not very nice from nice to do that

Re: Nice value works only for low priority

Reply #3
So i should start my screensaver with sudo? I think it will not light back again if i execute it as root. Not very nice from nice to do that
You could execute
Code: [Select]
$ xhost +si:localuser:root
to allow the root user to connect to X display, otherwise you cannot lower the niceness of any program as non-root, your screensaver included. Only root is allowed to do that.

Again, this is by design. Unix (and thus GNU/Linux) were since the start multi-user environments, meaning that multiple users can be logged in the same machine at the same time. If everyone was able to give their programs high priority, that would be a recipe for disaster. Effectively the computer would hang.

Re: Nice value works only for low priority

Reply #4
I can set low priority as user but not high priority. Wonder why? Computer would not hang if processes get low priority? Think we both miss some knowledge about this aspect  :-\

Re: Nice value works only for low priority

Reply #5
I can set low priority as user but not high priority. Wonder why? Computer would not hang if processes get low priority? Think we both miss some knowledge about this aspect  :-\
Priority is the inverse of niceness. A "high priority" process is "not nice" (aka it has negative niceness) and vice versa.

https://en.wikipedia.org/wiki/Nice_%28Unix%29

Re: Nice value works only for low priority

Reply #6
So i can change niceness but i can't easily change nastyness


Re: Nice value works only for low priority

Reply #8
You're right but i still can't understand without being sarcastic or other bs why can't nice value be set other way than runing as root? If i'm allowed to execute programms why i can't set them my desired nice value?

Re: Nice value works only for low priority

Reply #9
You're right but i still can't understand without being sarcastic or other bs why can't nice value be set other way than runing as root? If i'm allowed to execute programms why i can't set them my desired nice value?

Login as "root", then you can do whatever you want. LIKE A BOSS!  :D


Re: Nice value works only for low priority

Reply #11
You're right but i still can't understand without being sarcastic or other bs why can't nice value be set other way than runing as root? If i'm allowed to execute programms why i can't set them my desired nice value?
Unlike your PC, some people still work on multi-user computers. Imagine what would happen if some fella over there ran a CPU cryptocoin miner at the maximum niceness of -20: others would literally have to wait for a simple "ls" to execute. That being said, on your own single-user PC you won't see measurable difference in performance if you run a task at -20 niceness vs default 0, except perhaps in the reduced responsiveness of your choking desktop environment.

TL;DR: in both UNIX-like and windows, only a superuser can elevate task priority.

Re: Nice value works only for low priority

Reply #12
Perhaps you could do something with PAM or groups or something like that, for example you can have a group that can do some specific privileged task then make yourself a part of that group, and rather than launch the thing as root, use the root powers of this new group you are in to renice it when it's started? There are various desktop permission things about. cgroups might also help, as an alternative to nice - libcgroup and so on.

 

Re: Nice value works only for low priority

Reply #13
Thank you for solutions, i will try that cgroup/group approach