import { exec } from "child_process" ; import { promisify } from "util" ; import { getPlatform } from "./get-platform" ; const execute = promisify ( exec ) ; export const getAllChildProccess = async ( pid ) : Promise < number [ ] > => { const platform = getPlatform ( ) ; const command = ( ( { platform , pid , } ) => { switch ( platform ) { case "unix" : return `pgrep "-P ${ pid }"` ; case "windows" : return `wmic process where (ParentProcessId=${ pid }) get ProcessId` ; default : throw new Error ( "Unable to find parent process" ) ; } } ) ( { platform , pid } ) ; let messages = [ ] ; try { const { stdout } = await execute ( command ) ; messages = stdout . split ( `\n` ) . filter ( Boolean ) . map ( ( value ) => parseInt ( value , 10 ) ) . filter ( ( value ) => ! isNaN ( value ) ) ; } catch ( e ) { } return messages ; } ;