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

Parse OSX process details correctly #64

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

Parse OSX process details correctly #64

wants to merge 3 commits into from

Conversation

milankinen
Copy link

Hello!

Here is a fix for #62. TableParser was a bit too generic so I tailored the parsing logic for ps in order to improve robustness. I added a test case based on the given example output from #62.

I hope we can get this fix released asap. Our testing pipeline needs this fix because testcafe (which depends on this package) can't parse browser PID correctly, hence leaving the browser process open after every test run. 😕

@milankinen
Copy link
Author

@neekey have you had time to look at this yet?

@neekey
Copy link
Owner

neekey commented Aug 14, 2017

Hi @milankinen thanks for your PR. Your way of parsing the output is quite the same as the original version of this module, which works in this case but will fail in other cases as well, so I won't accept this as a solution, though it works in your case.

you can take a look at this discussion neekey/table-parser#3 (comment), there are more cases like the discussion mentioned.

Actually table-parser has done its best already (since it tries to catch as much edge cases as it can), but it can't work well if the input's format is very hard to predict, there is a boundary needs to be set for table-parser's ability.

So instead of improving table-parser itself, I am thinking if there's any way to regulate the output format of ps, which is the core part of the issue. (like @falconscript did here #62 (comment))

@neekey
Copy link
Owner

neekey commented Aug 14, 2017

yes, I think I can definitely narrow down the metrics to only pid, command, arguments, ppid

@milankinen
Copy link
Author

milankinen commented Aug 14, 2017

which works in this case but will fail in other cases as well

I coudn't find those cases (not even from the table parser thread you posted). Could you provide a link to them?

So instead of improving table-parser itself, I am thinking if there's any way to regulate the output format of ps, which is the core part of the issue.

Yes that's definitely the right way, although it'd introduce non-backwards compatible API changes. The purpose of this PR is to fix the parsing without breaking the backwards compatibility so that's why I thought it could be the first step.

@lkounadis
Copy link

Hello, when will this commit be merged into the release branch? I am dealing with an error and this is the solution needed.. I am currently using this commit in order to work now. would appreciate it if we could get in though..

@raszi
Copy link

raszi commented Oct 26, 2017

I believe you could run the ps with the following args on BSDs and macOS:

$ ps -x -opid,ppid,command|head -3
  PID  PPID COMMAND
  308     1 /usr/sbin/cfprefsd agent
  313     1 /usr/sbin/distnoted agent

Empact added a commit to Empact/zap-desktop that referenced this pull request Dec 24, 2017
On mac, the ps output can be misaligned, e.g. when some VSZ field is
longer than expected.

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the default fields of ps.

neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Dec 25, 2017
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Dec 25, 2017
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Dec 26, 2017
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Dec 29, 2017
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jan 2, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jan 5, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jan 10, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jan 20, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jan 22, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Mar 17, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jun 6, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Jun 15, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
Empact added a commit to Empact/zap-desktop that referenced this pull request Aug 17, 2018
`ps x -o pid,command` rather than `ps lx`

The default ps-node lookup is via ps lx, which includes:

  -l Display information associated with the following keywords:
    uid, pid, ppid, flags, cpu, pri, nice, vsz=SZ, rss, wchan,
    state=S, paddr=ADDR, tty, time, and command=CMD.

On mac, the `ps l` output can be misaligned, e.g. when some VSZ field is
longer than expected.

Many of these fields are unnecessary because we're looking up by name only,
so we can lookup using only the command fields of ps.
https://gist.github.com/ivankovacevic/9918272

More on the issue with ps-node:
neekey/table-parser#11
neekey/ps#64
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.

4 participants