User Tools

Site Tools


listar_los_procesos_que_usan_memoria_swap

Listado de procesos que están utilizando la memoria de intercambio (SWAP)

Recomendación (smem): Smem.

Linea de comandos: Listar uso de memoria swap de todos los procesos.

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done

Script: Listar todos los procesos que están utilizando memoria swap.

pidswap.sh
#!/bin/bash
 
    # find-out-what-is-using-your-swap.sh
    # -- Get current swap usage for all running processes
    # --
    # -- rev.0.3, 2012-09-03, Jan Smid          - alignment and intendation, sorting
    # -- rev.0.2, 2012-08-09, Mikko Rantalainen - pipe the output to "sort -nk3" to get sorted output
    # -- rev.0.1, 2011-05-27, Erik Ljungstrom   - initial version
 
 
SCRIPT_NAME=`basename $0`;
SORT="kb";                 # {pid|kB|name} as first parameter, [default: kb]
[ "$1" != "" ] && { SORT="$1"; }
 
[ ! -x `which mktemp` ] && { echo "ERROR: mktemp is not available!"; exit; }
MKTEMP=`which mktemp`;
TMP=`${MKTEMP} -d`;
[ ! -d "${TMP}" ] && { echo "ERROR: unable to create temp dir!"; exit; }
 
>${TMP}/${SCRIPT_NAME}.pid;
>${TMP}/${SCRIPT_NAME}.kb;
>${TMP}/${SCRIPT_NAME}.name;
 
