一行代码实现 linux 指定进程网络的使用情况
pid=4203;count=0;while true;do info2=`sed -n '4,100p' /proc/$pid/net/dev |awk '{print $2" "$10}'|awk 'BEGIN {recv=0;sen=0}{revc+=$1;sen+=$2}END{print revc","sen}'`;recv2=`echo $info2|cut -d, -f1`;sen2=`echo $info2|cut -d, -f2`;[[ $((count%15)) -eq 0 ]] && (echo "recv (bytes) send") ;if [[ $count -eq 0 ]];then recv_diff=0;sen_diff=0;else recv_diff=$((recv2-recv1));sen_diff=$((sen2-sen1));fi;printf "%-15s %s " $recv_diff $sen_diff;recv1=$recv2;sen1=$sen2;count=$((count+1));sleep 1;done