This one fails:
nice -n 10 exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"
this succeeds:
nice -n 10 java test
Does it mean can't combine nice and exec?
This one fails:
nice -n 10 exec "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"
this succeeds:
nice -n 10 java test
Does it mean can't combine nice and exec?
Try:
nice -n 10 sh -c 'exec $JAVA $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"'
exec is not an executable. I'm really not sure why you'd need to do this, though.
I'm really sure it's going to be
exec nice -n 10 "$JAVA" $JAVA_HEAP_MAX $NUTCH_OPTS -classpath "$CLASSPATH" $CLASS "$@"
Think about what it is that exec will be doing (replacing the currently running process), you can adjust the process priority separately, i.e. using top or by using renice from another process.
You can't directly nice exec because exec is a builtin and not a separate executable.
Nice is a program which takes in another program and runs it. It doesn't filter that program through your shell, so it will not work on shell builtins like exec.
However, there is a more fundamental problem!
Nice (the system call) is specifically problematic in that it needs to be a separate process -- since a (non-root) process can't decrease its niceness, it can't just just "increase my niceness, execute, decrease".
As such what you're trying to do would not do what you think it would do. The exec would turn the nice process into java... which is already what happens when you run nice without any exec! The existing shell would continue running.
This would be the case even if nice were a shell builtin.
If you actually want to do this, you either need to directly increase the shell's own niceness, or try to simulate the exec by nohup (or similar) the nice process and then exiting the original shell.