Mac Developer Library Developer
Search

 

This manual page is part of Xcode Tools version 5.0

To obtain these tools:

If you are running a version of Xcode Tools other than 5.0, view the documentation locally:

  • In Xcode

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

  • To learn how the manual is organized or to learn about command syntax, read the manual page for manpages(5).

  • For more information about this technology, look for other documentation in the Apple Developer Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.




GETPRIORITY(2)              BSD System Calls Manual             GETPRIORITY(2)

NAME
     getpriority, setpriority -- get/set program scheduling priority

SYNOPSIS
     #include <sys/resource.h>

     int
     getpriority(int which, id_t who);

     int
     setpriority(int which, id_t who, int prio);

DESCRIPTION
     The scheduling priority of the process, process group, or user as indicated by which and who is
     obtained with the getpriority() call and set with the setpriority() call.  Which is one of
     PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and who is interpreted relative to which (a process identifier
     for PRIO_PROCESS, process group identifier for PRIO_PGRP, and a user ID for PRIO_USER).  A zero value
     of who denotes the current process, process group, or user.  prio is a value in the range -20 to 20.
     The default priority is 0; lower priorities cause more favorable scheduling.

     The getpriority() call returns the highest priority (lowest numerical value) enjoyed by any of the
     specified processes.  The setpriority() call sets the priorities of all of the specified processes to
     the specified value.  Only the super-user may lower priorities.

     Additionally, the current thread or process can be placed in a background state by specifying PRIO_DAR-WIN_THREAD PRIO_DARWIN_THREAD
     WIN_THREAD or PRIO_DARWIN_PROCESS for which.  Only a value of zero (the current thread or process) is
     supported for who when setting or getting background state.  prio is either 0 (to remove current thread
     from background status) or PRIO_DARWIN_BG (to set current thread into background state).  When a thread
     or process is in a background state the scheduling priority is set to the lowest value, disk IO is
     throttled (with behavior similar to using setiopolicy_np(3) to set a throttleable policy), and network
     IO is throttled for any sockets opened after going into background state.  Any previously opened sock-ets sockets
     ets are not affected.  The getpriority() call returns 0 when current thread or process is not in back-ground background
     ground state or 1 when the current thread is in background state.  Any thread or process can set itself
     into background state.

RETURN VALUES
     Since getpriority() can legitimately return the value -1, it is necessary to clear the external vari-able variable
     able errno prior to the call, then check it afterward to determine if a -1 is an error or a legitimate
     value.  The setpriority() call returns 0 if there is no error, or -1 if there is.

ERRORS
     Getpriority() and setpriority() will fail if:

     [EINVAL]           Which is not one of PRIO_PROCESS, PRIO_PGRP, PRIO_USER, PRIO_DARWIN_THREAD, or
                        PRIO_DARWIN_PROCESS.

     [EINVAL]           Who is not a valid process, process group, or user ID.

     [EINVAL]           Who is not 0 when which is PRIO_DARWIN_THREAD or PRIO_DARWIN_PROCESS.

     [ESRCH]            No process can be located using the which and who values specified.

     In addition to the errors indicated above, setpriority() will fail if:

     [EACCES]           A non super-user attempts to lower a process priority.

     [EPERM]            A process is located, but neither its effective nor real user ID matches the effec-tive effective
                        tive user ID of the caller.

LEGACY SYNOPSIS
     #include <sys/types.h>
     #include <sys/resource.h>

     The include file <sys/types.h> is necessary.

     int
     getpriority(int which, int who);

     int
     setpriority(int which, int who, int value);

     The type of who has changed.

SEE ALSO
     nice(1), fork(2), setiopolicy_np(3), compat(5), renice(8)

HISTORY
     The getpriority() function call appeared in 4.2BSD.

4th Berkeley Distribution        June 4, 1993        4th Berkeley Distribution

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation with the feedback links below.
Bug reports
Report bugs in the functionality of the described tool or API through Bug Reporter.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.

Feedback