@kaynooo/cli-proc 0.7.5 → 0.8.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/README.md +11 -11
- package/dist/proc-cli.js +621 -408
- package/package.json +9 -15
- package/src/pid.ts +6 -6
- package/src/ports.ts +8 -9
- package/src/procs.ts +7 -8
- package/dist/pid-cli.js +0 -1890
- package/dist/ports-cli.js +0 -2155
- package/dist/procs-cli.js +0 -2032
- package/src/pid-cli.ts +0 -7
- package/src/ports-cli.ts +0 -7
- package/src/procs-cli.ts +0 -7
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.1",
|
|
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.46.0"
|
|
39
33
|
}
|
|
40
34
|
}
|
package/src/pid.ts
CHANGED
|
@@ -7,10 +7,10 @@ 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>: shows what a process is, from its executable and command line to its parent chain, memory, open files, listening ports and cgroup
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
The environment is not shown unless --env is given, with every
|
|
12
|
+
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
|
+
The environment is not shown unless --env is given, with every secret masked.`
|
|
14
14
|
const EXITS: ExitRow[] = [[0, 'it showed the process'], [1, 'no process has this pid'], [2, 'a usage error']]
|
|
15
15
|
|
|
16
16
|
const DIGITS = /^\d+$/
|
|
@@ -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,10 @@ 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]: lists what listens on this machine, one row per port with its owning process, command and working directory
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
\`ports <port
|
|
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.`
|
|
15
|
+
A port Docker publishes shows as its compose project and service; the owner of another user's socket shows as -. \`proc ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
16
|
+
\`proc ports <port> --kill\` stops its owner, 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
17
|
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
18
|
|
|
20
19
|
const options = {
|
|
@@ -147,10 +146,10 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
147
146
|
positionals: ['[port]'],
|
|
148
147
|
replaces: 'ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand',
|
|
149
148
|
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',
|
|
149
|
+
['proc ports', 'every listening port with its owner'],
|
|
150
|
+
['proc ports 3000', 'who holds 3000, exit 1 when nobody does'],
|
|
151
|
+
['proc ports 3000 --kill --yes', 'stop it'],
|
|
152
|
+
'proc ports --json',
|
|
154
153
|
],
|
|
155
154
|
})
|
|
156
155
|
|
|
@@ -164,7 +163,7 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
164
163
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`)
|
|
165
164
|
|
|
166
165
|
if (values.kill === true && port === undefined)
|
|
167
|
-
badUsage('--kill takes the port to free: ports <port> --kill')
|
|
166
|
+
badUsage('--kill takes the port to free: proc ports <port> --kill')
|
|
168
167
|
|
|
169
168
|
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot('/proc', uid => uid === process.getuid?.())])
|
|
170
169
|
const byPid = new Map(procs.map(proc => [proc.pid, proc]))
|
package/src/procs.ts
CHANGED
|
@@ -9,11 +9,10 @@ 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: lists the calling user's leftover or heavy dev processes, grouped by project folder, browser profile or command
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
\`--kill\` is a dry run that names what it would stop unless --yes is given; it sends SIGTERM, then SIGKILL after --grace to what is still there. It never signals pid 1, shells, terminals, this command and its ancestors, or processes of other users.`
|
|
14
|
+
A process is listed when it is a dev tool (bun, node, vite, chromium, playwright, 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 it and those sharing its browser profile come with it.
|
|
15
|
+
\`--kill\` is a dry run that names what it would stop unless --yes is given. It never signals pid 1, shells, terminals, this command and its ancestors, or processes of other users.`
|
|
17
16
|
const EXITS: ExitRow[] = [[0, 'it listed or stopped everything'], [1, 'a process survived SIGKILL'], [2, 'a usage error']]
|
|
18
17
|
|
|
19
18
|
const options = {
|
|
@@ -65,10 +64,10 @@ export async function procs(args: string[]): Promise<number> {
|
|
|
65
64
|
exits: EXITS,
|
|
66
65
|
replaces: 'pkill -f and pgrep -f one-liners (which match their own shell), ps aux | grep for leftover chromium, bun or vite processes',
|
|
67
66
|
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',
|
|
67
|
+
['proc procs', 'leftover and heavy dev processes, by origin'],
|
|
68
|
+
['proc procs --min-mem 1G --older 1h', 'only the big ones that have run a while'],
|
|
69
|
+
['proc procs --kill', 'dry run: what would be stopped'],
|
|
70
|
+
'proc procs --kill --yes',
|
|
72
71
|
],
|
|
73
72
|
})
|
|
74
73
|
const minMem = values['min-mem'] === undefined ? undefined : parseSize(values['min-mem'], 1024 ** 2)
|