@ac-kit/app-system 0.1.0

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.
Files changed (95) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +45 -0
  3. package/dist/async/file-lock.d.ts +38 -0
  4. package/dist/async/file-lock.d.ts.map +1 -0
  5. package/dist/async/file-lock.js +67 -0
  6. package/dist/async/file-lock.js.map +1 -0
  7. package/dist/async/udp-bind-lock.d.ts +75 -0
  8. package/dist/async/udp-bind-lock.d.ts.map +1 -0
  9. package/dist/async/udp-bind-lock.js +85 -0
  10. package/dist/async/udp-bind-lock.js.map +1 -0
  11. package/dist/fs/artifact-cache.d.ts +124 -0
  12. package/dist/fs/artifact-cache.d.ts.map +1 -0
  13. package/dist/fs/artifact-cache.js +183 -0
  14. package/dist/fs/artifact-cache.js.map +1 -0
  15. package/dist/fs/rotate-log-files.d.ts +20 -0
  16. package/dist/fs/rotate-log-files.d.ts.map +1 -0
  17. package/dist/fs/rotate-log-files.js +45 -0
  18. package/dist/fs/rotate-log-files.js.map +1 -0
  19. package/dist/fs/rotating-file-sink.d.ts +42 -0
  20. package/dist/fs/rotating-file-sink.d.ts.map +1 -0
  21. package/dist/fs/rotating-file-sink.js +213 -0
  22. package/dist/fs/rotating-file-sink.js.map +1 -0
  23. package/dist/index.d.ts +23 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +23 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/os/get-processes-snapshot.d.ts +56 -0
  28. package/dist/os/get-processes-snapshot.d.ts.map +1 -0
  29. package/dist/os/get-processes-snapshot.js +197 -0
  30. package/dist/os/get-processes-snapshot.js.map +1 -0
  31. package/dist/os/host-metrics.d.ts +43 -0
  32. package/dist/os/host-metrics.d.ts.map +1 -0
  33. package/dist/os/host-metrics.js +78 -0
  34. package/dist/os/host-metrics.js.map +1 -0
  35. package/dist/os/process-kill-by-pid-file.d.ts +35 -0
  36. package/dist/os/process-kill-by-pid-file.d.ts.map +1 -0
  37. package/dist/os/process-kill-by-pid-file.js +48 -0
  38. package/dist/os/process-kill-by-pid-file.js.map +1 -0
  39. package/dist/os/process-wait-pid.d.ts +18 -0
  40. package/dist/os/process-wait-pid.d.ts.map +1 -0
  41. package/dist/os/process-wait-pid.js +26 -0
  42. package/dist/os/process-wait-pid.js.map +1 -0
  43. package/dist/os/ps.d.ts +98 -0
  44. package/dist/os/ps.d.ts.map +1 -0
  45. package/dist/os/ps.js +165 -0
  46. package/dist/os/ps.js.map +1 -0
  47. package/dist/os/sysfs.d.ts +19 -0
  48. package/dist/os/sysfs.d.ts.map +1 -0
  49. package/dist/os/sysfs.js +66 -0
  50. package/dist/os/sysfs.js.map +1 -0
  51. package/dist/process/child-process-message-sink.d.ts +21 -0
  52. package/dist/process/child-process-message-sink.d.ts.map +1 -0
  53. package/dist/process/child-process-message-sink.js +16 -0
  54. package/dist/process/child-process-message-sink.js.map +1 -0
  55. package/dist/process/error-listeners.d.ts +56 -0
  56. package/dist/process/error-listeners.d.ts.map +1 -0
  57. package/dist/process/error-listeners.js +113 -0
  58. package/dist/process/error-listeners.js.map +1 -0
  59. package/dist/process/exit-manager.d.ts +58 -0
  60. package/dist/process/exit-manager.d.ts.map +1 -0
  61. package/dist/process/exit-manager.js +88 -0
  62. package/dist/process/exit-manager.js.map +1 -0
  63. package/dist/process/has-binary.d.ts +25 -0
  64. package/dist/process/has-binary.d.ts.map +1 -0
  65. package/dist/process/has-binary.js +35 -0
  66. package/dist/process/has-binary.js.map +1 -0
  67. package/dist/process/pid-file.d.ts +17 -0
  68. package/dist/process/pid-file.d.ts.map +1 -0
  69. package/dist/process/pid-file.js +25 -0
  70. package/dist/process/pid-file.js.map +1 -0
  71. package/dist/process/process-pid-file.d.ts +37 -0
  72. package/dist/process/process-pid-file.d.ts.map +1 -0
  73. package/dist/process/process-pid-file.js +57 -0
  74. package/dist/process/process-pid-file.js.map +1 -0
  75. package/dist/process/report-process.d.ts +36 -0
  76. package/dist/process/report-process.d.ts.map +1 -0
  77. package/dist/process/report-process.js +121 -0
  78. package/dist/process/report-process.js.map +1 -0
  79. package/dist/shell/shorten-posix-path.d.ts +10 -0
  80. package/dist/shell/shorten-posix-path.d.ts.map +1 -0
  81. package/dist/shell/shorten-posix-path.js +19 -0
  82. package/dist/shell/shorten-posix-path.js.map +1 -0
  83. package/dist/terminal/node-terminal.d.ts +11 -0
  84. package/dist/terminal/node-terminal.d.ts.map +1 -0
  85. package/dist/terminal/node-terminal.js +162 -0
  86. package/dist/terminal/node-terminal.js.map +1 -0
  87. package/dist/text/charset-decode-stream.d.ts +13 -0
  88. package/dist/text/charset-decode-stream.d.ts.map +1 -0
  89. package/dist/text/charset-decode-stream.js +51 -0
  90. package/dist/text/charset-decode-stream.js.map +1 -0
  91. package/dist/text/charset-encode-stream.d.ts +12 -0
  92. package/dist/text/charset-encode-stream.d.ts.map +1 -0
  93. package/dist/text/charset-encode-stream.js +47 -0
  94. package/dist/text/charset-encode-stream.js.map +1 -0
  95. package/package.json +75 -0
