44 lines
915 B
Python
Executable File
44 lines
915 B
Python
Executable File
#!/bin/python3
|
|
|
|
import sys
|
|
import time
|
|
import signal
|
|
|
|
# Ignore SIGTERM
|
|
def handle_sigterm(signum, frame):
|
|
print("SIGTERM received but ignored")
|
|
|
|
sig="NONE"
|
|
while not sig in ["y", "n"]:
|
|
sig = input("Signal? (y|n)").strip()
|
|
if sig=="y":
|
|
print("Capturing SIGTERM")
|
|
signal.signal(signal.SIGTERM, handle_sigterm)
|
|
|
|
# 4 GiB in bytes
|
|
mem = input("enter allocated mem in GB\n> ")
|
|
TARGET_SIZE = int(mem) * 1024 * 1024 * 1024
|
|
|
|
CHUNK_SIZE = 100 * 1024 * 1024 # 100 MB chunks
|
|
|
|
blocks = []
|
|
total = 0
|
|
|
|
print("Allocating memory...")
|
|
|
|
try:
|
|
while total < TARGET_SIZE:
|
|
blocks.append(bytearray(CHUNK_SIZE))
|
|
total += CHUNK_SIZE
|
|
print(f"Allocated: {total / (1024**3):.2f} GB")
|
|
time.sleep(0.01)
|
|
|
|
print("Done. Holding memory... Press Ctrl+C to exit.")
|
|
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
except KeyboardInterrupt:
|
|
print("\nExiting, releasing memory...")
|
|
blocks.clear()
|