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.Bd -literal -offset indent
99struct sched_param {
100	int sched_priority;	/* scheduling priority */
101};
102.Ed
103.Pp
104The
105.Fn sched_getscheduler
106system call returns the scheduling policy of the process specified
107by
108.Fa pid .
109.Pp
110If a process specified by
111.Fa pid
112exists and if the calling process has permission,
113the scheduling parameters for the process whose process ID is equal to
114.Fa pid
115are returned.
116.Pp
117In this implementation, the policy of when a process can obtain the
118scheduling parameters of another process are detailed in
119.St -p1003.1b-93
120as a read-style operation.
121.Pp
122If
123.Fa pid
124is zero, the scheduling parameters for the calling process will be
125returned.
126In this implementation, the
127.Fa sched_getscheduler
128system call will fail if
129.Fa pid
130is negative.
131.Sh RETURN VALUES
132.Rv -std
133.Sh ERRORS
134On failure
135.Va errno
136will be set to the corresponding value:
137.Bl -tag -width Er
138.It Bq Er ENOSYS
139The system is not configured to support this functionality.
140.It Bq Er EPERM
141The requesting process doesn not have permission as detailed in
142.St -p1003.1b-93 .
143.It Bq Er ESRCH
144No process can be found corresponding to that specified by
145.Fa pid .
146.It Bq Er EINVAL
147The value of the
148.Fa policy
149argument is invalid, or one or more of the parameters contained in
150.Fa param
151is outside the valid range for the specified scheduling policy.
152.El
153.Sh SEE ALSO
154.Xr sched_getparam 2 ,
155.Xr sched_get_priority_max 2 ,
156.Xr sched_get_priority_min 2 ,
157.Xr sched_rr_get_interval 2 ,
158.Xr sched_setparam 2 ,
159.Xr sched_yield 2
160.Sh STANDARDS
161The
162.Fn sched_setscheduler
163and
164.Fn sched_getscheduler
165system calls conform to
166.St -p1003.1b-93 .
167