@@ -0,0 +1,197 @@
1
+ import { BYTES_PER_KIB, UnimplementedError, defaults } from "@ac-kit/core";
2
+ import { ps, psParseDuration } from "./ps.js";
3
+ const GET_PROCESSES_SNAPSHOT_DEFAULT_OPTIONS = {
4
+ filters: null,
5
+ fields: null,
6
+ signal: null,
7
+ };
8
+ const PROCESS_INFO_TO_PS_FIELD = {
9
+ parentId: "ppid",
10
+ id: "pid",
11
+ command: "args",
12
+ userName: "user",
13
+ groupName: "group",
14
+ memoryUsage: "vsz",
15
+ cpuUsage: "pcpu",
16
+ accumulatedCpuUsageMs: "time",
17
+ startTime: "etime",
18
+ };
19
+ export async function getProcessesSnapshotPosix(options) {
20
+ let { fields, filters, signal } = defaults(options, GET_PROCESSES_SNAPSHOT_DEFAULT_OPTIONS);
21
+ if (!fields || fields.length === 0) {
22
+ fields = Object.keys(PROCESS_INFO_TO_PS_FIELD);
23
+ }
24
+ const additionalFiltersFields = [];
25
+ let psFilters;
26
+ if (filters) {
27
+ psFilters = {};
28
+ if (filters.groupName) {
29
+ psFilters.group = [filters.groupName];
30
+ }
31
+ if (filters.userName) {
32
+ psFilters.user = [filters.userName];
33
+ }
34
+ if (filters.id) {
35
+ psFilters.pid = [filters.id];
36
+ }
37
+ if (filters.parentId && !fields.includes("parentId")) {
38
+ additionalFiltersFields.push("parentId");
39
+ }
40
+ if (filters.command && !fields.includes("command")) {
41
+ additionalFiltersFields.push("command");
42
+ }
43
+ if ((filters.minMemoryUsage || filters.maxMemoryUsage) &&
44
+ !fields.includes("memoryUsage")) {
45
+ additionalFiltersFields.push("memoryUsage");
46
+ }
47
+ if ((filters.minCpuUsage || filters.maxCpuUsage) &&
48
+ !fields.includes("cpuUsage")) {
49
+ additionalFiltersFields.push("cpuUsage");
50
+ }
51
+ if ((filters.minAccumulatedCpuUsageMs || filters.maxAccumulatedCpuUsageMs) &&
52
+ !fields.includes("accumulatedCpuUsageMs")) {
53
+ additionalFiltersFields.push("accumulatedCpuUsageMs");
54
+ }
55
+ if ((filters.minStartTime || filters.maxStartTime) &&
56
+ !fields.includes("startTime")) {
57
+ additionalFiltersFields.push("startTime");
58
+ }
59
+ }
60
+ const psResult = await ps({
61
+ selector: psFilters ?? "all",
62
+ fields: [...fields, ...additionalFiltersFields].map((f) => PROCESS_INFO_TO_PS_FIELD[f]),
63
+ execOptions: {
64
+ signal: signal ?? undefined,
65
+ },
66
+ });
67
+ let result = psResult.map((psEntry) => {
68
+ const entry = {};
69
+ for (const field of fields) {
70
+ const psField = PROCESS_INFO_TO_PS_FIELD[field];
71
+ const psValue = psEntry[psField];
72
+ if (psValue === undefined) {
73
+ throw new Error(`Expected field ${psField} to be present in ps result`);
74
+ }
75
+ switch (psField) {
76
+ case "vsz":
77
+ entry[field] = +psValue * BYTES_PER_KIB;
78
+ break;
79
+ case "time":
80
+ entry[field] = psParseDuration(`${psValue}`);
81
+ break;
82
+ case "etime":
83
+ entry[field] = new Date(Date.now() - psParseDuration(`${psValue}`));
84
+ break;
85
+ default:
86
+ entry[field] = psEntry[psField];
87
+ break;
88
+ }
89
+ }
90
+ return entry;
91
+ });
92
+ if (additionalFiltersFields.length > 0) {
93
+ result = result.filter((entry) => {
94
+ if (filters?.parentId !== undefined &&
95
+ entry.parentId !== filters.parentId) {
96
+ return false;
97
+ }
98
+ if (filters?.command !== undefined && entry.command !== undefined) {
99
+ const [cmd, ...args] = filters.command;
100
+ if (typeof cmd === "string") {
101
+ if (entry.command[0] !== cmd) {
102
+ return false;
103
+ }
104
+ }
105
+ else {
106
+ if (!cmd.test(entry.command[0])) {
107
+ return false;
108
+ }
109
+ }
110
+ for (let i = 0; i < args.length; i++) {
111
+ const arg = args[i];
112
+ const entryArg = entry.command[i + 1];
113
+ if (entryArg === undefined) {
114
+ return false;
115
+ }
116
+ if (typeof arg === "string") {
117
+ if (entryArg !== arg) {
118
+ return false;
119
+ }
120
+ }
121
+ else {
122
+ if (!arg.test(entryArg)) {
123
+ return false;
124
+ }
125
+ }
126
+ }
127
+ }
128
+ if (filters?.minMemoryUsage !== undefined &&
129
+ entry.memoryUsage !== undefined &&
130
+ entry.memoryUsage < filters.minMemoryUsage) {
131
+ return false;
132
+ }
133
+ if (filters?.maxMemoryUsage !== undefined &&
134
+ entry.memoryUsage !== undefined &&
135
+ entry.memoryUsage > filters.maxMemoryUsage) {
136
+ return false;
137
+ }
138
+ if (entry.cpuUsage !== undefined) {
139
+ if (filters?.minCpuUsage !== undefined &&
140
+ entry.cpuUsage < filters.minCpuUsage) {
141
+ return false;
142
+ }
143
+ if (filters?.maxCpuUsage !== undefined &&
144
+ entry.cpuUsage > filters.maxCpuUsage) {
145
+ return false;
146
+ }
147
+ }
148
+ if (entry.accumulatedCpuUsageMs !== undefined) {
149
+ if (filters?.minAccumulatedCpuUsageMs !== undefined &&
150
+ entry.accumulatedCpuUsageMs < filters.minAccumulatedCpuUsageMs) {
151
+ return false;
152
+ }
153
+ if (filters?.maxAccumulatedCpuUsageMs !== undefined &&
154
+ entry.accumulatedCpuUsageMs > filters.maxAccumulatedCpuUsageMs) {
155
+ return false;
156
+ }
157
+ }
158
+ if (entry.startTime !== undefined) {
159
+ if (filters?.minStartTime !== undefined &&
160
+ entry.startTime < filters.minStartTime) {
161
+ return false;
162
+ }
163
+ if (filters?.maxStartTime !== undefined &&
164
+ entry.startTime > filters.maxStartTime) {
165
+ return false;
166
+ }
167
+ }
168
+ return true;
169
+ });
170
+ // Remove any additional fields used for filtering
171
+ result = result.map((entry) => {
172
+ for (const field of additionalFiltersFields) {
173
+ delete entry[field];
174
+ }
175
+ return entry;
176
+ });
177
+ }
178
+ return result;
179
+ }
180
+ /**
181
+ * Not supported on Windows.
182
+ *
183
+ * The POSIX implementation reads `ps`, which Windows has no equivalent of:
184
+ * `tasklist` and WMI both report a different field set under different names,
185
+ * so this would be a second implementation rather than a port. Until one
186
+ * exists, the call fails loudly instead of returning a partial snapshot a
187
+ * caller would read as complete.
188
+ *
189
+ * @throws {UnimplementedError} Always.
190
+ */
191
+ export async function getProcessesSnapshotWin32(_options) {
192
+ throw new UnimplementedError("getProcessesSnapshot is not supported on Windows");
193
+ }
194
+ export const getProcessesSnapshot = process.platform === "win32"
195
+ ? getProcessesSnapshotWin32
196
+ : getProcessesSnapshotPosix;
197
+ //# sourceMappingURL=get-processes-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-processes-snapshot.js","sourceRoot":"","sources":["../../src/os/get-processes-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG3E,OAAO,EAAiC,EAAE,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA8C7E,MAAM,sCAAsC,GAC3C;IACC,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;CACZ,CAAC;AAEH,MAAM,wBAAwB,GAA8C;IAC3E,QAAQ,EAAE,MAAM;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AC,CAAC;QAEH,kDAAkD;QAClD,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC7B,KAAK,MAAM,KAAK,IAAI,uBAAuB,EAAE,CAAC;gBAC7C,OAAQ,KAAuB,CAAC,KAAK,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,MAAa,CAAC;AACtB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAK7C,QAAY;IACb,MAAM,IAAI,kBAAkB,CAC3B,kDAAkD,CAClD,CAAC;AACH,CAAC;AAWD,MAAM,CAAC,MAAM,oBAAoB,GAChC,OAAO,CAAC,QAAQ,KAAK,OAAO;IAC3B,CAAC,CAAC,yBAAyB;IAC3B,CAAC,CAAC,yBAAyB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Mean of `scaling_cur_freq / cpuinfo_max_freq` across the cores exposing both,
3
+ * or `null` where the platform exposes neither — which a caller must read as
4
+ * "unknown", never as "nominal".
5
+ *
6
+ * A ratio well below 1 during a measurement means the CPU is being clocked
7
+ * down, which invalidates a comparison against samples taken at full speed.
8
+ *
9
+ * Only Linux publishes these nodes, so every other platform answers `null` by
10
+ * simply finding nothing to read.
11
+ *
12
+ * @param sysfsRoot Root of the sysfs mount. Defaults to `/sys`.
13
+ */
14
+ export declare function readCpuFrequencyRatio(sysfsRoot?: string): Promise<number | null>;
15
+ /**
16
+ * Temperature of the hottest readable thermal zone in °C, or `null` where the
17
+ * platform exposes none.
18
+ *
19
+ * Only Linux publishes these nodes, so every other platform answers `null` by
20
+ * simply finding nothing to read.
21
+ *
22
+ * @param sysfsRoot Root of the sysfs mount. Defaults to `/sys`.
23
+ */
24
+ export declare function readMaxTemperatureC(sysfsRoot?: string): Promise<number | null>;
25
+ export declare const PROCFS_DEFAULT_ROOT = "/proc";
26
+ /**
27
+ * Resident set size of another process in bytes, or `null` when the process is
28
+ * gone, the platform exposes no procfs, or the caller may not read it.
29
+ *
30
+ * Reads `VmRSS` from `/proc/<pid>/status` rather than the resident-pages field
31
+ * of `statm`, because that one is a page count and the page size is not
32
+ * knowable from Node — 4 KiB is only the common case, and an arm64 kernel
33
+ * configured for 16 KiB pages would make every reading wrong by a factor of
34
+ * four.
35
+ *
36
+ * Cheap enough to poll at second granularity, unlike
37
+ * {@link getProcessesSnapshot}, which spawns `ps`.
38
+ *
39
+ * @param pid The process to inspect.
40
+ * @param procfsRoot Root of the procfs mount. Defaults to `/proc`.
41
+ */
42
+ export declare function readProcessRssBytes(pid: number, procfsRoot?: string): Promise<number | null>;
43
+ //# sourceMappingURL=host-metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-metrics.d.ts","sourceRoot":"","sources":["../../src/os/host-metrics.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CAC1C,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACxC,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAI3C;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,mBAAmB,CACxC,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,MAA4B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAaxB"}
@@ -0,0 +1,78 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { sysfsCpuFrequencyRatios, sysfsThermalZoneTemperaturesC, } from "./sysfs.js";
4
+ /**
5
+ * Mean of `scaling_cur_freq / cpuinfo_max_freq` across the cores exposing both,
6
+ * or `null` where the platform exposes neither — which a caller must read as
7
+ * "unknown", never as "nominal".
8
+ *
9
+ * A ratio well below 1 during a measurement means the CPU is being clocked
10
+ * down, which invalidates a comparison against samples taken at full speed.
11
+ *
12
+ * Only Linux publishes these nodes, so every other platform answers `null` by
13
+ * simply finding nothing to read.
14
+ *
15
+ * @param sysfsRoot Root of the sysfs mount. Defaults to `/sys`.
16
+ */
17
+ export async function readCpuFrequencyRatio(sysfsRoot) {
18
+ const ratios = await sysfsCpuFrequencyRatios(sysfsRoot);
19
+ if (ratios.length === 0) {
20
+ return null;
21
+ }
22
+ let total = 0;
23
+ for (const ratio of ratios) {
24
+ total += ratio;
25
+ }
26
+ return total / ratios.length;
27
+ }
28
+ /**
29
+ * Temperature of the hottest readable thermal zone in °C, or `null` where the
30
+ * platform exposes none.
31
+ *
32
+ * Only Linux publishes these nodes, so every other platform answers `null` by
33
+ * simply finding nothing to read.
34
+ *
35
+ * @param sysfsRoot Root of the sysfs mount. Defaults to `/sys`.
36
+ */
37
+ export async function readMaxTemperatureC(sysfsRoot) {
38
+ let hottest = null;
39
+ for (const temperature of await sysfsThermalZoneTemperaturesC(sysfsRoot)) {
40
+ if (hottest === null || temperature > hottest) {
41
+ hottest = temperature;
42
+ }
43
+ }
44
+ return hottest;
45
+ }
46
+ export const PROCFS_DEFAULT_ROOT = "/proc";
47
+ const VM_RSS_LINE = /^VmRSS:\s+(\d+)\s+kB$/m;
48
+ /**
49
+ * Resident set size of another process in bytes, or `null` when the process is
50
+ * gone, the platform exposes no procfs, or the caller may not read it.
51
+ *
52
+ * Reads `VmRSS` from `/proc/<pid>/status` rather than the resident-pages field
53
+ * of `statm`, because that one is a page count and the page size is not
54
+ * knowable from Node — 4 KiB is only the common case, and an arm64 kernel
55
+ * configured for 16 KiB pages would make every reading wrong by a factor of
56
+ * four.
57
+ *
58
+ * Cheap enough to poll at second granularity, unlike
59
+ * {@link getProcessesSnapshot}, which spawns `ps`.
60
+ *
61
+ * @param pid The process to inspect.
62
+ * @param procfsRoot Root of the procfs mount. Defaults to `/proc`.
63
+ */
64
+ export async function readProcessRssBytes(pid, procfsRoot = PROCFS_DEFAULT_ROOT) {
65
+ try {
66
+ const status = await readFile(join(procfsRoot, String(pid), "status"), {
67
+ encoding: "utf8",
68
+ });
69
+ const kilobytes = VM_RSS_LINE.exec(status)?.[1];
70
+ return kilobytes === undefined
71
+ ? null
72
+ : Number.parseInt(kilobytes, 10) * 1024;
73
+ }
74
+ catch {
75
+ return null;
76
+ }
77
+ }
78
+ //# sourceMappingURL=host-metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-metrics.js","sourceRoot":"","sources":["../../src/os/host-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACN,uBAAuB,EACvB,6BAA6B,GAC7B,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,KAAK,IAAI,KAAK,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;AAC9B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,SAAkB;IAElB,IAAI,OAAO,GAAkB,IAAI,CAAC;IAClC,KAAK,MAAM,WAAW,IAAI,MAAM,6BAA6B,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1E,IAAI,OAAO,KAAK,IAAI,IAAI,WAAW,GAAG,OAAO,EAAE,CAAC;YAC/C,OAAO,GAAG,WAAW,CAAC;QACvB,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,GAAW,EACX,UAAU,GAAW,mBAAmB;IAExC,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE;YACtE,QAAQ,EAAE,MAAM;SAChB,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEhD,OAAO,SAAS,KAAK,SAAS;YAC7B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { PathLike } from "node:fs";
2
+ import { type ProcessWaitPidOptions } from "./process-wait-pid.js";
3
+ export type ProcessKillByPidFileOptions = {
4
+ /** An optional AbortSignal that can be used to abort the operation. */
5
+ signal?: AbortSignal | null;
6
+ /**
7
+ * Wait options to use after sending the kill signal. Default is `{}` (wait
8
+ * for termination with default options).
9
+ *
10
+ * If `null`, the function will not wait for the process to terminate.
11
+ */
12
+ waitOptions?: Omit<ProcessWaitPidOptions, "signal"> | null;
13
+ };
14
+ /**
15
+ * Kill the process whose PID is stored in the PID file and optionally wait for
16
+ * it to terminate.
17
+ *
18
+ * Different signals can be used to terminate the process: - 'SIGTERM'
19
+ * (default): Politely asks the process to terminate, allowing it to perform
20
+ * cleanup operations. - 'SIGINT': Simulates an interrupt signal (like pressing
21
+ * Ctrl+C in a terminal). This allows the process to handle the signal and
22
+ * perform any necessary cleanup. - 'SIGKILL': Forces the process to terminate
23
+ * immediately. This signal cannot be caught or ignored by the process.
24
+ *
25
+ * If 'SIGKILL' is used, the PID file will be deleted automatically after the
26
+ * process is killed. Other signals, which are catch-able, should allow the
27
+ * process to handle its own cleanup, including removing the PID file if
28
+ * necessary.
29
+ *
30
+ * @param pidFile The path to the PID file.
31
+ * @param killSignal The signal to send to the process.
32
+ * @param options Optional abort and wait settings.
33
+ */
34
+ export declare function processKillByPidFile(pidFile: PathLike, killSignal: Parameters<typeof process.kill>[1], options?: ProcessKillByPidFileOptions): Promise<void>;
35
+ //# sourceMappingURL=process-kill-by-pid-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-kill-by-pid-file.d.ts","sourceRoot":"","sources":["../../src/os/process-kill-by-pid-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMxC,OAAO,EACN,KAAK,qBAAqB,EAE1B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,2BAA2B,GAAG;IACzC,uEAAuE;IACvE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC;CAC3D,CAAC;AAQF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,QAAQ,EACjB,UAAU,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAC9C,OAAO,CAAC,EAAE,2BAA2B,GACnC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
@@ -0,0 +1,48 @@
1
+ import { unlink } from "node:fs/promises";
2
+ import { defaults } from "@ac-kit/core";
3
+ import { readPidFile } from "../process/pid-file.js";
4
+ import { processWaitPid, } from "./process-wait-pid.js";
5
+ const PROCESS_KILL_BY_PID_FILE_DEFAULT_OPTIONS = {
6
+ signal: null,
7
+ waitOptions: {},
8
+ };
9
+ /**
10
+ * Kill the process whose PID is stored in the PID file and optionally wait for
11
+ * it to terminate.
12
+ *
13
+ * Different signals can be used to terminate the process: - 'SIGTERM'
14
+ * (default): Politely asks the process to terminate, allowing it to perform
15
+ * cleanup operations. - 'SIGINT': Simulates an interrupt signal (like pressing
16
+ * Ctrl+C in a terminal). This allows the process to handle the signal and
17
+ * perform any necessary cleanup. - 'SIGKILL': Forces the process to terminate
18
+ * immediately. This signal cannot be caught or ignored by the process.
19
+ *
20
+ * If 'SIGKILL' is used, the PID file will be deleted automatically after the
21
+ * process is killed. Other signals, which are catch-able, should allow the
22
+ * process to handle its own cleanup, including removing the PID file if
23
+ * necessary.
24
+ *
25
+ * @param pidFile The path to the PID file.
26
+ * @param killSignal The signal to send to the process.
27
+ * @param options Optional abort and wait settings.
28
+ */
29
+ export async function processKillByPidFile(pidFile, killSignal, options) {
30
+ const effectiveOptions = defaults(options, PROCESS_KILL_BY_PID_FILE_DEFAULT_OPTIONS);
31
+ const pid = await readPidFile(pidFile, {
32
+ signal: effectiveOptions.signal ?? undefined,
33
+ });
34
+ process.kill(pid, killSignal);
35
+ if (effectiveOptions.waitOptions !== null) {
36
+ await processWaitPid(pid, {
37
+ ...effectiveOptions.waitOptions,
38
+ signal: effectiveOptions.signal,
39
+ });
40
+ }
41
+ if (killSignal === "SIGKILL") {
42
+ try {
43
+ await unlink(pidFile);
44
+ }
45
+ catch { }
46
+ }
47
+ }
48
+ //# sourceMappingURL=process-kill-by-pid-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-kill-by-pid-file.js","sourceRoot":"","sources":["../../src/os/process-kill-by-pid-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEN,cAAc,GACd,MAAM,uBAAuB,CAAC;AAe/B,MAAM,wCAAwC,GAC7C;IACC,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,EAAE;CACf,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,OAAiB,EACjB,UAA8C,EAC9C,OAAqC;IAErC,MAAM,gBAAgB,GAAG,QAAQ,CAChC,OAAO,EACP,wCAAwC,CACxC,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE;QACtC,MAAM,EAAE,gBAAgB,CAAC,MAAM,IAAI,SAAS;KAC5C,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAE9B,IAAI,gBAAgB,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QAC3C,MAAM,cAAc,CAAC,GAAG,EAAE;YACzB,GAAG,gBAAgB,CAAC,WAAW;YAC/B,MAAM,EAAE,gBAAgB,CAAC,MAAM;SAC/B,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,CAAC;YACJ,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;AACF,CAAC"}
@@ -0,0 +1,18 @@
1
+ export type ProcessWaitPidOptions = {
2
+ /** An optional AbortSignal that can be used to abort the operation. */
3
+ signal?: AbortSignal | null;
4
+ /**
5
+ * If specified, the function will poll at the given interval (in
6
+ * milliseconds) to check if the process has terminated after sending the kill
7
+ * signal. Default is 50 ms.
8
+ */
9
+ pollIntervalMs?: number;
10
+ };
11
+ export declare const PROCESS_WAIT_PID_DEFAULT_OPTIONS: Required<ProcessWaitPidOptions>;
12
+ /**
13
+ * Wait for a process by its PID to terminate.
14
+ *
15
+ * @param pid The PID of the process to wait.
16
+ */
17
+ export declare function processWaitPid(pid: number, options?: ProcessWaitPidOptions): Promise<void>;
18
+ //# sourceMappingURL=process-wait-pid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-wait-pid.d.ts","sourceRoot":"","sources":["../../src/os/process-wait-pid.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG;IACnC,uEAAuE;IACvE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,qBAAqB,CAI3E,CAAC;AAEH;;;;GAIG;AACH,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -0,0 +1,26 @@
1
+ import { defaults, waitFor } from "@ac-kit/core";
2
+ import { getProcessesSnapshot } from "./get-processes-snapshot.js";
3
+ export const PROCESS_WAIT_PID_DEFAULT_OPTIONS = {
4
+ signal: null,
5
+ pollIntervalMs: 50,
6
+ };
7
+ /**
8
+ * Wait for a process by its PID to terminate.
9
+ *
10
+ * @param pid The PID of the process to wait.
11
+ */
12
+ export async function processWaitPid(pid, options) {
13
+ const effectiveOptions = defaults(options, PROCESS_WAIT_PID_DEFAULT_OPTIONS);
14
+ await waitFor(async () => {
15
+ const processes = await getProcessesSnapshot({
16
+ filters: { id: pid },
17
+ fields: ["id"],
18
+ signal: effectiveOptions.signal,
19
+ });
20
+ return processes.length === 0;
21
+ }, {
22
+ signal: effectiveOptions.signal,
23
+ intervalMs: effectiveOptions.pollIntervalMs,
24
+ });
25
+ }
26
+ //# sourceMappingURL=process-wait-pid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-wait-pid.js","sourceRoot":"","sources":["../../src/os/process-wait-pid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAcnE,MAAM,CAAC,MAAM,gCAAgC,GAC5C;IACC,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,EAAE;CAClB,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,GAAW,EACX,OAA+B;IAE/B,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAC;IAE7E,MAAM,OAAO,CACZ,KAAK,IAAI,EAAE;QACV,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC;YAC5C,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE;YACpB,MAAM,EAAE,CAAC,IAAI,CAAC;YACd,MAAM,EAAE,gBAAgB,CAAC,MAAM;SAC/B,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAC/B,CAAC,EACD;QACC,MAAM,EAAE,gBAAgB,CAAC,MAAM;QAC/B,UAAU,EAAE,gBAAgB,CAAC,cAAc;KAC3C,CACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,98 @@
1
+ import type { ExecOptions } from "node:child_process";
2
+ import type { TupleToUnion } from "type-fest";
3
+ export type PsFilters = {
4
+ group?: (number | string)[];
5
+ pid?: number[];
6
+ tty?: string[];
7
+ user?: (number | string)[];
8
+ };
9
+ export type PsSelector = "all" | "tty" | PsFilters;
10
+ export type PsOptions = {
11
+ /**
12
+ * Selector to filter processes. Defaults to `"all"`.
13
+ *
14
+ * If a string is provided, it can be: - "all": Select all processes
15
+ * (equivalent to `-A` argument). - "tty": Select processes associated with a
16
+ * terminal (equivalent to `-a` argument).
17
+ *
18
+ * If an object is provided, it can contain any of the following optional
19
+ * properties to filter processes: - `group`: An array of group IDs (numbers
20
+ * or strings) to filter by group ID (argument: `-G`). - `pid`: An array of
21
+ * process IDs (numbers) to filter by process ID (argument: `-p`). - `tty`: An
22
+ * array of terminal names (strings) to filter by terminal (argument: `-t`). -
23
+ * `user`: An array of user IDs (numbers or strings) to filter by user ID
24
+ * (argument: `-U`).
25
+ */
26
+ selector?: PsSelector;
27
+ /**
28
+ * Fields to include in the result. Defaults to `null`.
29
+ *
30
+ * If the array is empty or not provided, all available fields will be
31
+ * included in the result.
32
+ *
33
+ * Available fields are: - `args`: Command and arguments. - `comm`: Name to be
34
+ * used for accounting. - `etime`: Elapsed time since the process was
35
+ * started.
36
+ *
37
+ * - `group`: Text name of effective group ID. - `nice`: The process scheduling
38
+ * increment (see setpriority(2)). - `pcpu`: The CPU utilization of the
39
+ * process; this is a decaying average over up to a minute of previous
40
+ * (real) time. Since the time base over which this is computed varies
41
+ * (since processes may be very young), it is possible for the sum of all
42
+ * %cpu fields to exceed 100%. - `pgid`: Process group number. - `pid`:
43
+ * Process ID. - `ppid`: Parent process ID. - `rgroup`: Text name of real
44
+ * group ID. - `ruser`: User name (from ruid). - `time`: Accumulated CPU
45
+ * time, user + system. - `tty`: Full name of controlling terminal. -
46
+ * `user`: User name (from uid). - `vsz`: Virtual size, in Kilobytes.
47
+ */
48
+ fields?: (keyof PsResult)[] | null;
49
+ /**
50
+ * Additional command arguments to pass to `ps`. Defaults to `null`.
51
+ *
52
+ * These will be appended to the command after the selector and output format
53
+ * arguments. Use with caution, as they may conflict with other arguments.
54
+ *
55
+ * Also, be careful to escape any argument if necessary to avoid shell
56
+ * injection vulnerabilities.
57
+ */
58
+ extraArgs?: string[] | null;
59
+ /**
60
+ * Additional execution options. Defaults to `null`.
61
+ *
62
+ * These options are passed to the underlying `exec` function.
63
+ */
64
+ execOptions?: Omit<ExecOptions, "encoding"> | null;
65
+ };
66
+ export declare const PS_DEFAULT_OPTIONS: Required<PsOptions>;
67
+ export type PsResult = Record<string, string | number> & {
68
+ args: [string, ...string[]];
69
+ comm: string;
70
+ etime: string;
71
+ group: string;
72
+ nice: number;
73
+ pcpu: number;
74
+ pgid: number;
75
+ pid: number;
76
+ ppid: number;
77
+ rgroup: number;
78
+ ruser: string;
79
+ time: string;
80
+ tty: string;
81
+ user: string;
82
+ vsz: number;
83
+ };
84
+ /**
85
+ * Get the list of running processes using the `ps` command.
86
+ *
87
+ * @param options Options for filtering and selecting fields.
88
+ * @returns A promise that resolves to an array of process information objects.
89
+ */
90
+ export declare function ps<O extends PsOptions = PsOptions, R = O["fields"] extends never[] ? Partial<PsResult> : Pick<PsResult, TupleToUnion<O["fields"]>>>(options?: O): Promise<R[]>;
91
+ /**
92
+ * Parse a duration string in the format [[[dd-]hh:]mm:]ss to milliseconds.
93
+ *
94
+ * @param duration Duration string in the format [[[dd-]hh:]mm:]ss
95
+ * @returns The duration in milliseconds.
96
+ */
97
+ export declare function psParseDuration(duration: string): number;
98
+ //# sourceMappingURL=ps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ps.d.ts","sourceRoot":"","sources":["../../src/os/ps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAetD,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,WAAW,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG;IAGvB,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAG5B,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IAGf,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IAGf,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACvB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,UAA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