Skip to content

Add flag for getting command line arguments of processes #17

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

Merged
merged 3 commits into from
Mar 23, 2018

Conversation

RMacfarlane
Copy link
Contributor

Use NtQueryInformationProcess to get the command line arguments of a process

@RMacfarlane RMacfarlane added this to the 0.2.0 milestone Mar 22, 2018
@RMacfarlane RMacfarlane self-assigned this Mar 22, 2018
@RMacfarlane RMacfarlane requested a review from Tyriar March 22, 2018 18:43
@Tyriar
Copy link
Member

Tyriar commented Mar 22, 2018

@RMacfarlane could you gauge how fast it is now to just query for args? (no memory/cpu)

src/process.h Outdated
@@ -21,11 +21,13 @@ struct ProcessInfo {
DWORD pid;
DWORD ppid;
DWORD memory; // Reported in bytes
TCHAR arguments[512];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice below you trim if the command line goes over, is there a actual maximum value we could use here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual maximum is 8191 (at least for processes run from cmd line), but increasing it beyond ~720 causes the JS tests to error out without any message. I tried switching to allocating the ProcessInfo array on the heap, but that causes a heap out of memory exception when running the tests with the current size.

Earlier I thought I was seeing nondeterministic failures when it was set to 720, so I'm wary of increasing it close to that. My guess is that it failed because it wasn't able to find a piece of contiguous memory large enough, even though its not a particularly large array, ~54k.

lib/index.ts Outdated
@@ -8,7 +8,8 @@ import { IProcessInfo, IProcessTreeNode, IProcessCpuInfo } from 'windows-process

export enum ProcessDataFlag {
None = 0,
Memory = 1
Memory = 1,
Arguments = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this again we should probably name this "CommandLine" instead of Arguments as that's the Windows terminology for the exe+args.

}

export interface IProcessInfo {
pid: number;
ppid: number;
name: string;
memory?: number;
arguments?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commandLine

@RMacfarlane
Copy link
Contributor Author

On my machine, calling getProcessList with only the args flag is under 20ms.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Good to merge after the few comment related changes.

children: IProcessTreeNode[];
}



/**
* Returns a tree of processes with the rootPid process as the root.
* @param {number} rootPid - The pid of the process that will be the root of the tree.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should omit the types here as they are redundant and could succumb to bit rot

}

export interface IProcessInfo {
pid: number;
ppid: number;
name: string;
memory?: number;
commandLine?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a note here about the 512 maximum, you don't need to explain it, just state that it's cut off.

@@ -6,14 +6,16 @@
declare module 'windows-process-tree' {
export enum ProcessDataFlag {
None = 0,
Memory = 1
Memory = 1,
CommandLine = 2
}

export interface IProcessInfo {
pid: number;
ppid: number;
name: string;
memory?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdoc explaining the unit would be good

@RMacfarlane RMacfarlane merged commit d6bbc51 into master Mar 23, 2018
@RMacfarlane RMacfarlane deleted the rmacfarlane/args branch March 23, 2018 18:35
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.

2 participants