xref: /netbsd/sys/sys/resource.h (revision bf9ec67e)
1 /*	$NetBSD: resource.h,v 1.20 1999/09/28 14:47:04 bouyer Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)resource.h	8.4 (Berkeley) 1/9/95
36  */
37 
38 #ifndef _SYS_RESOURCE_H_
39 #define	_SYS_RESOURCE_H_
40 
41 #include <sys/time.h>
42 
43 /*
44  * Process priority specifications to get/setpriority.
45  */
46 #define	PRIO_MIN	-20
47 #define	PRIO_MAX	20
48 
49 #define	PRIO_PROCESS	0
50 #define	PRIO_PGRP	1
51 #define	PRIO_USER	2
52 
53 /*
54  * Resource utilization information.
55  */
56 
57 #define	RUSAGE_SELF	0
58 #define	RUSAGE_CHILDREN	-1
59 
60 struct	rusage {
61 	struct timeval ru_utime;	/* user time used */
62 	struct timeval ru_stime;	/* system time used */
63 	long	ru_maxrss;		/* max resident set size */
64 #define	ru_first	ru_ixrss
65 	long	ru_ixrss;		/* integral shared memory size */
66 	long	ru_idrss;		/* integral unshared data " */
67 	long	ru_isrss;		/* integral unshared stack " */
68 	long	ru_minflt;		/* page reclaims */
69 	long	ru_majflt;		/* page faults */
70 	long	ru_nswap;		/* swaps */
71 	long	ru_inblock;		/* block input operations */
72 	long	ru_oublock;		/* block output operations */
73 	long	ru_msgsnd;		/* messages sent */
74 	long	ru_msgrcv;		/* messages received */
75 	long	ru_nsignals;		/* signals received */
76 	long	ru_nvcsw;		/* voluntary context switches */
77 	long	ru_nivcsw;		/* involuntary " */
78 #define	ru_last		ru_nivcsw
79 };
80 
81 /*
82  * Resource limits
83  */
84 #define	RLIMIT_CPU	0		/* cpu time in milliseconds */
85 #define	RLIMIT_FSIZE	1		/* maximum file size */
86 #define	RLIMIT_DATA	2		/* data size */
87 #define	RLIMIT_STACK	3		/* stack size */
88 #define	RLIMIT_CORE	4		/* core file size */
89 #define	RLIMIT_RSS	5		/* resident set size */
90 #define	RLIMIT_MEMLOCK	6		/* locked-in-memory address space */
91 #define	RLIMIT_NPROC	7		/* number of processes */
92 #define	RLIMIT_NOFILE	8		/* number of open files */
93 
94 #define	RLIM_NLIMITS	9		/* number of resource limits */
95 
96 #define	RLIM_INFINITY	(~((u_quad_t)1 << 63))	/* no limit */
97 #define	RLIM_SAVED_MAX	RLIM_INFINITY	/* unrepresentable hard limit */
98 #define	RLIM_SAVED_CUR	RLIM_INFINITY	/* unrepresentable soft limit */
99 
100 #if defined(_KERNEL)
101 /* 4.3BSD compatibility rlimit argument structure. */
102 struct orlimit {
103 	int32_t	rlim_cur;		/* current (soft) limit */
104 	int32_t	rlim_max;		/* maximum value for rlim_cur */
105 };
106 #endif
107 
108 struct rlimit {
109 	rlim_t	rlim_cur;		/* current (soft) limit */
110 	rlim_t	rlim_max;		/* maximum value for rlim_cur */
111 };
112 
113 #if !defined(_XOPEN_SOURCE)
114 /* Load average structure. */
115 struct loadavg {
116 	fixpt_t	ldavg[3];
117 	long	fscale;
118 };
119 #endif
120 
121 #ifdef _KERNEL
122 extern struct loadavg averunnable;
123 struct pcred;
124 int	dosetrlimit __P((struct proc *, struct pcred *, int, struct rlimit *));
125 int	donice __P((struct proc *, struct proc *, int));
126 
127 #else
128 #include <sys/cdefs.h>
129 
130 __BEGIN_DECLS
131 int	getpriority __P((int, int));
132 int	getrlimit __P((int, struct rlimit *));
133 int	getrusage __P((int, struct rusage *));
134 int	setpriority __P((int, int, int));
135 int	setrlimit __P((int, const struct rlimit *));
136 __END_DECLS
137 
138 #endif	/* _KERNEL */
139 #endif	/* !_SYS_RESOURCE_H_ */
140