Skip to content

Instantly share code, notes, and snippets.

@sargun
Created December 3, 2020 02:11
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 sargun/dbca7659b9de4aa0549f6ddac7541245 to your computer and use it in GitHub Desktop.
Save sargun/dbca7659b9de4aa0549f6ddac7541245 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os, random, time, sys, mmap, random
fds = []
mmaps = []
SIZE = (2**20)
def rand_str():
return bytes(chr(random.randint(0, 127)) * SIZE, 'ascii')
n = random.randint(0, 1000)
while True:
if len(fds) < 1000:
fd = os.open('/mnt', os.O_RDWR | os.O_TMPFILE)
fds.append(fd)
os.write(fd, rand_str()) # 4MB
if len(mmaps) < 10000:
m = mmap.mmap(-1, 4096)
mmaps.append(m)
else:
mmaps.pop(0).close()
if n % 1000 == 0:
n += 1
for (dirpath, dirnames, filenames) in os.walk('/sys'):
for f in dirnames + filenames:
try:
os.stat(os.path.join(dirpath, f))
except Exception as e:
print(f'Experienced error stating {dirpath}/{f}: {e}')
for i in mmaps:
m[0:4095] = b'x'*4095
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment