@zgeoff/rig 0.1.0 → 0.1.1
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/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProcessEntry } from './read-process-table.ts';
|
|
2
|
+
|
|
3
|
+
// `ps` lists itself too, as a child of the reader that has exited by then, so the parse leaves out
|
|
4
|
+
// the entry whose process ID is the listing's own.
|
|
5
|
+
export function parseProcessListing(stdout: string, listingPID: number): readonly ProcessEntry[] {
|
|
6
|
+
return stdout
|
|
7
|
+
.split('\n')
|
|
8
|
+
.map((line) => line.trim().split(/\s+/u))
|
|
9
|
+
.flatMap(([pid, parentID, groupID, state]) =>
|
|
10
|
+
pid === undefined || parentID === undefined || groupID === undefined || state === undefined
|
|
11
|
+
? []
|
|
12
|
+
: [{ pid: Number(pid), parentID: Number(parentID), groupID: Number(groupID), state }],
|
|
13
|
+
)
|
|
14
|
+
.filter((entry) => entry.pid !== listingPID);
|
|
15
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseProcessListing } from './parse-process-listing.ts';
|
|
2
|
+
|
|
1
3
|
export interface ProcessEntry {
|
|
2
4
|
readonly pid: number;
|
|
3
5
|
|
|
@@ -9,8 +11,7 @@ export interface ProcessEntry {
|
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
// Null when `ps` fails to start or exits nonzero. `ps -A` lists every process, so a nonzero exit
|
|
12
|
-
// is a failed listing, never a sign that a process has exited.
|
|
13
|
-
// the reader that has exited by then, so the listing leaves it out.
|
|
14
|
+
// is a failed listing, never a sign that a process has exited.
|
|
14
15
|
export function readProcessTable(): readonly ProcessEntry[] | null {
|
|
15
16
|
const listing = runListing();
|
|
16
17
|
|
|
@@ -18,16 +19,7 @@ export function readProcessTable(): readonly ProcessEntry[] | null {
|
|
|
18
19
|
return null;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
return listing.stdout
|
|
22
|
-
.toString()
|
|
23
|
-
.split('\n')
|
|
24
|
-
.map((line) => line.trim().split(/\s+/u))
|
|
25
|
-
.flatMap(([pid, parentID, groupID, state]) =>
|
|
26
|
-
pid === undefined || parentID === undefined || groupID === undefined || state === undefined
|
|
27
|
-
? []
|
|
28
|
-
: [{ pid: Number(pid), parentID: Number(parentID), groupID: Number(groupID), state }],
|
|
29
|
-
)
|
|
30
|
-
.filter((entry) => entry.pid !== listing.pid);
|
|
22
|
+
return parseProcessListing(listing.stdout.toString(), listing.pid);
|
|
31
23
|
}
|
|
32
24
|
|
|
33
25
|
function runListing() {
|