mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-22 17:57:46 +00:00
feat: improve getProcessInfo robustness with try-catch and empty output fallback
This commit is contained in:
@@ -20,11 +20,26 @@ async function getProcessInfo(pid: number): Promise<{
|
|||||||
command: string;
|
command: string;
|
||||||
}> {
|
}> {
|
||||||
// Only used for Unix systems (macOS and Linux)
|
// Only used for Unix systems (macOS and Linux)
|
||||||
const { stdout } = await execAsync(`ps -p ${pid} -o ppid=,comm=`);
|
try {
|
||||||
const [ppidStr, ...commandParts] = stdout.trim().split(/\s+/);
|
const command = `ps -o ppid=,command= -p ${pid}`;
|
||||||
const parentPid = parseInt(ppidStr, 10);
|
const { stdout } = await execAsync(command);
|
||||||
const command = commandParts.join(' ');
|
const trimmedStdout = stdout.trim();
|
||||||
return { parentPid, name: path.basename(command), command };
|
if (!trimmedStdout) {
|
||||||
|
return { parentPid: 0, name: '', command: '' };
|
||||||
|
}
|
||||||
|
const parts = trimmedStdout.split(/\s+/);
|
||||||
|
const ppidString = parts[0];
|
||||||
|
const parentPid = parseInt(ppidString, 10);
|
||||||
|
const fullCommand = trimmedStdout.substring(ppidString.length).trim();
|
||||||
|
const processName = path.basename(fullCommand.split(' ')[0]);
|
||||||
|
return {
|
||||||
|
parentPid: isNaN(parentPid) ? 1 : parentPid,
|
||||||
|
name: processName,
|
||||||
|
command: fullCommand,
|
||||||
|
};
|
||||||
|
} catch (_e) {
|
||||||
|
return { parentPid: 0, name: '', command: '' };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Finds the IDE process info on Unix-like systems.
|
* Finds the IDE process info on Unix-like systems.
|
||||||
|
|||||||
Reference in New Issue
Block a user