From: Stefan Schantl Date: Wed, 29 Aug 2018 08:55:32 +0000 (+0200) Subject: ids.cgi: Fix get_memory_usage() X-Git-Tag: suricata-beta3~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=004b13b7e801c18d399740c4e9b7866c9685637c;p=people%2Fstevee%2Fipfire-2.x.git ids.cgi: Fix get_memory_usage() Change the get_memory_usage() function to grab and return the memory usage of the entire process, containing all sub-processes and threads. Fixes #11821 Signed-off-by: Stefan Schantl --- diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index d3c68711ce..045211298f 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -824,28 +824,36 @@ sub readrulesfile ($) { ## Function to get the used memory of a given process-id. # sub get_memory_usage($) { - my $pid = @_; + my ($pid) = @_; - my $memory=0; + my $memory = 0; - # Try to open statm file for the given process-id on the pseudo + # Try to open the status file for the given process-id on the pseudo # file system proc. - if (open(FILE, "/proc/$pid/statm")) { - # Read file content. - my $temp = ; - - # Splitt file content and store in an array. - my @memory = split(/ /,$temp); + if (open(FILE, "/proc/$pid/status")) { + # Loop through the entire file. + while () { + # Splitt current line content and store them into variables. + my ($key, $value) = split(":", $_, 2); + + # Check if the current key is the one which contains the memory usage. + # The wanted one is VmRSS which contains the Real-memory (resident set) + # of the entire process. + if ($key eq "VmRSS") { + # Found the memory usage add it to the memory variable. + $memory += $value; + + # Break the loop. + last; + } + } # Close file handle. - close(FILE); - - # Calculate memory usage. - $memory+=$memory[0]; + close(FILE); # Return memory usage. return $memory; - } + } # If the file could not be open, return nothing. return;