1 package SL::System::Process;
5 use parent qw(Rose::Object);
7 use English qw(-no_match_vars);
11 use List::Util qw(first);
16 return $cached_exe_dir if defined $cached_exe_dir;
18 my $bin_dir = File::Spec->rel2abs($FindBin::Bin);
19 my @dirs = File::Spec->splitdir($bin_dir);
21 $cached_exe_dir = first { -f File::Spec->catdir(@dirs[0..$_], 'SL', 'System', 'TaskServer.pm') }
22 reverse(0..scalar(@dirs) - 1);
23 $cached_exe_dir = defined($cached_exe_dir) ? File::Spec->catdir(@dirs[0..$cached_exe_dir]) : File::Spec->curdir;
25 return $cached_exe_dir;
28 sub _parse_number_with_unit {
31 return undef unless defined $number;
32 return $number unless $number =~ m{^ \s* (\d+) \s* ([kmg])b \s* $}xi;
34 my %factors = (K => 1024, M => 1024 * 1024, G => 1024 * 1024 * 1024);
36 return $1 * $factors{uc $2};
39 sub memory_usage_is_too_high {
40 return undef unless $::lx_office_conf{system};
43 rss => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_rss}),
44 size => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_vsz}),
47 # $::lxdebug->dump(0, "limits", \%limits);
49 return undef unless $limits{rss} || $limits{vsz};
53 my $in = IO::File->new("/proc/$$/status", "r") or return undef;
57 $usage{lc $1} = _parse_number_with_unit($2) if m{^ vm(rss|size): \s* (\d+ \s* [kmg]b) \s* $}ix;
62 # $::lxdebug->dump(0, "usage", \%usage);
64 foreach my $type (keys %limits) {
65 next if !$limits{$type};
66 next if $limits{$type} >= ($usage{$type} // 0);
70 $::lxdebug->message(LXDebug::WARN(), "Exiting due to memory size limit reached for type '${type}': limit " . $limits{$type} . " bytes, usage " . $usage{$type} . " bytes");
88 SL::System::Process - assorted system-relevant functions
92 # Get base path to kivitendo scripts
93 my $path = SL::System::Process->exe_dir;
101 Returns the absolute path to the directory the kivitendo executables
102 (C<login.pl> etc.) and modules (sub-directory C<SL/> etc.) are located
105 =item C<memory_usage_is_too_high>
107 Returns true if the current process uses more memory than the configured
118 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>