Open System Services Programmer's Guide

Using the OSS API
OSS functions provide information about process times (times()), environment variables
(getenv()), user IDs (getuid(), geteuid()), groups and group IDs (getgroups(),
getgid(), getegid()), and system limits (sysconf()) for OSS and Guardian processes.
Because Guardian processes do not have OSS process IDs and cannot belong to process groups,
the getpid(), getppid(), and getpgrp() functions operate only on OSS processes. You can
call sysconf() from a Guardian process, but it is not meaningful to do so.
Example 33 gets the system-dependent system limits of a process and sends their values to the
standard output file. The system limits shown in this example are not in the limits.h header file
because they are not available at compile time.
Example 33 Getting Information About System Limits Using sysconf()
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void pr_sysconf(char *, int);
int main (int argc, char *argv[])
{
/* Retrieve system-dependent system limits. */
pr_sysconf("ARG_MAX =", _SC_ARG_MAX);
pr_sysconf("CHILD_MAX =", _SC_CHILD_MAX);
pr_sysconf("clock ticks/second =", _SC_CLK_TCK);
pr_sysconf("NGROUPS_MAX =", _SC_NGROUPS_MAX);
pr_sysconf("OPEN_MAX =", _SC_OPEN_MAX);
#ifdef _SC_STREAM_MAX
pr_sysconf("STREAM_MAX =", _SC_STREAM_MAX);
#endif
#ifdef _SC_TZNAME_MAX
pr_sysconf("TZNAME_MAX =", _SC_TZNAME_MAX);
#endif
pr_sysconf("_POSIX_JOB_CONTROL =", _SC_JOB_CONTROL);
pr_sysconf("_POSIX_SAVED_IDS =", _SC_SAVED_IDS);
pr_sysconf("_POSIX_VERSION =", _SC_VERSION);
exit(0);
}
/* This function displays system-dependent limits to standard output.*/
static void pr_sysconf(char *mesg, int name)
{
long val;
fputs(mesg, stdout);
errno = 0;
if ( (val = sysconf(name)) < 0) {
if (errno != 0) {
printf("sysconf error\n"); /* not a valid constant name */
exit(1);
}
fputs(" (not defined)\n", stdout); /* value is indeterminate */
} else
printf(" %ld\n", val);
}
130 Managing Processes