@kaynooo/cli-proc 0.7.4 → 0.8.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.
- package/README.md +10 -10
- package/dist/proc-cli.js +98 -41
- package/package.json +9 -15
- package/src/pid.ts +4 -4
- package/src/ports.ts +8 -8
- package/src/procs.ts +5 -5
- package/dist/pid-cli.js +0 -1809
- package/dist/ports-cli.js +0 -2074
- package/dist/procs-cli.js +0 -1951
- package/src/pid-cli.ts +0 -7
- package/src/ports-cli.ts +0 -7
- package/src/procs-cli.ts +0 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# proc
|
|
2
2
|
|
|
3
|
-
Three process and port helpers for Linux
|
|
3
|
+
Three process and port helpers for Linux, reading `/proc` directly instead of shelling out to `ps`, `ss` or `lsof`: `proc pid` inspects one process, `proc ports` tells who listens on what, `proc procs` finds leftover or heavy dev processes.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
bun install -g @kaynooo/cli-proc
|
|
@@ -10,23 +10,23 @@ bun install -g @kaynooo/cli-proc
|
|
|
10
10
|
|
|
11
11
|
| Command | What it does |
|
|
12
12
|
| --- | --- |
|
|
13
|
-
| `pid <pid>` | executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on, cgroup; `--env` adds the environment with secrets masked, `--json` everything |
|
|
14
|
-
| `ports [port]` | the listening sockets (TCP and UDP, IPv4 and IPv6) with port, protocol, bound address, pid, command and working directory; a port Docker publishes shows its compose project and service |
|
|
15
|
-
| `ports <port> --kill` | stops the owner: SIGTERM, and with `--force` SIGKILL after `--grace` (5s); asks on a terminal unless `--yes` |
|
|
16
|
-
| `procs` | leftover or heavy dev processes grouped by origin, with count, total RSS and oldest age |
|
|
17
|
-
| `procs --kill` | a dry run naming what would be stopped; `--yes` sends SIGTERM, then SIGKILL after `--grace` |
|
|
13
|
+
| `proc pid <pid>` | executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on, cgroup; `--env` adds the environment with secrets masked, `--json` everything |
|
|
14
|
+
| `proc ports [port]` | the listening sockets (TCP and UDP, IPv4 and IPv6) with port, protocol, bound address, pid, command and working directory; a port Docker publishes shows its compose project and service |
|
|
15
|
+
| `proc ports <port> --kill` | stops the owner: SIGTERM, and with `--force` SIGKILL after `--grace` (5s); asks on a terminal unless `--yes` |
|
|
16
|
+
| `proc procs` | leftover or heavy dev processes grouped by origin, with count, total RSS and oldest age |
|
|
17
|
+
| `proc procs --kill` | a dry run naming what would be stopped; `--yes` sends SIGTERM, then SIGKILL after `--grace` |
|
|
18
18
|
|
|
19
|
-
## pid
|
|
19
|
+
## proc pid
|
|
20
20
|
|
|
21
21
|
A missing pid exits 1. What the calling user cannot read of another user's process (executable, working directory, open files, limits, environment) is left out and named at the end. The environment is off unless `--env` is given: a name that looks like a secret (kit's rule, shared with `ev` and `redact`) has its whole value masked, and a URL password, a well known token format, a private key or a long opaque token is masked inside any value; the command line is masked the same way.
|
|
22
22
|
|
|
23
|
-
## ports
|
|
23
|
+
## proc ports
|
|
24
24
|
|
|
25
25
|
Sockets come from `/proc/net/{tcp,tcp6,udp,udp6}` and are mapped to their owner through the inode in `/proc/<pid>/fd`, so only the calling user's processes show an owner; the others show `-`. A socket without a readable owner, or held by `docker-proxy`, takes the container publishing its port when `docker ps` answers (skipped quietly when docker is missing or its daemon unreachable).
|
|
26
26
|
|
|
27
|
-
`ports <port>` exits 1 when nothing listens there. `--kill` refuses a process of another user, pid 1, this command and its ancestors, and a container's port, for which it prints the `docker stop <container>` to run instead.
|
|
27
|
+
`proc ports <port>` exits 1 when nothing listens there. `--kill` refuses a process of another user, pid 1, this command and its ancestors, and a container's port, for which it prints the `docker stop <container>` to run instead.
|
|
28
28
|
|
|
29
|
-
## procs
|
|
29
|
+
## proc procs
|
|
30
30
|
|
|
31
31
|
A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and WebKit browsers and their helpers, language servers, test runners) of the calling user and either:
|
|
32
32
|
|
package/dist/proc-cli.js
CHANGED
|
@@ -601,7 +601,7 @@ class Completing {
|
|
|
601
601
|
}
|
|
602
602
|
var completion = { active: false };
|
|
603
603
|
var OUTPUT_OPTIONS = {
|
|
604
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
604
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
605
605
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
606
606
|
};
|
|
607
607
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -897,6 +897,66 @@ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs
|
|
|
897
897
|
import { dirname as dirname3, join as join5 } from "path";
|
|
898
898
|
import process14 from "process";
|
|
899
899
|
|
|
900
|
+
// ../kit/src/completions.ts
|
|
901
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
902
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
903
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
904
|
+
set -l current (commandline -ct)
|
|
905
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
906
|
+
if test "$line" = __files__
|
|
907
|
+
__fish_complete_path $current
|
|
908
|
+
else
|
|
909
|
+
echo $line
|
|
910
|
+
end
|
|
911
|
+
end
|
|
912
|
+
end`;
|
|
913
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
914
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
915
|
+
local -a lines
|
|
916
|
+
COMPREPLY=()
|
|
917
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
918
|
+
for line in "\${lines[@]}"; do
|
|
919
|
+
if [[ $line == __files__ ]]; then
|
|
920
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
921
|
+
else
|
|
922
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
923
|
+
fi
|
|
924
|
+
done
|
|
925
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
926
|
+
}`;
|
|
927
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
928
|
+
local line
|
|
929
|
+
local -a described plain
|
|
930
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
931
|
+
if [[ $line == __files__ ]]; then
|
|
932
|
+
_files
|
|
933
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
934
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
935
|
+
else
|
|
936
|
+
plain+=("$line")
|
|
937
|
+
fi
|
|
938
|
+
done
|
|
939
|
+
(( \${#described} )) && _describe -V value described
|
|
940
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
941
|
+
return 0
|
|
942
|
+
}`;
|
|
943
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
944
|
+
if (shell === "fish")
|
|
945
|
+
return `${header}
|
|
946
|
+
${FISH_FUNCTION}
|
|
947
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
948
|
+
`).join("")}`;
|
|
949
|
+
if (shell === "bash")
|
|
950
|
+
return `${header}
|
|
951
|
+
${BASH_FUNCTION}
|
|
952
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
953
|
+
`;
|
|
954
|
+
return `${header}
|
|
955
|
+
${ZSH_FUNCTION}
|
|
956
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
957
|
+
`;
|
|
958
|
+
}
|
|
959
|
+
|
|
900
960
|
// ../kit/src/notify.ts
|
|
901
961
|
import process12 from "process";
|
|
902
962
|
var NOTIFY_AFTER_MS = 1e4;
|
|
@@ -970,7 +1030,11 @@ var LEVEL_OPTIONS = {
|
|
|
970
1030
|
...OUTPUT_OPTIONS,
|
|
971
1031
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
972
1032
|
};
|
|
973
|
-
var TOP_OPTIONS = {
|
|
1033
|
+
var TOP_OPTIONS = {
|
|
1034
|
+
...LEVEL_OPTIONS,
|
|
1035
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1036
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1037
|
+
};
|
|
974
1038
|
async function commandRows(all, colors) {
|
|
975
1039
|
const commands = shown(all);
|
|
976
1040
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1203,6 +1267,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1203
1267
|
}
|
|
1204
1268
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1205
1269
|
}
|
|
1270
|
+
var COMPLETIONS = "--completions";
|
|
1271
|
+
function flagValue([flag = "", ...rest]) {
|
|
1272
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1273
|
+
}
|
|
1274
|
+
function printCompletionScript(name, args) {
|
|
1275
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1276
|
+
if (shell === undefined || args.length !== 1) {
|
|
1277
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1278
|
+
return 2;
|
|
1279
|
+
}
|
|
1280
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1281
|
+
return 0;
|
|
1282
|
+
}
|
|
1206
1283
|
async function printCandidates(found) {
|
|
1207
1284
|
for (const line of await found)
|
|
1208
1285
|
console.log(line);
|
|
@@ -1227,6 +1304,8 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1227
1304
|
const version = cli.version ?? packageVersion();
|
|
1228
1305
|
if (argv[0] === COMPLETE)
|
|
1229
1306
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1307
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1308
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1230
1309
|
const started = performance.now();
|
|
1231
1310
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1232
1311
|
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
@@ -1253,28 +1332,6 @@ function commandPath(scope, argv) {
|
|
|
1253
1332
|
}
|
|
1254
1333
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1255
1334
|
}
|
|
1256
|
-
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1257
|
-
if (argv[0] === COMPLETE)
|
|
1258
|
-
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1259
|
-
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1260
|
-
console.log(version ?? packageVersion());
|
|
1261
|
-
return 0;
|
|
1262
|
-
}
|
|
1263
|
-
let code;
|
|
1264
|
-
const started = performance.now();
|
|
1265
|
-
try {
|
|
1266
|
-
code = await run(argv);
|
|
1267
|
-
} catch (error) {
|
|
1268
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1269
|
-
}
|
|
1270
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1271
|
-
if (usage !== false) {
|
|
1272
|
-
try {
|
|
1273
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1274
|
-
} catch {}
|
|
1275
|
-
}
|
|
1276
|
-
return code;
|
|
1277
|
-
}
|
|
1278
1335
|
// ../kit/src/folders.ts
|
|
1279
1336
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1280
1337
|
// ../kit/src/secrets.ts
|
|
@@ -1677,7 +1734,7 @@ async function userName(uid) {
|
|
|
1677
1734
|
}
|
|
1678
1735
|
|
|
1679
1736
|
// src/pid.ts
|
|
1680
|
-
var usage2 = `pid <pid>
|
|
1737
|
+
var usage2 = `proc pid <pid>
|
|
1681
1738
|
|
|
1682
1739
|
Shows what a process is: its executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on and its cgroup. Everything is read from /proc; what the calling user cannot read of another user's process is left out and named at the end.
|
|
1683
1740
|
The environment is not shown unless --env is given, with every value that looks like a secret masked.`;
|
|
@@ -1787,9 +1844,9 @@ async function pid(args) {
|
|
|
1787
1844
|
positionals: ["<pid>"],
|
|
1788
1845
|
replaces: "cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function",
|
|
1789
1846
|
examples: [
|
|
1790
|
-
["pid 4242", "executable, directory, command, parents, memory, limits and ports"],
|
|
1791
|
-
["pid 4242 --env", "with the environment, secrets masked"],
|
|
1792
|
-
"pid 4242 --json"
|
|
1847
|
+
["proc pid 4242", "executable, directory, command, parents, memory, limits and ports"],
|
|
1848
|
+
["proc pid 4242 --env", "with the environment, secrets masked"],
|
|
1849
|
+
"proc pid 4242 --json"
|
|
1793
1850
|
]
|
|
1794
1851
|
});
|
|
1795
1852
|
const [given] = positionals;
|
|
@@ -2091,11 +2148,11 @@ async function terminate(pids, { escalate, graceMs, signaller = realSignaller })
|
|
|
2091
2148
|
}
|
|
2092
2149
|
|
|
2093
2150
|
// src/ports.ts
|
|
2094
|
-
var usage3 = `ports [port]
|
|
2151
|
+
var usage3 = `proc ports [port]
|
|
2095
2152
|
|
|
2096
2153
|
Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
|
|
2097
|
-
\`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
2098
|
-
\`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
|
|
2154
|
+
\`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
2155
|
+
\`proc ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
|
|
2099
2156
|
var EXITS2 = [[0, "it listed or stopped"], [1, "nothing listens on the given port or the owner could not be stopped"], [2, "a usage error"]];
|
|
2100
2157
|
var options2 = {
|
|
2101
2158
|
json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
|
|
@@ -2188,10 +2245,10 @@ async function ports(args) {
|
|
|
2188
2245
|
positionals: ["[port]"],
|
|
2189
2246
|
replaces: "ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand",
|
|
2190
2247
|
examples: [
|
|
2191
|
-
["ports", "every listening port with its owner"],
|
|
2192
|
-
["ports 3000", "who holds 3000, exit 1 when nobody does"],
|
|
2193
|
-
["ports 3000 --kill --yes", "stop it"],
|
|
2194
|
-
"ports --json"
|
|
2248
|
+
["proc ports", "every listening port with its owner"],
|
|
2249
|
+
["proc ports 3000", "who holds 3000, exit 1 when nobody does"],
|
|
2250
|
+
["proc ports 3000 --kill --yes", "stop it"],
|
|
2251
|
+
"proc ports --json"
|
|
2195
2252
|
]
|
|
2196
2253
|
});
|
|
2197
2254
|
if (values.watch !== undefined)
|
|
@@ -2201,7 +2258,7 @@ async function ports(args) {
|
|
|
2201
2258
|
if (port !== undefined && port > 65535)
|
|
2202
2259
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
|
|
2203
2260
|
if (values.kill === true && port === undefined)
|
|
2204
|
-
badUsage("--kill takes the port to free: ports <port> --kill");
|
|
2261
|
+
badUsage("--kill takes the port to free: proc ports <port> --kill");
|
|
2205
2262
|
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process20.getuid?.())]);
|
|
2206
2263
|
const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
|
|
2207
2264
|
const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
|
|
@@ -2346,7 +2403,7 @@ function selectGroups(procs, options) {
|
|
|
2346
2403
|
}
|
|
2347
2404
|
|
|
2348
2405
|
// src/procs.ts
|
|
2349
|
-
var usage4 = `procs
|
|
2406
|
+
var usage4 = `proc procs
|
|
2350
2407
|
|
|
2351
2408
|
Lists the leftover or heavy processes of the calling user that are worth cleaning, grouped by origin: the project folder their working directory is in, a browser profile for a chromium and its helpers, else their command. Each group shows its process count, total resident memory and oldest age.
|
|
2352
2409
|
A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and webview browsers and their helpers, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default). The processes below a listed one, and those sharing a browser profile with it, are listed too, so a chromium whose main process was killed groups with its leftover helpers.
|
|
@@ -2395,10 +2452,10 @@ async function procs(args) {
|
|
|
2395
2452
|
exits: EXITS3,
|
|
2396
2453
|
replaces: "pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes",
|
|
2397
2454
|
examples: [
|
|
2398
|
-
["procs", "leftover and heavy dev processes, by origin"],
|
|
2399
|
-
["procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
|
|
2400
|
-
["procs --kill", "dry run: what would be stopped"],
|
|
2401
|
-
"procs --kill --yes"
|
|
2455
|
+
["proc procs", "leftover and heavy dev processes, by origin"],
|
|
2456
|
+
["proc procs --min-mem 1G --older 1h", "only the big ones that have run a while"],
|
|
2457
|
+
["proc procs --kill", "dry run: what would be stopped"],
|
|
2458
|
+
"proc procs --kill --yes"
|
|
2402
2459
|
]
|
|
2403
2460
|
});
|
|
2404
2461
|
const minMem = values["min-mem"] === undefined ? undefined : parseSize(values["min-mem"], 1024 ** 2);
|
package/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-proc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.8.0",
|
|
5
|
+
"description": "proc: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/proc#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/proc"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": ["process", "port", "proc", "kill", "cli", "bun"],
|
|
16
16
|
"os": ["linux"],
|
|
17
17
|
"bin": {
|
|
18
|
-
"proc": "./dist/proc-cli.js"
|
|
19
|
-
"pid": "./dist/pid-cli.js",
|
|
20
|
-
"ports": "./dist/ports-cli.js",
|
|
21
|
-
"procs": "./dist/procs-cli.js"
|
|
18
|
+
"proc": "./dist/proc-cli.js"
|
|
22
19
|
},
|
|
23
20
|
"files": ["dist", "src"],
|
|
24
21
|
"engines": {
|
|
@@ -28,13 +25,10 @@
|
|
|
28
25
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
29
26
|
},
|
|
30
27
|
"scripts": {
|
|
31
|
-
"build": "$npm_execpath build src/proc-cli.ts
|
|
32
|
-
"proc": "$npm_execpath src/proc-cli.ts"
|
|
33
|
-
"pid": "$npm_execpath src/pid-cli.ts",
|
|
34
|
-
"ports": "$npm_execpath src/ports-cli.ts",
|
|
35
|
-
"procs": "$npm_execpath src/procs-cli.ts"
|
|
28
|
+
"build": "$npm_execpath build src/proc-cli.ts --target bun --outdir dist",
|
|
29
|
+
"proc": "$npm_execpath src/proc-cli.ts"
|
|
36
30
|
},
|
|
37
31
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
32
|
+
"@kaynooo/cli-kit": "0.41.1"
|
|
39
33
|
}
|
|
40
34
|
}
|
package/src/pid.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { maskArgs, maskEnviron } from './mask'
|
|
|
7
7
|
import { parseCgroup, parseEnviron, parseLimits, parseStat, parseStatus, statusBytes } from './parse'
|
|
8
8
|
import { bootMs, fdCount, readProc, readSockets, readText, socketsOf, userName } from './read'
|
|
9
9
|
|
|
10
|
-
const usage = `pid <pid>
|
|
10
|
+
const usage = `proc pid <pid>
|
|
11
11
|
|
|
12
12
|
Shows what a process is: its executable, working directory, command line, parent chain up to init, user, start time and age, memory, open files and limits, the TCP and UDP ports it listens on and its cgroup. Everything is read from /proc; what the calling user cannot read of another user's process is left out and named at the end.
|
|
13
13
|
The environment is not shown unless --env is given, with every value that looks like a secret masked.`
|
|
@@ -170,9 +170,9 @@ export async function pid(args: string[]): Promise<number> {
|
|
|
170
170
|
positionals: ['<pid>'],
|
|
171
171
|
replaces: 'cat /proc/<pid>/{cmdline,environ,limits}, readlink /proc/<pid>/{exe,cwd}, the fish pid function',
|
|
172
172
|
examples: [
|
|
173
|
-
['pid 4242', 'executable, directory, command, parents, memory, limits and ports'],
|
|
174
|
-
['pid 4242 --env', 'with the environment, secrets masked'],
|
|
175
|
-
'pid 4242 --json',
|
|
173
|
+
['proc pid 4242', 'executable, directory, command, parents, memory, limits and ports'],
|
|
174
|
+
['proc pid 4242 --env', 'with the environment, secrets masked'],
|
|
175
|
+
'proc pid 4242 --json',
|
|
176
176
|
],
|
|
177
177
|
})
|
|
178
178
|
const [given] = positionals
|
package/src/ports.ts
CHANGED
|
@@ -10,11 +10,11 @@ import { protectionOf, terminate } from './kill'
|
|
|
10
10
|
import { maskArgs } from './mask'
|
|
11
11
|
import { ancestry, readSockets, snapshot, socketOwners } from './read'
|
|
12
12
|
|
|
13
|
-
const usage = `ports [port]
|
|
13
|
+
const usage = `proc ports [port]
|
|
14
14
|
|
|
15
15
|
Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
|
|
16
|
-
\`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
17
|
-
\`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`
|
|
16
|
+
\`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
17
|
+
\`proc ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`
|
|
18
18
|
const EXITS: ExitRow[] = [[0, 'it listed or stopped'], [1, 'nothing listens on the given port or the owner could not be stopped'], [2, 'a usage error']]
|
|
19
19
|
|
|
20
20
|
const options = {
|
|
@@ -147,10 +147,10 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
147
147
|
positionals: ['[port]'],
|
|
148
148
|
replaces: 'ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand',
|
|
149
149
|
examples: [
|
|
150
|
-
['ports', 'every listening port with its owner'],
|
|
151
|
-
['ports 3000', 'who holds 3000, exit 1 when nobody does'],
|
|
152
|
-
['ports 3000 --kill --yes', 'stop it'],
|
|
153
|
-
'ports --json',
|
|
150
|
+
['proc ports', 'every listening port with its owner'],
|
|
151
|
+
['proc ports 3000', 'who holds 3000, exit 1 when nobody does'],
|
|
152
|
+
['proc ports 3000 --kill --yes', 'stop it'],
|
|
153
|
+
'proc ports --json',
|
|
154
154
|
],
|
|
155
155
|
})
|
|
156
156
|
|
|
@@ -164,7 +164,7 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
164
164
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`)
|
|
165
165
|
|
|
166
166
|
if (values.kill === true && port === undefined)
|
|
167
|
-
badUsage('--kill takes the port to free: ports <port> --kill')
|
|
167
|
+
badUsage('--kill takes the port to free: proc ports <port> --kill')
|
|
168
168
|
|
|
169
169
|
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot('/proc', uid => uid === process.getuid?.())])
|
|
170
170
|
const byPid = new Map(procs.map(proc => [proc.pid, proc]))
|
package/src/procs.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { maskArgs } from './mask'
|
|
|
9
9
|
import { ancestry, snapshot } from './read'
|
|
10
10
|
import { selectGroups } from './select'
|
|
11
11
|
|
|
12
|
-
const usage = `procs
|
|
12
|
+
const usage = `proc procs
|
|
13
13
|
|
|
14
14
|
Lists the leftover or heavy processes of the calling user that are worth cleaning, grouped by origin: the project folder their working directory is in, a browser profile for a chromium and its helpers, else their command. Each group shows its process count, total resident memory and oldest age.
|
|
15
15
|
A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium and chrome, playwright and webview browsers and their helpers, language servers, test runners) and either an orphan, reparented to init or to the user's systemd, or heavy (500M resident by default). The processes below a listed one, and those sharing a browser profile with it, are listed too, so a chromium whose main process was killed groups with its leftover helpers.
|
|
@@ -65,10 +65,10 @@ export async function procs(args: string[]): Promise<number> {
|
|
|
65
65
|
exits: EXITS,
|
|
66
66
|
replaces: 'pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes',
|
|
67
67
|
examples: [
|
|
68
|
-
['procs', 'leftover and heavy dev processes, by origin'],
|
|
69
|
-
['procs --min-mem 1G --older 1h', 'only the big ones that have run a while'],
|
|
70
|
-
['procs --kill', 'dry run: what would be stopped'],
|
|
71
|
-
'procs --kill --yes',
|
|
68
|
+
['proc procs', 'leftover and heavy dev processes, by origin'],
|
|
69
|
+
['proc procs --min-mem 1G --older 1h', 'only the big ones that have run a while'],
|
|
70
|
+
['proc procs --kill', 'dry run: what would be stopped'],
|
|
71
|
+
'proc procs --kill --yes',
|
|
72
72
|
],
|
|
73
73
|
})
|
|
74
74
|
const minMem = values['min-mem'] === undefined ? undefined : parseSize(values['min-mem'], 1024 ** 2)
|