menios icon indicating copy to clipboard operation
menios copied to clipboard

Improved ps command to match Linux behavior

Open pbalduino opened this issue 3 months ago • 0 comments

Description

The current ps command in meniOS provides basic process listing functionality, but it doesn't match the behavior and output format of its Linux counterpart. We should improve it to be more familiar to users while working within meniOS's current limitations.

Current State

The existing ps implementation is a minimal utility that lists processes. It lacks many features that users expect from a standard ps command.

Proposed Changes

Enhance ps to support common Linux ps features, adapted for meniOS:

Output Format

  • Standard columns: PID, PPID, STATE, CMD
  • Optional columns (where applicable):
    • %CPU - CPU usage percentage (if scheduler tracking is available)
    • %MEM - Memory usage percentage
    • TIME - CPU time consumed
    • VSZ - Virtual memory size
    • RSS - Resident set size (if available)

Command-Line Options

Implement common ps flags:

  • ps (no args) - Show processes for current session/terminal
  • ps -e or ps -A - Show all processes
  • ps -f - Full-format listing (add PPID, START time if available)
  • ps -l - Long format with additional fields
  • ps -u <user> - Filter by user (placeholder for future user support)
  • ps aux - BSD-style: all processes with user-oriented output
  • ps -p <pid> - Show specific process(es)

Process State Display

Map meniOS process states to standard Linux codes:

  • R - Running
  • S - Sleeping/Blocked
  • Z - Zombie
  • T - Stopped
  • D - Uninterruptible sleep (if applicable)

Adaptation to meniOS Limitations

No TTY support:

  • Show ? or - in TTY column
  • Don't filter by controlling terminal

No user/group management:

  • Show numeric UID/GID as 0 or placeholder
  • Skip user-based filtering (or stub it for future)

No session/process group tracking (if not implemented):

  • Show placeholder values or omit columns

Limited time tracking:

  • Use available kernel timing if present
  • Show - or 0:00 if not available

Implementation Tasks

  • [ ] Add command-line argument parsing (-e, -f, -l, -aux, -p, etc.)
  • [ ] Implement column-based output formatting
  • [ ] Add process state translation to standard codes
  • [ ] Query kernel for extended process information (memory, time, parent PID)
  • [ ] Handle edge cases (zombie processes, kernel threads)
  • [ ] Add header row for column identification
  • [ ] Implement sorting (by PID by default)
  • [ ] Add man page or help text (ps --help)

Example Output

$ ps
  PID  PPID STATE CMD
    1     0 S     /sbin/init
   42     1 S     /bin/mosh
   43    42 R     ps

$ ps -ef
  PID  PPID STATE  TIME CMD
    1     0 S     0:00 /sbin/init
   42     1 S     0:02 /bin/mosh
   43    42 R     0:00 ps -ef

$ ps aux
USER  PID %CPU %MEM   VSZ  RSS STATE START TIME CMD
root    1  0.0  1.2  4096 2048 S     00:00 0:00 /sbin/init
root   42  0.1  2.4  8192 4096 S     00:01 0:02 /bin/mosh
root   43  0.0  0.8  2048 1024 R     00:03 0:00 ps aux

Dependencies

  • Kernel must expose process information via syscalls or /proc-like interface
  • May depend on enhanced process tracking in the kernel (parent PID, resource usage)

Related Issues

  • Complements existing shell utilities (#183)
  • May benefit from procfs implementation (if planned)

Acceptance Criteria

  • [ ] ps with no arguments shows current processes
  • [ ] ps -e shows all system processes
  • [ ] Output includes standard columns (PID, PPID, STATE, CMD)
  • [ ] Process states match Linux conventions (R, S, Z, T, D)
  • [ ] Works correctly with meniOS limitations (no TTY, no users)
  • [ ] Help text available (ps --help)

Notes

This enhancement makes meniOS more familiar to Linux users while respecting current system limitations. As meniOS gains features (TTY, users, sessions), ps can be incrementally enhanced to support them.

pbalduino avatar Oct 16 '25 19:10 pbalduino