R: Get or Set the Priority (Niceness) of a Process

psnice {tools} | R Documentation

## Get or Set the Priority (Niceness) of a Process

### Description

Get or set the ‘niceness’ of the current process, or one or more other processes.

### Usage

    psnice(pid = Sys.getpid(), value = NA_integer_)

### Arguments

`pid` | positive integers: the process IDs of one of more processes: defaults to the R session process.
`value` | The niceness to be set, or `NA` for an enquiry.

### Details

POSIX operating systems have a concept of process priorities, usually from 0 to 39 (or 40) with 20 being a normal priority and (somewhat confusingly) larger numeric values denoting lower priority. To add to the confusion, there is a ‘niceness’ value, the amount by which the priority numerically exceeds 20 (which can be negative). Processes with high niceness will receive less CPU time than those with normal priority. On some OSes, processes with niceness `+19` are only run when the system would otherwise be idle.

On many OSes utilities such as `top` report the priority and not the niceness. Niceness is used by the utility ‘/usr/bin/renice’: ‘/usr/bin/nice’ (and `/usr/bin/renice -n`) specifies an increment in niceness.

Only privileged users (usually super-users) can lower the niceness.

Windows has a slightly different concept of ‘priority classes’. We have mapped the idle priority to niceness `19`, ‘below normal’ to `15`, normal to `0`, ‘above normal’ to `-5` and ‘realtime’ to `-10`. Unlike Unix-alikes, a non-privileged user can increase the priority class on Windows (but using ‘realtime’ is inadvisable).

### Value

An integer vector of previous niceness values, `NA` if unknown for any reason.

### See Also

Various functions in package parallel create child processes whose priority may need to be changed.

`pskill`.

[Package tools version 3.1.2 Index]