Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to parse 'ps wwl' for better compatibility #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

uranusjr
Copy link
Member

The “Berkeley standard’ argument has better compatibility than either BSD or GNU standard.

Fix #21, close #22.

@kadler and @sirn It’d be wonderful if you could test this on your environments to make sure things still work.

The "Berkeley standard" argument has better compatibility than either
BSD or GNU standard. The output is unfortunately much more difficult to
parse.
@kadler
Copy link

kadler commented Mar 18, 2019

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/QOpenSys/pkgs/lib/python3.6/site-packages/shellingham/posix/ps.py", line 115, in get_process_mapping
    return dict(_parse_ps_output(output))
  File "/QOpenSys/pkgs/lib/python3.6/site-packages/shellingham/posix/ps.py", line 100, in _parse_ps_output
    for k in ('pid', 'ppid', 'command')
  File "/QOpenSys/pkgs/lib/python3.6/site-packages/shellingham/posix/ps.py", line 100, in <genexpr>
    for k in ('pid', 'ppid', 'command')
KeyError: 'command'

On AIX/PASE, this is CMD, not COMMAND

@uranusjr
Copy link
Member Author

Arrrrg! Why IBM, why.

This works around the discrepancy in column naming between different ps
implementations.
@uranusjr
Copy link
Member Author

OK. How about this.

@kadler
Copy link

kadler commented Mar 19, 2019

Still not right:

Python 3.6.8 (default, Mar 15 2019, 19:26:20) 
[GCC 6.3.0] on aix6
Type "help", "copyright", "credits" or "license" for more information.
>>> import shellingham.posix.ps as ps
>>> print(ps._get_ps_output())
     F S      UID    PID   PPID   C PRI NI ADDR  SZ  RSS   WCHAN    TTY  TIME CMD
240000 A      105 932687 932686   0  20 20    0 7516    0          pts/0  0:00 -bash 
200000 A      105 932807 932687   0  20 20    0 16504    0          pts/0  0:00 python3 
200000 A      105 932808 932807   0  20 20    0 6792    0          pts/0  0:00 ps wwl 

>>> from pprint import pprint
>>> pprint(ps.get_process_mapping())
{'932687': Process(args=('0', '-bash'), pid='932687', ppid='932686'),
 '932807': Process(args=('00', 'python3'), pid='932807', ppid='932687'),
 '932810': Process(args=('0', 'ps', 'wwl'), pid='932810', ppid='932807')}

The assumption that the column header offsets match the columns is not correct on the AIX ps. Here's another example that's even worse:

     F S UID      PID     PPID   C PRI NI ADDR  SZ  RSS   WCHAN    TTY  TIME CMD
240001 A 203 14549132  8192226   1  60 20 96aaf7590 2620 2552          pts/0  0:00 -bash 
200001 A 203 16384118 14549132   3  61 20 8aaeeb590 1440 1468          pts/0  0:00 ps wwl

@uranusjr
Copy link
Member Author

What is IBM even doing. I can’t even read that output as a human.

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.

detect_shell fails on IBM i / AIX
2 participants