File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22const path = require ( 'path' ) ;
33const childProcess = require ( 'child_process' ) ;
4- const tasklist = require ( 'tasklist' ) ;
54const pify = require ( 'pify' ) ;
65
76const TEN_MEGABYTES = 1000 * 1000 * 10 ;
87
98function win ( ) {
10- return tasklist ( ) . then ( data => {
11- return data . map ( x => {
12- return {
13- pid : x . pid ,
14- name : x . imageName ,
15- cmd : x . imageName
16- } ;
17- } ) ;
18- } ) ;
9+ // Source: https://github.com/MarkTiedemann/fastlist
10+ const bin = path . join ( __dirname , 'fastlist.exe' ) ;
11+
12+ return pify ( childProcess . execFile ) ( bin , { maxBuffer : TEN_MEGABYTES } )
13+ . then ( stdout =>
14+ stdout . trim ( )
15+ . split ( '\r\n' )
16+ . map ( line => line . split ( '\t' ) )
17+ . map ( ( [ name , pid , ppid ] ) => ( {
18+ name,
19+ pid : Number . parseInt ( pid , 10 ) ,
20+ ppid : Number . parseInt ( ppid , 10 )
21+ } ) )
22+ ) ;
1923}
2024
2125function def ( options = { } ) {
Original file line number Diff line number Diff line change 2828 " tasklist"
2929 ],
3030 "dependencies" : {
31- "pify" : " ^3.0.0" ,
32- "tasklist" : " ^3.1.0"
31+ "pify" : " ^4.0.0"
3332 },
3433 "devDependencies" : {
3534 "ava" : " *" ,
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ const psList = require('ps-list');
2323})();
2424```
2525
26- > The ` cpu ` , ` memory ` , and ` ppid ` properties are not supported on Windows.
26+ > The ` cmd ` , ` cpu ` , and ` memory ` properties are not supported on Windows.
2727
2828
2929## API
Original file line number Diff line number Diff line change @@ -12,19 +12,17 @@ test('main', async t => {
1212 list . every ( x =>
1313 typeof x . pid === 'number' &&
1414 typeof x . name === 'string' &&
15- typeof x . cmd === 'string '
15+ typeof x . ppid === 'number '
1616 )
1717 ) ;
1818
1919 if ( ! isWindows ) {
2020 t . true (
2121 list . every ( x =>
22+ typeof x . cmd === 'string' &&
2223 typeof x . cpu === 'number' &&
2324 typeof x . memory === 'number'
2425 )
2526 ) ;
26- t . true (
27- list . every ( x => typeof x . ppid === 'number' )
28- ) ;
2927 }
3028} ) ;
You can’t perform that action at this time.
0 commit comments