Run the command using /usr/bin/nice . For instance:
$ /usr/bin/nice -n 10 somecommand arg1 arg2
somecommand arg1 arg2 will be executed with a value of +10. (On Unix / Linux, a higher value results in a lower priority for the scheduler. The nice range is usually from -19 to +19.)
Please note that this solution is platform specific. It will only work on Linux and Unix systems ...
FOLLOW UP
ProcessBuilder should be created like any normal command; i.e.
new ProcessBuilder("nice", "-n", "10", "somecommand", "arg1", "arg2");
There is no black magic about when / how to split commands / arguments. The command syntax (for example, nice ) determines what its arguments should be, and determines how they should be indicated on the shell command line and how they should be provided when using ProcessBuilder (or the built-in exec* system calls, this is important).
I don't think there should be problems with waitFor() , etc., because (AFAIK) the /usr/bin/nice command uses exec (not fork / exec ) to run the provided command. Try it ...
source share