1use crate::process::{Pid, Uid};
2use crate::{backend, io};
3
4/// `nice(inc)`—Adjust the scheduling priority of the current process.
5///
6/// # References
7/// - [POSIX]
8/// - [Linux]
9///
10/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/nice.html
11/// [Linux]: https://man7.org/linux/man-pages/man2/nice.2.html
12#[inline]
13pub fn nice(inc: i32) -> io::Result<i32> {
14 backend::process::syscalls::nice(inc)
15}
16
17/// `getpriority(PRIO_USER, uid)`—Get the scheduling priority of the given
18/// user.
19///
20/// # References
21/// - [POSIX]
22/// - [Linux]
23/// - [Apple]
24///
25/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
26/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
27/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
28#[inline]
29#[doc(alias = "getpriority")]
30pub fn getpriority_user(uid: Uid) -> io::Result<i32> {
31 backend::process::syscalls::getpriority_user(uid)
32}
33
34/// `getpriority(PRIO_PGRP, gid)`—Get the scheduling priority of the given
35/// process group.
36///
37/// A `pgid` of `None` means the process group of the calling process.
38///
39/// # References
40/// - [POSIX]
41/// - [Linux]
42/// - [Apple]
43///
44/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
45/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
46/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
47#[inline]
48#[doc(alias = "getpriority")]
49pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
50 backend::process::syscalls::getpriority_pgrp(pgid)
51}
52
53/// `getpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given
54/// process.
55///
56/// A `pid` of `None` means the calling process.
57///
58/// # References
59/// - [POSIX]
60/// - [Linux]
61/// - [Apple]
62///
63/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
64/// [Linux]: https://man7.org/linux/man-pages/man2/getpriority.2.html
65/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
66#[inline]
67#[doc(alias = "getpriority")]
68pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
69 backend::process::syscalls::getpriority_process(pid)
70}
71
72/// `setpriority(PRIO_USER, uid)`—Get the scheduling priority of the given
73/// user.
74///
75/// # References
76/// - [POSIX]
77/// - [Linux]
78/// - [Apple]
79///
80/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
81/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
82/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
83#[inline]
84#[doc(alias = "setpriority")]
85pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> {
86 backend::process::syscalls::setpriority_user(uid, priority)
87}
88
89/// `setpriority(PRIO_PGRP, pgid)`—Get the scheduling priority of the given
90/// process group.
91///
92/// A `pgid` of `None` means the process group of the calling process.
93///
94/// # References
95/// - [POSIX]
96/// - [Linux]
97/// - [Apple]
98///
99/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
100/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
101/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
102#[inline]
103#[doc(alias = "setpriority")]
104pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> {
105 backend::process::syscalls::setpriority_pgrp(pgid, priority)
106}
107
108/// `setpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given
109/// process.
110///
111/// A `pid` of `None` means the calling process.
112///
113/// # References
114/// - [POSIX]
115/// - [Linux]
116/// - [Apple]
117///
118/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
119/// [Linux]: https://man7.org/linux/man-pages/man2/setpriority.2.html
120/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setpriority.2.html
121#[inline]
122#[doc(alias = "setpriority")]
123pub fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> {
124 backend::process::syscalls::setpriority_process(pid, priority)
125}
126