Skip to content

Add ps syscall and userspace ps command#481

Open
ankitpokhrel08 wants to merge 2 commits intomit-pdos:riscvfrom
ankitpokhrel08:riscv
Open

Add ps syscall and userspace ps command#481
ankitpokhrel08 wants to merge 2 commits intomit-pdos:riscvfrom
ankitpokhrel08:riscv

Conversation

@ankitpokhrel08
Copy link
Copy Markdown

I implemented a new ps feature in xv6 that exposes active process information from kernel space to userspace through a dedicated syscall.

This PR adds a full end-to-end syscall path
(userspace -> syscall stub -> syscall dispatcher -> kernel worker -> copyout -> userspace print)
and a simple ps command to validate behaviour from the shell.

What I changed

  • Added a new syscall number for ps
  • Added kernel syscall handler and dispatcher wiring
  • Implemented kernel process walker that:
    • Iterates process table
    • Collects active processes SLEEPING, RUNNABLE, RUNNING
    • Copies process info safely back to userspace copyout
  • Added shared process info struct for kernel-userspace contract
  • Added userspace syscall declaration and stub generation
  • Added userspace ps command
  • Updated build config to include ps program in user binaries

Why this change
The goal was to implement a realistic syscall pattern and practice core OS concepts:

  • argument passing from userspace to kernel
  • safe memory transfer across the privilege boundary
  • process table traversal with locking
  • syscall dispatch integration
    Sample output
image

How I tested

  • Built xv6 and booted in QEMU
  • Ran ps at idle and verified base processes (init, sh, ps )
    image

  • Spawned background workloads (e.g. sleep) and confirmed they appear in ps
    image

  • Re-ran ps multiple times to confirm stable syscall behaviour and expected state transitions [After 10 sec]
    image

Notes

  • The command intentionally shows only active processes for clarity.
  • ps appears as running while it is executing, which is expected.

@ankitpokhrel08
Copy link
Copy Markdown
Author

Case Study on Operating System as a part of the Operating System course completed!

@ankitpokhrel08
Copy link
Copy Markdown
Author

Also added a userspace sleep command sleep.c, sleep N now maps to roughly N seconds (tick-based via pause()), which makes ps demos much easier. You can now run sleep 1 & and immediately observe the process in SLEEPING state via ps.

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