sys_resource.h(7POSIX)

๐Ÿ’– sys_resource.h โ€” the POSIX page, but make it bestie ๐Ÿ’–

okay so this is sys_resource.h from the POSIX Programmer's Manual (that's the 7POSIX section, for the uninitiated). come sit with me, we're gonna get through this together, it's literally so much shorter than it looks ๐Ÿซถ


๐ŸŒธ PROLOG ๐ŸŒธ

bestie. real talk. this manual page is part of the POSIX Programmer's Manual, right? and the tea is: the Linux implementation of this interface may differ โ€” so if you're on Linux, go consult the corresponding Linux manual page for the details of Linux behavior. OR. plot twist. the interface may not be implemented on Linux at all. ๐Ÿ’€ so like. vibe check your platform first, fr fr.


โœจ NAME โœจ

sys/resource.h โ€” definitions for XSI resource operations ๐Ÿ‘‘


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <sys/resource.h>

that's it. that's the whole synopsis. iconic.


๐Ÿ’… DESCRIPTION ๐Ÿ’…

okay so here's what this header is gonna do for you. it's a header, it's got lore, let's go section by section because there's a lot of little constants and they all matter.

the which girls (for getpriority() and setpriority()) ๐ŸŒˆ

<sys/resource.h> shall define these symbolic constants as possible values of the which argument of getpriority() and setpriority():

  • 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 moment ๐Ÿฆ‹

the header shall define this type through typedef:

  • rlim_t โ€” an unsigned integer type used for limit values. she's the limit girlie.

the #if-safe constants โญ

these symbolic constants get defined, and their values shall be suitable for use in #if preprocessing directives (yes, in the preprocessor, not just at runtime โ€” that's the whole point):

  • RLIM_INFINITY โ€” a value of rlim_t indicating no limit.
  • 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 cute little footnote: on implementations where all resource limits are representable in an object of type rlim_t, RLIM_SAVED_MAX and RLIM_SAVED_CUR need not be distinct from RLIM_INFINITY. so don't be out here assuming they're different, okay? ๐Ÿ™ˆ

the who girls (for getrusage()) ๐Ÿ“

<sys/resource.h> shall define these symbolic constants as possible values of the who parameter of getrusage():

  • RUSAGE_SELF โ€” returns information about the current process.
  • RUSAGE_CHILDREN โ€” returns information about children of the current process.

struct rlimit ๐Ÿงš

the header shall define the rlimit structure, and it shall include at least these members:

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

struct rusage ๐Ÿ’œ

the header shall define the rusage structure, and it shall include at least these members:

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

and where does struct timeval come from? <sys/resource.h> shall define the timeval structure as described in <sys/time.h>. no reinventing the wheel here, bestie.

the resource constants (for getrlimit() and setrlimit()) ๐Ÿ”ฅ

<sys/resource.h> shall define these symbolic constants 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 ๐Ÿ‘‘

these shall be declared as functions, and they may also be defined as macros. function prototypes shall be provided:

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 *);

and one more typedef ๐ŸŒธ

<sys/resource.h> shall define the id_t type through typedef, as described in <sys/types.h>.

sneaky bonus symbols ๐Ÿ‘€

inclusion of the <sys/resource.h> header may also make visible all symbols from <sys/time.h>. so like, free real estate, maybe. "may." don't come for me.

heads up: the following sections are informative โ€” they're not normative, they're just vibes and context. ๐Ÿ’ซ

๐Ÿซถ APPLICATION USAGE ๐Ÿซถ

None. nothing. empty. the void. and honestly? respect. ๐Ÿ˜Œ


๐Ÿ’ญ RATIONALE ๐Ÿ’ญ

None. again โ€” nothing. no thoughts, head empty, and it's serving. โœจ


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None. the future is bright and completely undefined for this one. slay. ๐Ÿ’…


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • <sys_time.h>
  • <sys_types.h>
  • the System Interfaces volume of POSIX.1โ€2017: getpriority(), getrlimit(), getrusage()

go read those, bestie, that's where the actual behavior lives. iykyk ๐Ÿฆ‹


okay so legally I have to tell you this, and I'm gonna tell you this properly:

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 .


not me having to cite my sources like a good academic girlie ๐Ÿ’€ โ€” this page came from IEEE/The Open Group, dated 2017, and it lives at sys_resource.h(7POSIX). mwah. take care of her. ๐ŸŽ€๐Ÿ’–โœจ
๐Ÿ“ฆ where this page comes from