Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
linux_process_memory
Advanced tools
Ruby gem to get a breakdown of the memory being used by a Linux process. It is specific to Linux and will not work on other operating systems even if they are Linux-like (i.e. MacOS, Windows, FreeBSD, etc.). The breakdown takes into account shared memory and swap memory. It is most useful for monitoring memory usage of processes that use shared memory.
If you need similar functionality like this on other platforms, you can use the get_process_mem gem.
Pass in a process pid to get a breakdown of the memory being used by that process.
memory = LinuxProcessMemory.new(1234)
If you don't pass in a pid, it will get the memory for the current process.
memory = LinuxProcessMemory.new
The memory breakdown is captured at the time the object is created. To get the memory breakdown at a different time, create a new object.
Memory is complicated in Linux and there are many different ways to measure it depending on how you want to count shared memory and swap. This gem provides a few different ways to measure memory usage. The following methods are available:
memory = LinuxProcessMemory.new
memory.total # => total memory used by the process (resident + swap)
memory.swap # => swap memory used
memory.shared # => shared memory used
memory.rss # => resident set size (i.e. non-swap memory allocated)
memory.resident # same as rss
memory.pss # => proportional set size (resident size + shared memory / number of processes)
memory.proportional # same as pss
memory.uss # => unique set size (resident memory not shared with other processes)
memory.unique # same as uss
memory.referenced # => memory actively referenced by the process (i.e. non-freeable memory)
These measurements tend to be the mose useful ones especially if your processes are using shared memory:
Values are returned in bytes, but you can request different units by passing in an optional argument to indicate the unit. Note that requesting a unit other than bytes will return a Float
instead of an Integer
.
memory = LinuxProcessMemory.new
memory.total(:kb) # => total memory used by the process in kilobytes
memory.total(:mb) # => total memory used by the process in megabytes
memory.total(:gb) # => total memory used by the process in gigabytes
This gem is specific to Linux. If you try to use it on a non-Linux platform then memory values will always be returned as -1. If you want to check if the gem is supported on your platform, you can use the supported?
method.
if LinuxProcessMemory.supported?
memory = LinuxProcessMemory.new
end
Here's an example of how you might use this gem to collect memory information on your processes by logging resident memory every minute.
if LinuxProcessMemory.supported?
logger = Logger.new($stderr)
Thread.new do
loop do
memory = LinuxProcessMemory.new
logger.info("Proportional memory: #{memory.pss(:mb).round} MB (pid: #{Process.pid})")
sleep(60)
end
end
end
Add this line to your application's Gemfile:
gem "linux_process_memory"
Then execute:
$ bundle
Or install it yourself as:
$ gem install linux_process_memory
Open a pull request on GitHub.
Please use the standardrb syntax and lint your code with standardrb --fix
before submitting.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that linux_process_memory demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.