0
      #ˆl–ßi~”Je¶…8 �q¦î	•1hßÆ0ÀÈ  0   %ˆl–Ãa¾”ªC]Šu@†ãm\ŠbÑ¿Ç„ï‰ÿ_‹uÐb&=LV[(ÂÊ ?÷     %#
# Copyright (c) 1995-2017 Jarkko Hietaniemi. All rights reserved.
# For license see COPYRIGHT and LICENSE later in this file.
#
# Resource.pm
#

require 5.002;

package BSD::Resource;

use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD $VERSION);

$VERSION = '1.2911';

use Carp;
use AutoLoader;

require Exporter;
require DynaLoader;

@ISA = qw(Exporter DynaLoader);

@EXPORT = qw(
	     PRIO_CONTRACT
	     PRIO_LWP
	     PRIO_MAX
	     PRIO_MIN
	     PRIO_PGRP
	     PRIO_PROCESS
	     PRIO_PROJECT
	     PRIO_SESSION
	     PRIO_TASK
	     PRIO_USER
	     PRIO_ZONE
	     RLIMIT_AIO_MEM
	     RLIMIT_AIO_OPS
	     RLIMIT_AS
	     RLIMIT_CORE
	     RLIMIT_CPU
	     RLIMIT_DATA
	     RLIMIT_FSIZE
	     RLIMIT_FREEMEM
	     RLIMIT_LOCKS
	     RLIMIT_MEMLOCK
	     RLIMIT_MSGQUEUE
	     RLIMIT_NICE
	     RLIMIT_NOFILE
	     RLIMIT_NPROC
	     RLIMIT_NPTS
	     RLIMIT_NTHR
	     RLIMIT_OFILE
	     RLIMIT_OPEN_MAX
	     RLIMIT_POSIXLOCKS
	     RLIMIT_PTHREAD
	     RLIMIT_RSESTACK
	     RLIMIT_RSS
	     RLIMIT_RTPRIO
	     RLIMIT_RTTIME
	     RLIMIT_SBSIZE
	     RLIMIT_SIGPENDING
	     RLIMIT_STACK
	     RLIMIT_SWAP
	     RLIMIT_TCACHE
	     RLIMIT_VMEM
	     RLIM_INFINITY
	     RLIM_NLIMITS
	     RLIM_SAVED_CUR
	     RLIM_SAVED_MAX
	     RUSAGE_BOTH
	     RUSAGE_CHILDREN
	     RUSAGE_SELF
	     RUSAGE_THREAD
	     get_rlimits
	     getpriority
	     getrlimit
	     getrusage
	     setpriority
	     setrlimit
);

Exporter::export_tags();

@EXPORT_OK = qw(times);

# Grandfather old foo_h form to new :foo_h form
sub import {
    my $this = shift;
    my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
    local $Exporter::ExportLevel = 1;
    Exporter::import($this,@list);
}

bootstrap BSD::Resource;

my $EINVAL = constant("EINVAL", 0);
my $EAGAIN = constant("EAGAIN", 0);

sub AUTOLOAD {
    if ($AUTOLOAD =~ /::(_?[a-z])/) {
        $AutoLoader::AUTOLOAD = $AUTOLOAD;
        goto &AutoLoader::AUTOLOAD;
    }
    local $! = 0;
    my $constname = $AUTOLOAD;
    $constname =~ s/.*:://;
    return if $constname eq 'DESTROY';
    my $val = constant($constname, @_ ? $_[0] : 0);
    no strict 'refs';
    if ($! == 0) {
        *$AUTOLOAD = sub { $val };
    }
    elsif ($! == $EAGAIN) {     # Not really a constant, so always call.
        *$AUTOLOAD = sub { constant($constname, $_[0]) };
    }
    elsif ($! == $EINVAL) {
        croak "$constname is not a valid BSD::Resource macro";
    }
    else {
        croak "Your vendor has not defined BSD::Resource macro $constname, used";
    }
    use strict 'refs';

    goto &$AUTOLOAD;
}
use strict;

=pod

=head1 NAME

BSD::Resource - BSD process resource limit and priority functions

=head1 SYNOPSIS

	use BSD::Resource;

	#
	# the process resource consumption so far
	#

	($usertime, $systemtime,
	 $maxrss, $ixrss, $idrss, $isrss, $minflt, $majflt, $nswap,
	 $inblock, $oublock, $msgsnd, $msgrcv,
	 $nsignals, $nvcsw, $nivcsw) = getrusage($ru_who);

	$rusage = getrusage($ru_who);

	#
	# the process resource limits
	#

	($nowsoft, $nowhard) = getrlimit($resource);

	$rlimit = getrlimit($resource);

	$success = setrlimit($resource, $newsoft, $newhard);

	#
	# the process scheduling priority
	#

	$nowpriority = getpriority($pr_which, $pr_who);

	$success = setpriority($pr_which, $pr_who, $priority);

	# The following is not a BSD function.
	# It is a Perlish utility for the users of BSD::Resource.

	$rlimits = get_rlimits();

=head1 DESCRIPTION

=head2 getrusage

	($usertime, $systemtime,
	 $maxrss, $ixrss, $idrss, $isrss, $minflt, $majflt, $nswap,
	 $inblock, $oublock, $msgsnd, $msgrcv,
	 $nsignals, $nvcsw, $nivcsw) = getrusage($ru_who);

	$rusage = getrusage($ru_who);

	# $ru_who argument is optional; it defaults to RUSAGE_SELF

	$rusage = getrusage();

The $ru_who argument is either C<RUSAGE_SELF> (the current process) or
C<RUSAGE_CHILDREN> (all the child processes of the current process)
or it maybe left away in which case C<RUSAGE_SELF> is used.

The C<RUSAGE_CHILDREN> is the total sum 