Skip to content

Instantly share code, notes, and snippets.

@matthewrmshin
Created July 18, 2013 13:51
Show Gist options
  • Save matthewrmshin/6029468 to your computer and use it in GitHub Desktop.
Save matthewrmshin/6029468 to your computer and use it in GitHub Desktop.
An attempt to repeat the `/bin/sh: FILE: /bin/bash: bad interpreter: Text file busy` problem. Write 10000 script files and executes them using a pool 10 processes.
#!/usr/bin/python
from glob import glob
from multiprocessing import Pool
import os
import stat
from subprocess import call
from uuid import uuid4
def main():
try:
pool = Pool(processes=10)
pool.map(write_and_exec, range(10000))
pool.close()
pool.join()
finally:
for name in glob("hello-*"):
os.unlink(name)
def write_and_exec(i):
f_name = "hello-%04d" % i
f = open(f_name, "w")
f.write("#!/bin/bash\ntrue\n")
f.flush()
#os.fsync(f.fileno())
f.close()
os.chmod(f_name, os.stat(f_name).st_mode | stat.S_IXUSR)
call([f_name], shell=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment