2011-02-17 18:11:09 +01:00
|
|
|
/*
|
|
|
|
priority.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <lib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
|
|
int getpriority(int which, int who)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
message m;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.PM_PRIORITY_WHICH = which;
|
|
|
|
m.PM_PRIORITY_WHO = who;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
/* GETPRIORITY returns negative for error.
|
|
|
|
* Otherwise, it returns the priority plus the minimum
|
|
|
|
* priority, to distiginuish from error. We have to
|
|
|
|
* correct for this. (The user program has to check errno
|
|
|
|
* to see if something really went wrong.)
|
|
|
|
*/
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
if((v = _syscall(PM_PROC_NR, PM_GETPRIORITY, &m)) < 0) {
|
2011-02-17 18:11:09 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
return v + PRIO_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int setpriority(int which, int who, int prio)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.PM_PRIORITY_WHICH = which;
|
|
|
|
m.PM_PRIORITY_WHO = who;
|
|
|
|
m.PM_PRIORITY_PRIO = prio;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
return _syscall(PM_PROC_NR, PM_SETPRIORITY, &m);
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|
|
|
|
|