1.\" $FreeBSD$
2.\" Copyright (c) 1998 HD Associates, Inc.
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd March 12, 1998
27.Dt SCHED_SETSCHEDULER 2
28.Os
29.Sh NAME
30.Nm sched_setscheduler ,
31.Nm sched_getscheduler
32.Nd set/get scheduling policy and scheduler parameters
33.Sh LIBRARY
34.Lb libc
35.Sh SYNOPSIS
36.In sched.h
37.Ft int
38.Fn sched_setscheduler "pid_t pid" "int policy" "const struct sched_param *param"
39.Ft int
40.Fn sched_getscheduler "pid_t pid"
41.Sh DESCRIPTION
42The
43.Fn sched_setscheduler
44system call sets the scheduling policy and scheduling parameters
45of the process specified by
46.Fa pid
47to
48.Fa policy
49and the parameters specified in the
50.Vt sched_param
51structure pointed to by
52.Fa param ,
53respectively.
54The value of the
55.Fa sched_priority
56member in the
57.Fa param
58structure must be any integer within the inclusive priority range for
59the scheduling policy specified by
60.Fa policy .
61.Pp
62In this implementation, if the value of
63.Fa pid
64is negative the system call will fail.
65.Pp
66If a process specified by
67.Fa pid
68exists and if the calling process has permission, the scheduling
69policy and scheduling parameters will be set for the process
70whose process ID is equal to
71.Fa pid .
72.Pp
73If
74.Fa pid
75is zero, the scheduling policy and scheduling
76parameters are set for the calling process.
77.Pp
78In this implementation, the policy of when a process can affect
79the scheduling parameters of another process is specified in
80.St -p1003.1b-93
81as a write-style operation.
82.Pp
83The scheduling policies are in
84.Fa <sched.h> :
85.Bl -tag -width [SCHED_OTHER]
86.It Bq Er SCHED_FIFO
87First-in-first-out fixed priority scheduling with no round robin scheduling;
88.It Bq Er SCHED_OTHER
89The standard time sharing scheduler;
90.It Bq Er SCHED_RR
91Round-robin scheduling across same priority processes.
92.El
93.Pp
94The
95.Vt sched_param
96structure is defined in
97.Fa <sched.h> :
98.Pp
99.Bd -literal -offset indent
100struct sched_param {
101	int sched_priority;	/* scheduling priority */
102};
103.Ed
104.Pp
105The
106.Fn sched_getscheduler
107system call returns the scheduling policy of the process specified
108by
109.Fa pid .
110.Pp
111If a process specified by
112.Fa pid
113exists and if the calling process has permission,
114the scheduling parameters for the process whose process ID is equal to
115.Fa pid
116are returned.
117.Pp
118In this implementation, the policy of when a process can obtain the
119scheduling parameters of another process are detailed in
120.St -p1003.1b-93
121as a read-style operation.
122.Pp
123If
124.Fa pid
125is zero, the scheduling parameters for the calling process will be
126returned.
127In this implementation, the
128.Fa sched_getscheduler
129system call will fail if
130.Fa pid
131is negative.
132.Sh RETURN VALUES
133.Rv -std
134.Sh ERRORS
135On failure
136.Va errno
137will be set to the corresponding value:
138.Bl -tag -width Er
139.It Bq Er ENOSYS
140The system is not configured to support this functionality.
141.It Bq Er EPERM
142The requesting process doesn not have permission as detailed in
143.St -p1003.1b-93 .
144.It Bq Er ESRCH
145No process can be found corresponding to that specified by
146.Fa pid .
147.It Bq Er EINVAL
148The value of the
149.Fa policy
150argument is invalid, or one or more of the parameters contained in
151.Fa param
152is outside the valid range for the specified scheduling policy.
153.El
154.Sh SEE ALSO
155.Xr sched_getparam 2 ,
156.Xr sched_get_priority_max 2 ,
157.Xr sched_get_priority_min 2 ,
158.Xr sched_rr_get_interval 2 ,
159.Xr sched_setparam 2 ,
160.Xr sched_yield 2
161.Sh STANDARDS
162The
163.Fn sched_setscheduler
164and
165.Fn sched_getscheduler
166system calls conform to
167.St -p1003.1b-93 .
168