8ae2e95643
Implemented against POSIX-1.2013. The implementation POSIX requirement thats setpriority() shall affect the priority of all system scope threads only extends to POSIX threads. This is implemented by modifying the default attributes for newly spawned pthreads. It is not possible to modify the default pthread attributes for different processes with the current implementation, as default pthread attributes are implemented in user-space. As a result, PRIO_PROCESS for which and 0 for who is the only supported combination for setpriority(). While it is possible to move the default attributes to the kernel, it is chosen not to so as to keep the pthread implementation user-space only. POSIX requires that lowering the nice value (increasing priority) can be done only by processes with appropriate privileges. However, as Haiku currently doesn't harbor any restrictions in setting the thread priority, this is not implemented. It is possible to have small precision errors when converting from Unix- style thread priority to Be-style. For example, the following program outputs "17" instead of the expected "18": #include <stdio.h> #include <sys/resource.h> int main() { setpriority(PRIO_PROCESS, 0, 18); printf("%d\n", getpriority(PRIO_PROCESS, 0)); return 0; } The underlying reason is because when you setpriority() both 18 and 19 are converted to the Be-style "2". This problem should not happen with priority levels lower than or equal to 20, when the Be notation is more precise than the Unix-style. Done as a part of GCI 2014. Fixes #2817. Signed-off-by: Timothy Gu <timothygu99@gmail.com> Co-authored-by: Leorize <leorize+oss@disroot.org> Change-Id: Ie14f105b00fe8563d16b3562748e1c2e56c873a6 Reviewed-on: https://review.haiku-os.org/c/78 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
73 lines
1.7 KiB
C
73 lines
1.7 KiB
C
/*
|
|
* Copyright 2003-2012 Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _SYS_RESOURCE_H
|
|
#define _SYS_RESOURCE_H
|
|
|
|
|
|
#include <config/types.h>
|
|
|
|
#include <sys/cdefs.h>
|
|
#include <sys/time.h>
|
|
|
|
|
|
/* getrlimit()/setrlimit() definitions */
|
|
|
|
typedef __haiku_addr_t rlim_t;
|
|
|
|
struct rlimit {
|
|
rlim_t rlim_cur; /* current soft limit */
|
|
rlim_t rlim_max; /* hard limit */
|
|
};
|
|
|
|
/* ToDo: the only supported mode is RLIMIT_NOFILE right now */
|
|
#define RLIMIT_CORE 0 /* size of the core file */
|
|
#define RLIMIT_CPU 1 /* CPU time per team */
|
|
#define RLIMIT_DATA 2 /* data segment size */
|
|
#define RLIMIT_FSIZE 3 /* file size */
|
|
#define RLIMIT_NOFILE 4 /* number of open files */
|
|
#define RLIMIT_STACK 5 /* stack size */
|
|
#define RLIMIT_AS 6 /* address space size */
|
|
/* Haiku-specifics */
|
|
#define RLIMIT_NOVMON 7 /* number of open vnode monitors */
|
|
|
|
#define RLIM_NLIMITS 8 /* number of resource limits */
|
|
|
|
#define RLIM_INFINITY (0xffffffffUL)
|
|
#define RLIM_SAVED_MAX RLIM_INFINITY
|
|
#define RLIM_SAVED_CUR RLIM_INFINITY
|
|
|
|
|
|
/* getrusage() definitions */
|
|
|
|
struct rusage {
|
|
struct timeval ru_utime; /* user time used */
|
|
struct timeval ru_stime; /* system time used */
|
|
};
|
|
|
|
#define RUSAGE_SELF 0
|
|
#define RUSAGE_CHILDREN -1
|
|
|
|
|
|
/* getpriority()/setpriority() definitions */
|
|
|
|
#define PRIO_PROCESS 0
|
|
#define PRIO_PGRP 1
|
|
#define PRIO_USER 2
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern int getrusage(int who, struct rusage *rusage);
|
|
|
|
extern int getrlimit(int resource, struct rlimit * rlp);
|
|
extern int setrlimit(int resource, const struct rlimit * rlp);
|
|
|
|
extern int getpriority(int which, id_t who);
|
|
extern int setpriority(int which, id_t who, int priority);
|
|
|
|
__END_DECLS
|
|
|
|
#endif /* _SYS_RESOURCE_H */
|