Improve ps name parsing

Replaces #8489


My commit cleans up the name parsing logic in `ps`.  For more context about the original issue see the linked PR that this replaces.