Skip to content

Instantly share code, notes, and snippets.

@satoru-takeuchi
Created September 24, 2021 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satoru-takeuchi/eb273d277c468f9e530ad74a324cbbeb to your computer and use it in GitHub Desktop.
Save satoru-takeuchi/eb273d277c468f9e530ad74a324cbbeb to your computer and use it in GitHub Desktop.
#!/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