sys_resource.h(0P)

๐Ÿ’– sys/resource.h โ€” bestie's guide to XSI resource ops ๐Ÿ’–

okay so first things first: this is a page from the POSIX Programmer's Manual (0P, she's certified, she's iconic), and the header file we're stanning is sys/resource.h โ€” the place where all your definitions for XSI resource operations live. ๐ŸŒˆ

โš ๏ธ real talk bestie: the Linux implementation of this interface may differ, so pls consult the corresponding Linux manual page for details of Linux behavior. Also? The interface might just... not be implemented on Linux at all. ๐Ÿ™ˆ

โœจ SYNOPSIS โœจ

#include <sys/resource.h>

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

So the <sys/resource.h> header is gonna define these symbolic constants as possible values for the which argument of getpriority() and setpriority(). Like, which thing are we even talking about here:

  • PRIO_PROCESS โ€” says the who argument is a process ID. ๐Ÿ’…
  • PRIO_PGRP โ€” says the who argument is a process group ID.
  • PRIO_USER โ€” says the who argument is a user ID.

๐Ÿฆ‹ the typedef, she's serving

The header also defines this type through typedef:

  • rlim_t โ€” an unsigned integer type used for limit values. That's the one, no cap.

โญ constants you can use in #if โญ

Next up, these symbolic constants, and their values are suitable for use in #if preprocessing directives. Periodt:

  • RLIM_INFINITY โ€” a value of rlim_t indicating no limit. Live your truth, no limits. ๐Ÿฆ‹
  • RLIM_SAVED_MAX โ€” a value of type rlim_t indicating an unrepresentable saved hard limit.
  • RLIM_SAVED_CUR โ€” a value of type rlim_t indicating an unrepresentable saved soft limit.

And here's the lil plot twist: on implementations where all resource limits are representable in an object of type rlim_t, then RLIM_SAVED_MAX and RLIM_SAVED_CUR need not be distinct from RLIM_INFINITY. So don't @ them if they're the same. ๐Ÿ˜ญ


๐ŸŒธ getrusage() vibes: the who parameter

The header defines these as possible values of the who parameter of getrusage():

  • RUSAGE_SELF โ€” returns info about the current process. main character energy fr.
  • RUSAGE_CHILDREN โ€” returns info about the children of the current process. the kids!! ๐Ÿซถ

๐Ÿ‘‘ the rlimit structure

The header defines the rlimit structure, which shall include at least these members:

rlim_t rlim_cur  The current (soft) limit.
rlim_t rlim_max  The hard limit.

๐Ÿ’œ the rusage structure

And the header defines the rusage structure, which shall include at least these members:

struct timeval ru_utime  User time used.
struct timeval ru_stime  System time used.

Oh and the header also defines the timeval structure as described in <sys/time.h>. Iconic crossover event. โœจ


๐Ÿ”ฅ RLIMIT constants โ€” possible values for the resource argument ๐Ÿ”ฅ

The header defines these as possible values for the resource argument of getrlimit() and setrlimit():

  • RLIMIT_CORE โ€” limit on size of core file.
  • RLIMIT_CPU โ€” limit on CPU time per process.
  • RLIMIT_DATA โ€” limit on data segment size.
  • RLIMIT_FSIZE โ€” limit on file size.
  • RLIMIT_NOFILE โ€” limit on number of open files.
  • RLIMIT_STACK โ€” limit on stack size.
  • RLIMIT_AS โ€” limit on address space size.

๐Ÿซถ the functions (and maybe macros, she's flexible)

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. Code is code, don't touch it:

int  getpriority(int, id_t);
int  getrlimit(int, struct rlimit *);
int  getrusage(int, struct rusage *);
int  setpriority(int, id_t, int);
int  setrlimit(int, const struct rlimit *);

๐Ÿ’… one more typedef moment

The <sys/resource.h> header defines the id_t type through typedef, as described in <sys/types.h>.

And heads up: including the <sys/resource.h> header may also make visible all symbols from <sys/time.h>. Surprise bonus content. ๐ŸŽ


๐Ÿ“Œ note: the following sections are informative. Not normative, just chatting.

๐Ÿ’ฌ APPLICATION USAGE

None. Literally nothing. Empty. A whole mood. ๐Ÿ’€


๐Ÿง  RATIONALE

None. Again. She said "no thoughts, head empty." ๐Ÿ˜ญ


๐Ÿ”ฎ FUTURE DIRECTIONS

None. The future is undefined and honestly? same. ๐ŸŒˆ


๐Ÿ‘€ SEE ALSO

  • <sys_time.h>
  • <sys_types.h>

The System Interfaces volume of POSIX.1โ€2017, plus:

  • getpriority()
  • getrlimit()
  • getrusage()

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! this lil baddie dropped back in 2017, courtesy of IEEE / The Open Group, and she's filed under sys_resource.h(0P). go set some limits, know your rusage, and slay responsibly. ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from