Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know if it's possible to execute and renice a process in one command, i.e. without having to look up the command in the list of processes using the ps command and then renice that particular pid.

share|improve this question
Why don't you use nice when you launch the process, instead of renice afterwards? – glenn jackman Sep 8 '11 at 2:32
@Glenn-jackman your post it is practically the answer. – Torian Sep 8 '11 at 4:22
up vote 2 down vote accepted

As I mentioned, @glenn-jackman gave you the answer. But just to elaborate a bit more, if you wish to give higher priority to the command but do not intend to run it as root, you could use a function (and sudo):

nice_cmd() {
  PRIORITY=$1 ; shift
  CMD=$1 ; shift
  ${CMD} $@ & cmdpid=$!
  sudo renice -n ${PRIORITY} -p ${cmdpid}

Then execute it as (this could ask for your user password, depending on how is sudo configured)

$ nice_cmd -5 vim somefile
$ fg

And from a top on another terminal, you can double check the nice value.

share|improve this answer
You always want to enclose $@ in double quotes. You don't need to shift the command: PRI=$1; shift; "$@" & pid=$1; ... – glenn jackman Sep 8 '11 at 5:01
Agreed, but it is just a good measure to be more specific on how it works. – Torian Sep 8 '11 at 15:35
Just interested in the two downvotes, any further reason why ? – Torian Sep 9 '11 at 19:52

Just use nice (instead of renice). For example:

nice -n 10 command

This will run command with a low priority.

share|improve this answer

Linux process scheduling using nice and renice commands with examples can also be found at http://www.vmexplore.com/tuning-process-scheduling/

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

It is better to provide action information here, and use the link as a reference for further details. That way your answer does not lose all of it value when the link becomes invalid. – Anthon Apr 6 '14 at 17:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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