import { run } from "./bin.mjs";
import * as os from "node:os";

//#region ../@intlayer/cli/dist/esm/chokidar/dist/esm/utils/runParallel/ps.mjs
/**
* Gets the list of all the pids of the system through the ps command.
* @param callback Callback function with error and process list.
*/
const ps = (callback) => {
	run("ps", [
		"-A",
		"-o",
		"ppid,pid"
	], (err, stdout, code) => {
		if (err) {
			callback(err);
			return;
		}
		if (code !== 0) {
			callback(/* @__PURE__ */ new Error(`pidtree ps command exited with code ${code}`));
			return;
		}
		if (!stdout) {
			callback(/* @__PURE__ */ new Error("No stdout received from ps command"));
			return;
		}
		try {
			const lines = stdout.split(os.EOL);
			const list = [];
			for (let i = 1; i < lines.length; i++) {
				const trimmed = lines[i].trim();
				if (!trimmed) continue;
				const parts = trimmed.split(/\s+/);
				const ppid = parseInt(parts[0], 10);
				const pid = parseInt(parts[1], 10);
				if (!Number.isNaN(ppid) && !Number.isNaN(pid)) list.push([ppid, pid]);
			}
			callback(null, list);
		} catch (error) {
			callback(error instanceof Error ? error : new Error(String(error)));
		}
	});
};

//#endregion
export { ps };
//# sourceMappingURL=ps.mjs.map