Created
September 24, 2021 13:22
-
-
Save satoru-takeuchi/eb273d277c468f9e530ad74a324cbbeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import time | |
import os | |
NLOOP=100000 | |
if len(sys.argv) < 2: | |
print("使い方: {} <nproc>".format(sys.argv[0])) | |
exit(1) | |
nproc = int(sys.argv[1]) | |
if nproc < 1: | |
print("nprocは1以上の整数にしてください: {}".format(nproc)) | |
start = time.perf_counter() | |
def child_fn(n): | |
progress = 100*[None] | |
for i in range(100): | |
for j in range(NLOOP): | |
continue | |
progress[i] = time.perf_counter() | |
f = open("{}.txt".format(n),"w") | |
for i in range(100): | |
f.write("{}\t{}\n".format(progress[i]-start,i)) | |
f.close() | |
exit(0) | |
for i in range(nproc): | |
pid = os.fork() | |
if (pid < 0): | |
exit(1) | |
elif pid == 0: | |
child_fn(i) | |
for i in range(nproc): | |
os.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment