How to get the raw number of bytes that a given PID is using from the Linux terminal regardless of distro?
Try one of these methods:
# process id
pid=$$
# memory page size
psz=$(grep -m1 KernelPageSize /proc/$pid/smaps |tr -d -c [0-9])
# assume by “RAM usage” OP wants “resident size”
printf '
1. with “ps” command : %d
2. from /proc/pid/status: %d
3. from /proc/pid/statm : %d
4. from /proc/pid/stat : %d
' $( ps -p $pid ho rsz ) \
$( grep -m1 VmRSS /proc/$pid/status |tr -d -c [0-9] ) \
$( read -a s < /proc/$pid/statm; echo $(( ${s[1]} * $psz )) ) \
$( read -a s < /proc/$pid/stat; echo $(( ${s[23]} * $psz )) )
1. with “ps” command : 12160
2. from /proc/pid/status: 12160
3. from /proc/pid/statm : 12160
4. from /proc/pid/stat : 12160
※ For /proc
filesystem refer to linux kernel documentation
※ For ps
command check its manual