-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcpuhog
More file actions
executable file
·44 lines (34 loc) · 810 Bytes
/
cpuhog
File metadata and controls
executable file
·44 lines (34 loc) · 810 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
41
42
43
44
#!/usr/bin/env python3
"""
usage: cpuhog [NUM_PROCS]
CPUHog will hog your CPU.
"""
import multiprocessing
import os
import sys
def hog():
print('hog started: %d' % os.getpid())
try:
while True:
pass
except KeyboardInterrupt:
pass
def run_hogs(num_hogs):
print('Launching %d hogs' % num_hogs)
procs = [multiprocessing.Process(target=hog) for i in range(num_hogs)]
for p in procs:
p.start()
for p in procs:
p.join()
if __name__ == '__main__':
if '-h' in sys.argv or '--help' in sys.argv:
print(__doc__.strip())
sys.exit()
if len(sys.argv) > 1:
num = int(sys.argv[1])
else:
num = multiprocessing.cpu_count()
try:
run_hogs(num)
except KeyboardInterrupt:
print('')