Skip to content

Commit

Permalink
Ensure PID is an integer
Browse files Browse the repository at this point in the history
This ensures that the `ps` call doesn't invoke something else.
  • Loading branch information
stanhu committed Mar 15, 2021
1 parent 2897a5a commit c6fb539
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (unreleased)

- Ensure PID is an integer (https://github.com/schneems/get_process_mem/pull/46)

## 0.2.7

- Native (faster) support for returning memory from different PIDs on mac (https://github.com/schneems/get_process_mem/pull/42)
Expand Down
2 changes: 1 addition & 1 deletion lib/get_process_mem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class GetProcessMem
def initialize(pid = Process.pid)
@status_file = Pathname.new "/proc/#{pid}/status"
@process_file = Pathname.new "/proc/#{pid}/smaps"
@pid = pid
@pid = Integer(pid)
@linux = @status_file.exist?
end

Expand Down
9 changes: 9 additions & 0 deletions test/get_process_mem_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def test_different_pid_returns_different_memory
Process.wait(pid) if pid
end

def test_invalid_pid
raised_exception = false
GetProcessMem.new('ls')
rescue ArgumentError
raised_exception = true
ensure
assert raised_exception
end

def test_seems_to_work
assert @mem.kb > 0
assert @mem.mb > 0
Expand Down

0 comments on commit c6fb539

Please sign in to comment.