Hola a todos, soy nuevo en el foro y también en programación Shell Script.
El problema es el siguiente:
necesito hacer un Script que busque todos los procesos del sistema y me muestre de forma jerárquica la cantidad de Bytes que ocupa cada una de las regiones del mapa de memoria de cada proceso.
Actualmente he conseguido que me muestre la cantidad de regiones en el mapa de memoria, esto lo hice solo para checar si en realidad esta funcionando el AWK, ahora lo que no he logrado es almacenar en 2 variables las direcciones de memoria que aparecen en la primera cadena de cada linea del fichero MAPS, entiendo que la dirección está en hexadecimal debo restar la dirección "menor" a la "mayor" pero primero cambiar la cadena a mayúsculas separarla en dos variables (así lo entiendo) y luego realizar la operación para que ahora si me muestre los dichosos BYtes que necesito jeje
Aqui les dejo Parte del fichero MAPS:
00110000-00126000 r-xp 00000000 08:01 8051 /usr/lib/libnssutil3.so
00126000-00129000 r--p 00015000 08:01 8051 /usr/lib/libnssutil3.so
00129000-0012a000 rw-p 00018000 08:01 8051 /usr/lib/libnssutil3.so
0012a000-0012d000 r-xp 00000000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2
0012d000-0012e000 r--p 00002000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2
El Script es el siguiente:
#!/bin/sh
#!/bin/bash
filtrado()
{
RES=0
echo "PROCESO $n"
cat /proc/"$n"/maps |sed 's/-/ /' | awk 'END {print "TOTAL:",NR;}'
awk '$2~/[p]/{ RES=RES+1;};END{print " PRIVADOS:",RES;}' /proc/"$n"/maps
awk '$2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " CON SOPORTE:",RES;}' /proc/"$n"/maps
awk '$2~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[x]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps
awk '$5!~/[1-9]/ && $2~/[p]/ {RES=RES+1;};END{print " ANONIMOS:",RES;}' /proc/"$n"/maps
awk '$2~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[x]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps
awk '$2~/[s]/{ RES=RES+1;};END{print " COMPARTIDOS:",RES;}' /proc/"$n"/maps
awk '$2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " CON SOPORTE:",RES;}' /proc/"$n"/maps
awk '$2~/[w]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[x]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[r]/ && $2!~/[w]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps
awk '$5!~/[1-9]/ && $2~/[s]/ {RES=RES+1;};END{print " ANONIMOS:",RES;}' /proc/"$n"/maps
awk '$2~/[w]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[x]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps
awk '$2~/[r]/ && $2!~/[w]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps
echo " "
}
clear
for n in `seq 1 10000`;
do
m=/proc/$n/maps
if [ -f $m ]; then
filtrado $n
fi
done
exit
de antemano gracias, espero haberme dado a entender
---------- Post updated at 01:08 PM ---------- Previous update was at 01:05 PM ----------
sorry, I can´t put post in spanish