-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetpid.py
More file actions
40 lines (32 loc) · 988 Bytes
/
getpid.py
File metadata and controls
40 lines (32 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import argparse
import psutil
import sys
from voussoirkit import betterhelp
from voussoirkit import subproctools
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, 'getpid')
def getpid_argparse(args):
pids = subproctools.getpid(args.process_name)
status = 0 if len(pids) > 0 else 1
for pid in pids:
print(pid)
return status
@vlogging.main_decorator
def main(argv):
parser = argparse.ArgumentParser(
description='''
Get PIDs for running processes that match the given process name.
Error level will be 0 if any processes are found, 1 if none are found.
''',
)
parser.add_argument(
'process_name',
type=str,
help='''
Name like "python.exe" or "chrome" as it appears in your task manager / ps.
''',
)
parser.set_defaults(func=getpid_argparse)
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))