Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/find_pid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from 'os'
import * as fs from 'fs'
import utils from './utils'
import * as os from 'os'
import log from './logger'
import utils from './utils'

const ensureDir = (path: string): Promise<void> => new Promise((resolve, reject) => {
if (fs.existsSync(path)) {
Expand Down Expand Up @@ -53,10 +53,16 @@ const finders: Record<string, (port: number) => Promise<number>> = {
})

if (found && found[2].length) {
resolve(parseInt(found[2], 10))
} else {
reject(new Error(`pid of port (${port}) not found`))
}
// PID column can be "pid" or "processname:pid"
const pidCell = String(found[2])
const pidMatch = pidCell.match(/:(\d+)$/)
const pid = pidMatch ? parseInt(pidMatch[1], 10) : parseInt(pidCell, 10)
if (!isNaN(pid)) {
resolve(pid)
}
}

reject(new Error(`pid of port (${port}) not found`))
}
})
})
Expand Down