I want to give a program I'm running in linux priority over other programs. I have sudo access and tried using sudo and the nice command. Specifically I ran a bash script file called RUN.sh that has the command

nice --10 nohup mpirun -np 1 ${bin}/pw.x < Cu8.30nc.crystal.in > Cu8.30nc.crystal.out

so I typed sudo RUN.sh and mpirun says it detects I'm running as root and this is very dangerous. The error message says:

mpirun has detected an attempt to run as root. Running at root is strongly discouraged as any mistake (e.g., in defining TMPDIR) or bug can result in catastrophic damage to the OS file system, leaving your system in an unusable state.

You can override this protection by adding the --allow-run-as-root option to your cmd line. However, we reiterate our strong advice against doing so - please do so at your own risk.

Basically I want to know if there is a way to give a program priority without risking the system like this. Thanks in advance for any help.

  • what do you mean by priority over other programs? – jsotola Oct 20 '19 at 18:24

You can run it as your non-privileged user, then re-nice it as root:

$ sleep 100 &
[1] 8128
$ ps -fu steeldriver | grep [s]leep
steeldriver   8128  4353  0 14:54 pts/1    00:00:00 sleep 100

$ sudo renice -10 8128
8128 (process ID) old priority 0, new priority -10

Confirm that the process owner is not changed by re-nicing:

$ ps -fu steeldriver | grep [s]leep
steeldriver   8128  4353  0 14:54 pts/1    00:00:00 sleep 100

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.