1f6aac1c3SLionel Sambuc /* $NetBSD: resource.h,v 1.33 2012/06/09 02:31:15 christos Exp $ */ 2f6aac1c3SLionel Sambuc 3f6aac1c3SLionel Sambuc /* 4f6aac1c3SLionel Sambuc * Copyright (c) 1982, 1986, 1993 5f6aac1c3SLionel Sambuc * The Regents of the University of California. All rights reserved. 6f6aac1c3SLionel Sambuc * 7f6aac1c3SLionel Sambuc * Redistribution and use in source and binary forms, with or without 8f6aac1c3SLionel Sambuc * modification, are permitted provided that the following conditions 9f6aac1c3SLionel Sambuc * are met: 10f6aac1c3SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 11f6aac1c3SLionel Sambuc * notice, this list of conditions and the following disclaimer. 12f6aac1c3SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 13f6aac1c3SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 14f6aac1c3SLionel Sambuc * documentation and/or other materials provided with the distribution. 15f6aac1c3SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors 16f6aac1c3SLionel Sambuc * may be used to endorse or promote products derived from this software 17f6aac1c3SLionel Sambuc * without specific prior written permission. 18f6aac1c3SLionel Sambuc * 19f6aac1c3SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20f6aac1c3SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21f6aac1c3SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22f6aac1c3SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23f6aac1c3SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24f6aac1c3SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25f6aac1c3SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26f6aac1c3SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27f6aac1c3SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28f6aac1c3SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29f6aac1c3SLionel Sambuc * SUCH DAMAGE. 30f6aac1c3SLionel Sambuc * 31f6aac1c3SLionel Sambuc * @(#)resource.h 8.4 (Berkeley) 1/9/95 32f6aac1c3SLionel Sambuc */ 33f6aac1c3SLionel Sambuc 34f6aac1c3SLionel Sambuc #ifndef _SYS_RESOURCE_H_ 35f6aac1c3SLionel Sambuc #define _SYS_RESOURCE_H_ 36f6aac1c3SLionel Sambuc 37f6aac1c3SLionel Sambuc #include <sys/featuretest.h> 38f6aac1c3SLionel Sambuc #include <sys/time.h> 39f6aac1c3SLionel Sambuc 40f6aac1c3SLionel Sambuc /* 41f6aac1c3SLionel Sambuc * Process priority specifications to get/setpriority. 42f6aac1c3SLionel Sambuc */ 43f6aac1c3SLionel Sambuc #define PRIO_MIN -20 44f6aac1c3SLionel Sambuc #define PRIO_MAX 20 45f6aac1c3SLionel Sambuc 46f6aac1c3SLionel Sambuc #define PRIO_PROCESS 0 47f6aac1c3SLionel Sambuc #define PRIO_PGRP 1 48f6aac1c3SLionel Sambuc #define PRIO_USER 2 49f6aac1c3SLionel Sambuc 50f6aac1c3SLionel Sambuc /* 5164f10ee6SXiaoguang Sun * Resource utilization information. 5264f10ee6SXiaoguang Sun */ 5364f10ee6SXiaoguang Sun 5464f10ee6SXiaoguang Sun #define RUSAGE_SELF 0 5564f10ee6SXiaoguang Sun #define RUSAGE_CHILDREN -1 5664f10ee6SXiaoguang Sun 5764f10ee6SXiaoguang Sun struct rusage { 5864f10ee6SXiaoguang Sun struct timeval ru_utime; /* user time used */ 5964f10ee6SXiaoguang Sun struct timeval ru_stime; /* system time used */ 6064f10ee6SXiaoguang Sun long ru_maxrss; /* max resident set size */ 6164f10ee6SXiaoguang Sun #define ru_first ru_ixrss 6264f10ee6SXiaoguang Sun long ru_ixrss; /* integral shared memory size */ 6364f10ee6SXiaoguang Sun long ru_idrss; /* integral unshared data " */ 6464f10ee6SXiaoguang Sun long ru_isrss; /* integral unshared stack " */ 6564f10ee6SXiaoguang Sun long ru_minflt; /* page reclaims */ 6664f10ee6SXiaoguang Sun long ru_majflt; /* page faults */ 6764f10ee6SXiaoguang Sun long ru_nswap; /* swaps */ 6864f10ee6SXiaoguang Sun long ru_inblock; /* block input operations */ 6964f10ee6SXiaoguang Sun long ru_oublock; /* block output operations */ 7064f10ee6SXiaoguang Sun long ru_msgsnd; /* messages sent */ 7164f10ee6SXiaoguang Sun long ru_msgrcv; /* messages received */ 7264f10ee6SXiaoguang Sun long ru_nsignals; /* signals received */ 7364f10ee6SXiaoguang Sun long ru_nvcsw; /* voluntary context switches */ 7464f10ee6SXiaoguang Sun long ru_nivcsw; /* involuntary " */ 7564f10ee6SXiaoguang Sun #define ru_last ru_nivcsw 7664f10ee6SXiaoguang Sun }; 7764f10ee6SXiaoguang Sun 7864f10ee6SXiaoguang Sun /* 79f6aac1c3SLionel Sambuc * Resource limits 80f6aac1c3SLionel Sambuc */ 81*46b89a73SBen Gras #define RLIMIT_CPU 0 /* cpu time in milliseconds */ 82*46b89a73SBen Gras #define RLIMIT_FSIZE 1 /* maximum file size */ 83*46b89a73SBen Gras #define RLIMIT_DATA 2 /* data size */ 84*46b89a73SBen Gras #define RLIMIT_STACK 3 /* stack size */ 85*46b89a73SBen Gras #define RLIMIT_CORE 4 /* core file size */ 86*46b89a73SBen Gras #define RLIMIT_RSS 5 /* resident set size */ 87*46b89a73SBen Gras #define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ 88*46b89a73SBen Gras #define RLIMIT_NPROC 7 /* number of processes */ 89*46b89a73SBen Gras #define RLIMIT_NOFILE 8 /* number of open files */ 90*46b89a73SBen Gras #define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */ 91*46b89a73SBen Gras #define RLIMIT_AS 10 /* virtual process size (inclusive of mmap) */ 92f6aac1c3SLionel Sambuc #define RLIMIT_VMEM RLIMIT_AS /* common alias */ 93*46b89a73SBen Gras #define RLIMIT_NTHR 11 /* number of threads */ 94f6aac1c3SLionel Sambuc 95f6aac1c3SLionel Sambuc #if defined(_NETBSD_SOURCE) 96*46b89a73SBen Gras #define RLIM_NLIMITS 12 /* number of resource limits */ 97f6aac1c3SLionel Sambuc #endif 98f6aac1c3SLionel Sambuc 99*46b89a73SBen Gras #define RLIM_INFINITY (~((u_quad_t)1 << 63)) /* no limit */ 100*46b89a73SBen Gras #define RLIM_SAVED_MAX RLIM_INFINITY /* unrepresentable hard limit */ 101*46b89a73SBen Gras #define RLIM_SAVED_CUR RLIM_INFINITY /* unrepresentable soft limit */ 102f6aac1c3SLionel Sambuc 103*46b89a73SBen Gras #if defined(_KERNEL) 104*46b89a73SBen Gras /* 4.3BSD compatibility rlimit argument structure. */ 105*46b89a73SBen Gras struct orlimit { 106*46b89a73SBen Gras int32_t rlim_cur; /* current (soft) limit */ 107*46b89a73SBen Gras int32_t rlim_max; /* maximum value for rlim_cur */ 108*46b89a73SBen Gras }; 109*46b89a73SBen Gras #endif 110*46b89a73SBen Gras 111*46b89a73SBen Gras struct rlimit { 112*46b89a73SBen Gras rlim_t rlim_cur; /* current (soft) limit */ 113*46b89a73SBen Gras rlim_t rlim_max; /* maximum value for rlim_cur */ 114f6aac1c3SLionel Sambuc }; 115f6aac1c3SLionel Sambuc 116*46b89a73SBen Gras #if defined(_NETBSD_SOURCE) 117*46b89a73SBen Gras /* Load average structure. */ 118*46b89a73SBen Gras struct loadavg { 119*46b89a73SBen Gras fixpt_t ldavg[3]; 120*46b89a73SBen Gras long fscale; 121*46b89a73SBen Gras }; 122*46b89a73SBen Gras #endif 123*46b89a73SBen Gras 124*46b89a73SBen Gras #ifdef _KERNEL 125*46b89a73SBen Gras extern struct loadavg averunnable; 126*46b89a73SBen Gras struct pcred; 127*46b89a73SBen Gras int dosetrlimit(struct lwp *, struct proc *, int, struct rlimit *); 128*46b89a73SBen Gras #else 129f6aac1c3SLionel Sambuc #include <sys/cdefs.h> 130f6aac1c3SLionel Sambuc 131f6aac1c3SLionel Sambuc __BEGIN_DECLS 132*46b89a73SBen Gras int getpriority(int, id_t); 133f6aac1c3SLionel Sambuc int getrlimit(int, struct rlimit *); 134*46b89a73SBen Gras #ifndef __LIBC12_SOURCE__ 135*46b89a73SBen Gras int getrusage(int, struct rusage *) __RENAME(__getrusage50); 136*46b89a73SBen Gras #endif 137*46b89a73SBen Gras int setpriority(int, id_t, int); 138*46b89a73SBen Gras int setrlimit(int, const struct rlimit *); 139f6aac1c3SLionel Sambuc __END_DECLS 140f6aac1c3SLionel Sambuc 141*46b89a73SBen Gras #endif /* _KERNEL */ 142f6aac1c3SLionel Sambuc #endif /* !_SYS_RESOURCE_H_ */ 143