Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Psh / Builtins / Ulimit.pm
CommitLineData
86530b38
AT
1package Psh::Builtins::Ulimit;
2
3require Psh::Util;
4
5my %map= (
6 c => 'RLIMIT_CORE',
7 d => 'RLIMIT_DATA',
8 f => 'RLIMIT_FSIZE',
9 l => 'RLIMIT_MEMLOCK',
10 m => 'RLIMIT_RSS',
11 n => 'RLIMIT_NOFILE',
12 u => 'RLIMIT_NPROC',
13 s => 'RLIMIT_STACK',
14 t => 'RLIMIT_CPU',
15 v => 'RLIMIT_AS',
16 );
17my %desc=(
18 RLIMIT_CORE => 'maximum size of core files',
19 RLIMIT_DATA => 'maximum size of data segment',
20 RLIMIT_FSIZE => 'maximum file size',
21 RLIMIT_MEMLOCK => 'maximum size of locked memory',
22 RLIMIT_RSS => 'maximum resident size',
23 RLIMIT_NOFILE => 'maximum number of open files',
24 RLIMIT_NPROC => 'maximum number of user processes',
25 RLIMIT_STACK => 'maximum stack size',
26 RLIMIT_CPU => 'maximum cpu time',
27 RLIMIT_AS => 'size of virtual memory',
28 );
29
30sub bi_ulimit {
31 my $arg= shift;
32 local @ARGV = @{shift()};
33
34 eval {
35 require BSD::Resource;
36 };
37 if ($@) {
38 Psh::Util::print_error_i18n('bi_bsdresource');
39 return (0,undef);
40 }
41 eval {
42 require Getopt::Std;
43 };
44 my $limits= BSD::Resource::get_rlimits();
45
46 push @ARGV,'-c' unless @ARGV;
47
48 my $type='S';
49 my $opts= join('', keys %map,'SHa');
50 my %opts=();
51 Getopt::Std::getopts($opts,\%opts);
52
53 if ($opts{'H'}) {
54 $type='H';
55 }
56 if ($opts{'a'}) {
57 foreach (keys %$limits) {
58 my ($soft, $hard)= BSD::Resource::getrlimit($limits->{$_});
59 my $val= $soft;
60 $val= $hard if $type eq 'H';
61 $val= 'unlimited' if $val<0;
62 next unless $desc{$_};
63 Psh::Util::print_out(sprintf("%-50s %s\n",$desc{$_},$val));
64 }
65 }
66 return (1,undef);
67}
68
691;