GETPRIORITY(3)             POSIX Programmer's Manual            GETPRIORITY(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       getpriority, setpriority -- get and set the nice value

SSYYNNOOPPSSIISS
       #include <sys/resource.h>

       int getpriority(int _w_h_i_c_h, id_t _w_h_o);
       int setpriority(int _w_h_i_c_h, id_t _w_h_o, int _v_a_l_u_e);

DDEESSCCRRIIPPTTIIOONN
       The _g_e_t_p_r_i_o_r_i_t_y() function shall obtain the nice value of a process,
       process group, or user. The _s_e_t_p_r_i_o_r_i_t_y() function shall set the nice
       value of a process, process group, or user to _v_a_l_u_e+{NZERO}.

       Target processes are specified by the values of the _w_h_i_c_h and _w_h_o
       arguments. The _w_h_i_c_h argument may be one of the following values:
       PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, indicating that the _w_h_o argument
       is to be interpreted as a process ID, a process group ID, or an
       effective user ID, respectively. A 0 value for the _w_h_o argument
       specifies the current process, process group, or user.

       The nice value set with _s_e_t_p_r_i_o_r_i_t_y() shall be applied to the process.
       If the process is multi-threaded, the nice value shall affect all
       system scope threads in the process.

       If more than one process is specified, _g_e_t_p_r_i_o_r_i_t_y() shall return value
       {NZERO} less than the lowest nice value pertaining to any of the
       specified processes, and _s_e_t_p_r_i_o_r_i_t_y() shall set the nice values of all
       of the specified processes to _v_a_l_u_e+{NZERO}.

       The default nice value is {NZERO}; lower nice values shall cause more
       favorable scheduling. While the range of valid nice values is
       [0,{NZERO}*2-1], implementations may enforce more restrictive limits.
       If _v_a_l_u_e+{NZERO} is less than the system's lowest supported nice value,
       _s_e_t_p_r_i_o_r_i_t_y() shall set the nice value to the lowest supported value;
       if _v_a_l_u_e+{NZERO} is greater than the system's highest supported nice
       value, _s_e_t_p_r_i_o_r_i_t_y() shall set the nice value to the highest supported
       value.

       Only a process with appropriate privileges can lower its nice value.

       Any processes or threads using SCHED_FIFO or SCHED_RR shall be
       unaffected by a call to _s_e_t_p_r_i_o_r_i_t_y().  This is not considered an
       error. A process which subsequently reverts to SCHED_OTHER need not
       have its priority affected by such a _s_e_t_p_r_i_o_r_i_t_y() call.

       The effect of changing the nice value may vary depending on the
       process-scheduling algorithm in effect.

       Since _g_e_t_p_r_i_o_r_i_t_y() can return the value -1 upon successful completion,
       it is necessary to set _e_r_r_n_o to 0 prior to a call to _g_e_t_p_r_i_o_r_i_t_y().  If
       _g_e_t_p_r_i_o_r_i_t_y() returns the value -1, then _e_r_r_n_o can be checked to see if
       an error occurred or if the value is a legitimate nice value.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _g_e_t_p_r_i_o_r_i_t_y() shall return an integer in
       the range -{NZERO} to {NZERO}-1.  Otherwise, -1 shall be returned and
       _e_r_r_n_o set to indicate the error.

       Upon successful completion, _s_e_t_p_r_i_o_r_i_t_y() shall return 0; otherwise, -1
       shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _g_e_t_p_r_i_o_r_i_t_y() and _s_e_t_p_r_i_o_r_i_t_y() functions shall fail if:

       EESSRRCCHH  No process could be located using the _w_h_i_c_h and _w_h_o argument
              values specified.

       EEIINNVVAALL The value of the _w_h_i_c_h argument was not recognized, or the value
              of the _w_h_o argument is not a valid process ID, process group ID,
              or user ID.

       In addition, _s_e_t_p_r_i_o_r_i_t_y() may fail if:

       EEPPEERRMM  A process was located, but neither the real nor effective user
              ID of the executing process match the effective user ID of the
              process whose nice value is being changed.

       EEAACCCCEESS A request was made to change the nice value to a lower numeric
              value and the current process does not have appropriate
              privileges.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   UUssiinngg ggeettpprriioorriittyy(())
       The following example returns the current scheduling priority for the
       process ID returned by the call to _g_e_t_p_i_d().

           ##iinncclluuddee <<ssyyss//rreessoouurrccee..hh>>
           ......
           iinntt wwhhiicchh == PPRRIIOO__PPRROOCCEESSSS;;
           iidd__tt ppiidd;;
           iinntt rreett;;

           pid = getpid();
           ret = getpriority(which, pid);

   UUssiinngg sseettpprriioorriittyy(())
       The following example sets the priority for the current process ID to
       -20.

           ##iinncclluuddee <<ssyyss//rreessoouurrccee..hh>>
           ......
           iinntt wwhhiicchh == PPRRIIOO__PPRROOCCEESSSS;;
           iidd__tt ppiidd;;
           iinntt pprriioorriittyy == --2200;;
           iinntt rreett;;

           pid = getpid();
           ret = setpriority(which, pid, priority);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _g_e_t_p_r_i_o_r_i_t_y() and _s_e_t_p_r_i_o_r_i_t_y() functions work with an offset nice
       value (nice value -{NZERO}). The nice value is in the range
       [0,2*{NZERO} -1], while the return value for _g_e_t_p_r_i_o_r_i_t_y() and the
       third parameter for _s_e_t_p_r_i_o_r_i_t_y() are in the range [-{NZERO},{NZERO}
       -1].

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _n_i_c_e(), _s_c_h_e_d___g_e_t___p_r_i_o_r_i_t_y___m_a_x(), _s_c_h_e_d___s_e_t_s_c_h_e_d_u_l_e_r()

       The Base Definitions volume of POSIX.1-2008, <<ssyyss__rreessoouurrccee..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                       GETPRIORITY(3)
