Skip to content

fix: add macOS support for process uptime retrieval#14

Open
bianbiandashen wants to merge 1 commit into
runta-dev:mainfrom
bianbiandashen:fix/macos-process-uptime
Open

fix: add macOS support for process uptime retrieval#14
bianbiandashen wants to merge 1 commit into
runta-dev:mainfrom
bianbiandashen:fix/macos-process-uptime

Conversation

@bianbiandashen

Copy link
Copy Markdown
Contributor

Summary

  • Add macOS support for get_process_uptime() function
  • Previously, this function only worked on Linux (using /proc/{pid}/stat)
  • Now uses ps -o etime= on macOS to get elapsed time

Why

The existing implementation relied on the Linux-specific /proc filesystem, which doesn't exist on macOS. This caused get_process_uptime() to always return None on macOS.

Changes

  • src/process.rs:
    • Split get_process_uptime into get_process_uptime_linux and get_process_uptime_macos using #[cfg]
    • Add parse_etime() function to parse ps output format ([[DD-]HH:]MM:SS)
    • Add unit tests for etime parsing on macOS
    • Update test_get_process_uptime_self to work on both platforms

Test plan

  • Tested on macOS - now returns correct uptime
  • Linux implementation unchanged
  • New macOS-specific unit tests pass

The get_process_uptime() function was using Linux-specific /proc
filesystem, which doesn't exist on macOS. This adds a macOS-specific
implementation using `ps -o etime=` command.

Changes:
- Split get_process_uptime into platform-specific implementations
- Add parse_etime() to parse ps etime output format on macOS
- Add macOS-specific unit tests for etime parsing
- Update test_get_process_uptime_self to work on both platforms
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

Successfully merging this pull request may close these issues.

1 participant