.\" $NetBSD: sched.3,v 1.1 2008/03/10 14:47:06 rmind Exp $ .\" .\" Copyright (c) 2008 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Mindaugas Rasiukevicius . .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the NetBSD .\" Foundation, Inc. and its contributors. .\" 4. Neither the name of The NetBSD Foundation nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd March 10, 2008 .Dt SCHED 3 .Os .Sh NAME .Nm sched_setparam , .Nm sched_getparam , .Nm sched_setscheduler , .Nm sched_getscheduler , .Nm sched_get_priority_max , .Nm sched_get_priority_min , .Nm sched_rr_get_interval , .Nm sched_yield .Nd process scheduling .Sh LIBRARY .Lb librt .Sh SYNOPSIS .In sched.h .Ft int .Fn sched_setparam "pid_t pid" "const struct sched_param *param" .Ft int .Fn sched_getparam "pid_t pid" "struct sched_param *param" .Ft int .Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param" .Ft int .Fn sched_getscheduler "pid_t pid" .Ft int .Fn sched_get_priority_max "int policy" .Ft int .Fn sched_get_priority_min "int policy" .Ft int .Fn sched_rr_get_interval "pid_t pid" "struct timespec *interval" .Ft int .Fn sched_yield "void" .Sh DESCRIPTION This section describes the functions used to get the scheduling information about the processes, and control the scheduling of the process. .Pp Available scheduling policies (classes) are: .Bl -tag -width SCHED_OTHER .It Dv SCHED_OTHER Time-sharing (TS) scheduling policy. The default policy in .Nx . .It Dv SCHED_FIFO First in, first out (FIFO) scheduling policy. .It Dv SCHED_RR Round robin scheduling policy. .El .Pp The .Fa struct sched_param contains at least one member: .Bl -tag -width flags .It Fa sched_priority Specifies the priority of the process. .El .Ss FUNCTIONS .Bl -tag -width compact .It Fn sched_setparam pid param Sets the scheduling parameters for the process specified by .Fa pid to .Fa param . If the value of .Fa pid is equal to zero, then the calling process is used. .It Fn sched_getparam pid param Gets the scheduling parameters of the process specified by .Fa pid into the structure .Fa param . If the value of .Fa pid is equal to zero, then the calling process is used. .It Fn sched_setscheduler pid policy param Set the scheduling policy and parameters for the process specified by .Fa pid . If the value of .Fa pid is equal to zero, then the calling process is used. .It Fn sched_getscheduler pid Returns the scheduling policy of the process specified by .Fa pid . If the value of .Fa pid is equal to zero, then the calling process is used. .It Fn sched_get_priority_max policy Returns the maximal priority which may be used for the scheduling policy specified by .Fa policy . .It Fn sched_get_priority_min policy Returns the minimal priority which may be used for the scheduling policy specified by .Fa policy . .It Fn sched_rr_get_interval pid interval Returns the time quantum into the structure .Fa interval of the process specified by .Fa pid . If the value of .Fa pid is equal to zero, then the calling process is used. The process must be running at .Fa SCHED_RR scheduling policy. .It Fn sched_yield Yields a processor voluntarily and gives other threads a chance to run without waiting for an involuntary preemptive switch. .El .Sh RETURN VALUES .Fn sched_setparam , .Fn sched_getparam , .Fn sched_rr_get_interval , and .Fn sched_yield return 0 on success. Otherwise, \-1 is returned and .Va errno is set to indicate the error. .Pp .Fn sched_setscheduler returns the previously used scheduling policy on success. Otherwise, \-1 is returned and .Va errno is set to indicate the error. .Pp .Fn sched_getscheduler returns the scheduling policy on success. Otherwise, \-1 is returned and .Va errno is set to indicate the error. .Pp The .Fn sched_get_priority_max and .Fn sched_get_priority_min return the maximal/minimal priority value on success. Otherwise, \-1 is returned and .Va errno is set to indicate the error. .Sh ERRORS The .Fn sched_setparam and .Fn sched_setscheduler functions fail if: .Bl -tag -width Er .It Bq Er EINVAL At least one of the specified scheduling parameters was invalid. .It Bq Er EPERM The calling process has no appropriate privileges to perform the operation. .It Bq Er ESRCH No process can be found corresponding to that specified by .Fa pid , and value of .Fa pid is not zero. .El .Pp The .Fn sched_getparam and .Fn sched_getscheduler functions fail if: .Bl -tag -width Er .It Bq Er EPERM The calling process is not a super-user and its effective user id does not match the effective user-id of the specified process. .It Bq Er ESRCH No process can be found corresponding to that specified by .Fa pid , and value of .Fa pid is not zero. .El .Pp The .Fn sched_get_priority_max and .Fn sched_get_priority_min functions fail if: .Bl -tag -width Er .It Bq Er EINVAL The specified scheduling policy is invalid. .El .Pp The .Fn sched_rr_get_interval function fails if: .Bl -tag -width Er .It Bq Er ESRCH No process can be found corresponding to that specified by .Fa pid , and value of .Fa pid is not zero. .El .Sh SEE ALSO .Xr pset 3 , .Xr schedctl 8 .Sh STANDARDS These functions conform to .St -p1003.1-2001 standard. .Sh HISTORY The scheduling functions appeared in .Nx 5.0 . .Sh BUGS Currently, these functions are valid and work correctly only with the SCHED_M2 thread scheduler implementation.