SUM=0;
OVERALL=0;
    echo "${OVERALL}" > ${TMP}/${SCRIPT_NAME}.overal;
 
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`;
do
    PID=`echo $DIR | cut -d / -f 3`
    PROGNAME=`ps -p $PID -o comm --no-headers`
 
    for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
    do
        let SUM=$SUM+$SWAP
    done
 
    if (( $SUM > 0 ));
    then
        echo -n ".";
        echo -e "${PID}\t${SUM}\t${PROGNAME}" >> ${TMP}/${SCRIPT_NAME}.pid;
        echo -e "${SUM}\t${PID}\t${PROGNAME}" >> ${TMP}/${SCRIPT_NAME}.kb;
        echo -e "${PROGNAME}\t${SUM}\t${PID}" >> ${TMP}/${SCRIPT_NAME}.name;
    fi
    let OVERALL=$OVERALL+$SUM
    SUM=0
done
echo "${OVERALL}" > ${TMP}/${SCRIPT_NAME}.overal;
echo;
echo "Overall swap used: ${OVERALL} kB";
echo "========================================";
case "${SORT}" in
    name )
        echo -e "name\tkB\tpid";
        echo "========================================";
        cat ${TMP}/${SCRIPT_NAME}.name|sort -r;
        ;;
 
    kb )
        echo -e "kB\tpid\tname";
        echo "========================================";
        cat ${TMP}/${SCRIPT_NAME}.kb|sort -rh;
        ;;
 
    pid | * )
        echo -e "pid\tkB\tname";
        echo "========================================";
        cat ${TMP}/${SCRIPT_NAME}.pid|sort -rh;
        ;;
esac
rm -fR "${TMP}/";

Ejemplo de salida.

 bash script.sh
............................................................................................................................................................................
Overall swap used: 841660 kB
========================================
kB      pid     name
========================================
132568  5587    python
127816  5719    python
32912   26898   mysqld
10596   26422   php-fpm
9960    26363   php-fpm
9948    26364   php-fpm
9780    26416   php-fpm
9468    5718    supervisord
9372    26431   php-fpm
8364    26412   php-fpm
6908    26418   php-fpm
5980    26454   php-fpm
5884    26435   php-fpm
5708    26419   php-fpm
5472    26360   php-fpm
5472    26359   php-fpm
5472    26358   php-fpm
5460    26357   php-fpm
5460    26356   php-fpm
5052    26417   php-fpm
4640    26477   php-fpm
4640    26476   php-fpm
4640    26475   php-fpm
4640    26474   php-fpm
4640    26473   php-fpm
4640    26472   php-fpm
4640    26471   php-fpm
4640    26470   php-fpm
4636    26469   php-fpm
4636    26468   php-fpm
4636    26467   php-fpm
4636    26465   php-fpm
4636    26464   php-fpm
4636    26463   php-fpm
4636    26462   php-fpm
4636    26461   php-fpm
4636    26460   php-fpm
4636    26459   php-fpm
4636    26458   php-fpm
4636    26457   php-fpm
4624    26406   php-fpm
4620    26405   php-fpm
4620    26404   php-fpm
4620    26403   php-fpm
4620    26402   php-fpm
4620    26401   php-fpm
4620    26400   php-fpm
4620    26399   php-fpm
4620    26398   php-fpm
4620    26397   php-fpm
4620    26396   php-fpm
4620    26395   php-fpm
4620    26394   php-fpm
4616    26393   php-fpm
4616    26392   php-fpm
4616    26391   php-fpm
4616    26390   php-fpm
4616    26389   php-fpm
4616    26388   php-fpm
4616    26387   php-fpm
4616    26386   php-fpm
4616    26385   php-fpm
4616    26384   php-fpm
4616    26383   php-fpm
4616    26382   php-fpm
4616    26381   php-fpm
4612    26380   php-fpm
4612    26379   php-fpm
4612    26378   php-fpm
4612    26377   php-fpm
4612    26376   php-fpm
4612    26374   php-fpm
4612    26373   php-fpm
4612    26372   php-fpm
4612    26371   php-fpm
4612    26370   php-fpm
4612    26369   php-fpm
4612    26368   php-fpm
4612    26367   php-fpm
4608    26366   php-fpm
4608    26365   php-fpm
4608    26362   php-fpm
4608    26361   php-fpm
4532    26355   php-fpm
4048    26410   php-fpm
3536    26428   php-fpm
3532    26409   php-fpm
3508    26423   php-fpm
3396    26436   php-fpm
3168    26449   php-fpm
3144    26444   php-fpm
2988    26420   php-fpm
2956    26439   php-fpm
2916    26415   php-fpm
2868    26447   php-fpm
2752    26425   php-fpm
2748    26437   php-fpm
2728    26434   php-fpm
2688    26448   php-fpm
2664    26426   php-fpm
2656    26451   php-fpm
2632    26408   php-fpm
2584    26424   php-fpm
2572    26441   php-fpm
2556    26452   php-fpm
2516    26455   php-fpm
2516    26414   php-fpm
2500    26440   php-fpm
2472    26432   php-fpm
2472    26407   php-fpm
2456    26429   php-fpm
2440    26443   php-fpm
2436    26421   php-fpm
2420    26411   php-fpm
2416    26450   php-fpm
2392    26438   php-fpm
2376    26453   php-fpm
2356    26427   php-fpm
2348    26433   php-fpm
2344    26442   php-fpm
2340    26430   php-fpm
2336    26456   php-fpm
2292    26445   php-fpm
2200    26446   php-fpm
1992    26621   nginx
1932    26413   php-fpm
1368    18115   nginx
1312    18112   nginx
1280    18113   nginx
1004    18114   nginx
948     23014   qmgr
836     1506    master
704     799     udevd
700     802     udevd
692     452     udevd
596     5723    nrpe
564     1619    crond
564     1285    sshd
492     1640    memcached
448     1165    rpc.statd
428     1052    vmtoolsd
424     5994    memcached
424     1661    memcached
320     31481   rsyslogd
284     26793   mysqld_safe
236     1245    dbus-daemon
208     1192    rpc.idmapd
184     1147    rpcbind
160     1107    auditd
152     13971   zabbix_agentd
136     1       init
132     1273    mcelog
112     13983   zabbix_agentd
96      13972   zabbix_agentd
88      1213    lldpad
80      1682    mingetty
80      1233    fcoemon
76      1684    mingetty
76      1680    mingetty
76      1678    mingetty
76      1676    mingetty
76      1674    mingetty
64      13982   zabbix_agentd
64      13981   zabbix_agentd
64      13980   zabbix_agentd
64      13979   zabbix_agentd
64      13978   zabbix_agentd
64      13977   zabbix_agentd
64      13976   zabbix_agentd
64      13975   zabbix_agentd
64      13974   zabbix_agentd
64      13973   zabbix_agentd
listar_los_procesos_que_usan_memoria_swap.txt · Last modified: 2020/12/25 22:57 by 127.0.0.1