-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
@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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
typings/windows-process-tree.d.ts
Outdated
} | ||
|
||
export interface IProcessInfo { | ||
pid: number; | ||
ppid: number; | ||
name: string; | ||
memory?: number; | ||
arguments?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commandLine
On my machine, calling getProcessList with only the args flag is under 20ms. |
There was a problem hiding this 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.
typings/windows-process-tree.d.ts
Outdated
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. |
There was a problem hiding this comment.
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
typings/windows-process-tree.d.ts
Outdated
} | ||
|
||
export interface IProcessInfo { | ||
pid: number; | ||
ppid: number; | ||
name: string; | ||
memory?: number; | ||
commandLine?: string; |
There was a problem hiding this comment.
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.
typings/windows-process-tree.d.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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
Use NtQueryInformationProcess to get the command line arguments of a process