~sircmpwn/hare

ref: 4e72da523d192c219cc7086f6d260b1b37211f4c hare/unix/nice+linux.ha -rw-r--r-- 636 bytes
4e72da52Sudipto Mallick strings: add ltrim, rtrim and trim 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use errors;
use rt;

// Adds the argument to the niceness of the current process. The input should be
// between -20 and 19 (inclusive); lower numbers represent a higher priority.
// Generally, you must have elevated permissions to reduce your niceness, but
// not to increase it.
export fn nice(inc: int) (void | errors::error) = {
	let prio = inc;
	if (inc > -40 && inc <= 40) {
		prio += rt::getpriority(rt::PRIO_PROCESS, 0) as int;
	};
	if (prio > 19) {
		prio = 19;
	};
	if (prio < -20) {
		prio = -20;
	};
	return match (rt::setpriority(rt::PRIO_PROCESS, 0, prio)) {
		void => void,
		err: rt::errno => errors::errno(err),
	};
};