Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID is not respected on MacOS/Darwin platform #39

Closed
edariedl opened this issue Apr 4, 2020 · 2 comments
Closed

PID is not respected on MacOS/Darwin platform #39

edariedl opened this issue Apr 4, 2020 · 2 comments

Comments

@edariedl
Copy link

edariedl commented Apr 4, 2020

get_process_mem always returns memory used by current process. It does not respect PID.

Here are some tests from irb

irb(main):001:0> require 'get_process_mem'
=> true
irb(main):002:0> GetProcessMem.new.kb
=> 17744.0
irb(main):003:0> `ps -o rss= -p #{Process.pid}`
=> " 17836\n"

but if I try to get memory of different process

irb(main):004:0> GetProcessMem.new(84330).kb
=> 17860.0
irb(main):005:0> `ps -o rss= -p 84330`
=> " 75104\n"

I'll get back the same amount of memory as I've got for the current process.

This issue was introduced by the pull request #32. Code for Darvin platform doesn't use PID to determine used RAM, it always returns used RAM for current process.

@schneems schneems changed the title PID is not respected on MacOS/Darvin platform PID is not respected on MacOS/Darwin platform Aug 25, 2020
schneems added a commit that referenced this issue Aug 25, 2020
Currently when you call `GetProcessMem.new` with a different pid value than the current process it calls `GetProcessMem::Darwin.resident_size this uses FFI to get data from the mach kernel about the current process.

- #32
- https://stackoverflow.com/questions/18389581/memory-used-by-a-process-under-mac-os-x/23379216#23379216

This PR adds a test to ensure that memory results from different processes is correctly reported.

This PR addresses the different PID problem by checking if a different pid other than Process.pid is being passed in. If that's the case then we will fall back to determining memory based off of shelling out to `ps`.

There was a performance concern over using `Process.pid` but it appears to be relatively fast. It is approximately the speed of allocating 3 string object.
@schneems
Copy link
Member

I've got a workaround on #41

schneems added a commit that referenced this issue Aug 25, 2020
[close #39] Supporting different PIDs on Mac
@schneems
Copy link
Member

This is fixed and released in 0.2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants