@aliou/pi-processes 0.3.4 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { hasAnsi, stripAnsi } from "./ansi";
2
+ export { formatRuntime, formatStatus, truncateCmd } from "./format";
3
+ export { isProcessGroupAlive, killProcessGroup } from "./process-group";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Check if a process group is still alive.
3
+ * Uses signal 0 to test existence without actually sending a signal.
4
+ */
5
+ export function isProcessGroupAlive(pgid: number): boolean {
6
+ try {
7
+ process.kill(-pgid, 0);
8
+ return true;
9
+ } catch (error) {
10
+ const err = error as NodeJS.ErrnoException;
11
+ // EPERM: exists, but we can't signal it
12
+ return err.code === "EPERM";
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Send a signal to an entire process group.
18
+ * Negative PID targets the process group.
19
+ */
20
+ export function killProcessGroup(pgid: number, signal: NodeJS.Signals): void {
21
+ process.kill(-pgid, signal);
22
+ }