From 28bd014ee53d65d3e7335f5deafe302b8e61ea61 Mon Sep 17 00:00:00 2001 From: Abayomi Akintomide Date: Sun, 18 Jan 2026 19:22:59 +0100 Subject: [PATCH] fix: extract pid from pid column that sometimes contain process name --- src/find_pid.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/find_pid.ts b/src/find_pid.ts index ba152db..af162b0 100644 --- a/src/find_pid.ts +++ b/src/find_pid.ts @@ -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 => new Promise((resolve, reject) => { if (fs.existsSync(path)) { @@ -53,10 +53,16 @@ const finders: Record Promise> = { }) 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`)) } }) })