I would like to find the parent process for a large amount of small child processes performing small IO operations.
For example, consider the following python script:
import os
import time
import subprocess
def high_tps_reader(file_path, num_reads_per_second, block_size):
while True:
for _ in range(num_reads_per_second):
subprocess.run(['dd', f'if={file_path}', 'of=/dev/null', f'bs={block_size}', 'count=1'], stderr=subprocess.DEVNULL)
sleep(1)
if __name__ == __name__:
file_path = '/tmp/testfile.txt'
num_reads_per_second = 10000
block_size = '4K' # Read 4KB at a time
if not os.path.exists(file_path):
with open(file_path, 'wb') as f:
f.write(b'a' * 1024 * 1024)
# Start the high TPS reader
high_tps_reader(file_path, num_reads_per_second, block_size)
Saving it under /tmp/high_tps.py
and running:
$ python3 /tmp/high_tps.py &
The script will run forever and spawn a very large number of small dd
child processes, who themselves perform IO operations. The combined IO is therefore very large for the parent process.
However, I cannot seem to find a way to see that using standard tools like pidstat
or iotop
as they only report individual processes.
The following does not work:
# pidstat -d 1 5
# iotop -ao
Also, since the dd
child processes almost instantly die, it is impossible for me to see them in the output for the above commands.