Загрузка данных


#!/bin/bash

> start.txt

for pid in $(ls /proc | grep '^[0-9]*$')
do
    if [ -f /proc/$pid/io ]
    then
        bytes=$(grep read_bytes /proc/$pid/io | awk '{print $2}')

        echo "$pid $bytes" >> start.txt
    fi
done

sleep 20

> result.txt

for pid in $(ls /proc | grep '^[0-9]*$')
do
    if [ -f /proc/$pid/io ]
    then
        start_bytes=$(grep "^$pid " start.txt | awk '{print $2}')

        end_bytes=$(grep read_bytes /proc/$pid/io | awk '{print $2}')

        if [ ! -z "$start_bytes" ] && [ ! -z "$end_bytes" ]
        then
            diff=$((end_bytes - start_bytes))

            cmd=$(cat /proc/$pid/cmdline | tr '\0' ' ')

            echo "$pid:$cmd:$diff" >> result.txt
        fi
    fi
done

sort -t ':' -k3 -nr result.txt | head -3