bhtool 0.2.2__tar.gz → 0.2.3__tar.gz
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.
- {bhtool-0.2.2 → bhtool-0.2.3}/PKG-INFO +1 -1
- bhtool-0.2.3/bhtool/psword.py +53 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/pyproject.toml +1 -1
- bhtool-0.2.2/bhtool/psword.py +0 -23
- {bhtool-0.2.2 → bhtool-0.2.3}/.gitignore +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/.python-version +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/README.md +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/bumpver.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/cli.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/clr_chmod.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/list_movies.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/npread.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/portkill.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/rm_npm.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/run.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/text.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/todict.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/bhtool/utils.py +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/jtools/jtools.js +0 -0
- {bhtool-0.2.2 → bhtool-0.2.3}/jtools/package.json +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Find processes with name"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import signal
|
|
8
|
+
|
|
9
|
+
from bhtool.utils import run_output
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def own_pids() -> set[int]:
|
|
13
|
+
"""Our process and its ancestors, which must never be killed."""
|
|
14
|
+
parents = {
|
|
15
|
+
int(pid): int(ppid)
|
|
16
|
+
for pid, ppid in re.findall(
|
|
17
|
+
r"(\d+)\s+(\d+)", run_output("ps -o pid=,ppid= -ax")
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
pids = {os.getpid()}
|
|
21
|
+
pid = os.getpid()
|
|
22
|
+
while pid in parents and parents[pid] > 1 and parents[pid] not in pids:
|
|
23
|
+
pid = parents[pid]
|
|
24
|
+
pids.add(pid)
|
|
25
|
+
return pids
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def psword(words: tuple[str, ...], kill: bool = False):
|
|
29
|
+
killed: set[int] = set()
|
|
30
|
+
skip = own_pids()
|
|
31
|
+
for word in words:
|
|
32
|
+
txt = run_output(f"ps aux | grep {word}")
|
|
33
|
+
for line in txt.splitlines():
|
|
34
|
+
tokens = line.split(None, 10)
|
|
35
|
+
if len(tokens) < 11:
|
|
36
|
+
continue
|
|
37
|
+
cmd = tokens[10]
|
|
38
|
+
if cmd.startswith("grep ") or "ps aux | grep" in cmd:
|
|
39
|
+
continue
|
|
40
|
+
pid = int(tokens[1])
|
|
41
|
+
if pid in skip or pid in killed:
|
|
42
|
+
continue
|
|
43
|
+
if len(cmd) > 80:
|
|
44
|
+
cmd = cmd[:80] + "..."
|
|
45
|
+
if kill:
|
|
46
|
+
print(f"kill target ({cmd})")
|
|
47
|
+
try:
|
|
48
|
+
os.kill(pid, signal.SIGKILL)
|
|
49
|
+
killed.add(pid)
|
|
50
|
+
except (ProcessLookupError, PermissionError) as err:
|
|
51
|
+
print(f"could not kill {pid}: {err}")
|
|
52
|
+
else:
|
|
53
|
+
print(f"process {pid}: {cmd}")
|
bhtool-0.2.2/bhtool/psword.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
"""Find processes with name"""
|
|
4
|
-
|
|
5
|
-
from bhtool.utils import run, run_output
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def psword(words: tuple[str, ...], kill: bool = False):
|
|
9
|
-
for word in words:
|
|
10
|
-
txt = run_output(f"ps aux | grep {word}")
|
|
11
|
-
for line in txt.splitlines():
|
|
12
|
-
tokens = line.split()
|
|
13
|
-
i_process = tokens[1]
|
|
14
|
-
cmd = " ".join(tokens[10:])
|
|
15
|
-
if len(cmd) > 80:
|
|
16
|
-
cmd = cmd[:80] + "..."
|
|
17
|
-
if "psword" in line:
|
|
18
|
-
continue
|
|
19
|
-
if kill:
|
|
20
|
-
print(f"kill target ({cmd})")
|
|
21
|
-
run(f"kill -9 {i_process}")
|
|
22
|
-
else:
|
|
23
|
-
print(f"process {i_process}: {cmd}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|