mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
Kernel/LibC: Implement sched_* functionality to set/get process priority
Right now, we allow anything inside a user to raise or lower any other process's priority. This feels simple enough to me. Linux disallows raising, but that's annoying in practice.
This commit is contained in:
parent
b160677e9e
commit
9cd0f6ffac
8 changed files with 103 additions and 1 deletions
|
@ -10,5 +10,29 @@ int sched_yield()
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int sched_get_priority_min(int policy)
|
||||
{
|
||||
(void)policy;
|
||||
return 0; // Idle
|
||||
}
|
||||
|
||||
int sched_get_priority_max(int policy)
|
||||
{
|
||||
(void)policy;
|
||||
return 3; // High
|
||||
}
|
||||
|
||||
int sched_setparam(pid_t pid, const struct sched_param *param)
|
||||
{
|
||||
int rc = syscall(SC_sched_setparam, pid, param);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int sched_getparam(pid_t pid, struct sched_param *param)
|
||||
{
|
||||
int rc = syscall(SC_sched_getparam, pid, param);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
15
LibC/sched.h
15
LibC/sched.h
|
@ -1,9 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int sched_yield();
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority;
|
||||
};
|
||||
|
||||
#define SCHED_FIFO 0
|
||||
#define SCHED_RR 1
|
||||
#define SCHED_OTHER 2
|
||||
#define SCHED_BATCH 3
|
||||
|
||||
int sched_get_priority_min(int policy);
|
||||
int sched_get_priority_max(int policy);
|
||||
int sched_setparam(pid_t pid, const struct sched_param *param);
|
||||
int sched_getparam(pid_t pid, struct sched_param *param);
|
||||
|
||||
__END_DECLS
|
||||
|
|
|
@ -107,4 +107,10 @@ enum
|
|||
#define X_OK 1
|
||||
#define F_OK 0
|
||||
|
||||
/*
|
||||
* We aren't fully compliant (don't support policies, and don't have a wide
|
||||
* range of values), but we do have process priorities.
|
||||
*/
|
||||
#define _POSIX_PRIORITY_SCHEDULING
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue