Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > P


Pthread Library
HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


pthread_get_nice_np(), pthread_set_nice_np() — get or set the nice value of a thread


#include <pthread.h>

int pthread_get_nice_np( pthread_t thread, int *nice_val );

int pthread_set_nice_np( pthread_t thread, int nice_val );



The thread whose nice value is to be set/retrieved.


Value of nice to be applied to the target thread is returned (get function) or it specifies the new value of nice for thread (set function).


These functions are used to set and retrieve the nice value of an individual thread.

pthread_get_nice_np() returns the current nice value setting of the target thread and stores it in nice_val. pthread_set_nice_np() adds the value of nice_val to the current nice value of the target thread.

A thread's nice value is a non-negative number. The system imposes a minimum nice value of 0 and a maximum of 39 with lower nice values providing more favorable scheduling. If calling pthread_set_nice_np() results in a nice value outside the range of 0 to 39, the value will be set to the nearest limit. A process must have appropriate privileges to lower a thread's nice value. The pthread_set_nice_np() function allows individual threads in the process to have different nice values.

pthread_get_nice_np() returns the current nice value less 20 and will be in the range -20 to +19.

The nice value of only system scope (PTHREAD_SCOPE_SYSTEM) threads can be changed. An attempt to change the nice value of a process-scope thread will result in a return value of ENOTSUP. Calling pthread_set_nice_np() on a thread that has a scheduling policy other than SCHED_HPUX will have an effect only when the thread's scheduling policy changes to SCHED_HPUX. If a thread calls the fork() system call to create a new process, the new process inherits the process-level nice value. Calling pthread_create() to create a new thread will result in the new thread inheriting the creating thread's nice value.


If the nice value of the entire process is changed through nice() or setpriority(), all the threads in the process will have their nice values reset to the new process-level nice value. The new process's nice value setting overwrites the old thread's setting. Thus its possible that a thread whose nice value had been set higher than the process-level nice value have its nice value lowered as a result of the process-level re-nicing.


Upon successful completion, pthread_set_nice_np() and pthread_get_nice_np() return zero.

Otherwise, an error number is returned to indicate the error (the errno variable is not set).


If any of the following occur, the pthread_get_nice_np() and pthread_set_nice_np() functions return the corresponding error:


A process-scope thread was specified.


The caller does not have permission to lower the nice value specified in nice_val.


No thread could be found corresponding to thread.


pthread_get_nice_np() and pthread_set_nice_np() were developed by HP.


fork(2), nice(2), setpriority(2), pthread_attr_getschedpolicy(3T), pthread_setschedparam(3T).

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.