You are not logged in.

#1 2007-09-01 04:05:21

Bangel
Member
Registered: 2007-05-17
Posts: 45

Stack Viewing on Archlinux

What's the command to view the stack of each occupying process?

Offline

#2 2007-09-01 16:35:15

mac57
Member
From: St. Somewhere
Registered: 2006-01-06
Posts: 304
Website

Re: Stack Viewing on Archlinux

Not sure I understand your question, and what the application for it is. The lack of other responses suggests that no one else does either.

Could you expand on the question a bit please, and explain why you want to do whatever it is?


Cast off the Microsoft shackles Jan 2005

Offline

#3 2007-09-01 16:58:03

KimTjik
Member
From: Sweden
Registered: 2007-08-22
Posts: 715

Re: Stack Viewing on Archlinux

Could he simply be looking for the "top" command? It kinds of fit the description, though being somewhat obscure.

Offline

#4 2007-09-01 17:27:35

Bangel
Member
Registered: 2007-05-17
Posts: 45

Re: Stack Viewing on Archlinux

I want to see the memory mapper, like a table with all the hex addresses sorted with each running processs. Like the stack for a running process begins at ... and ends at ...

Offline

#5 2007-09-01 18:00:21

hussam
Member
Registered: 2006-03-26
Posts: 572
Website

Re: Stack Viewing on Archlinux

Not sure if this is what you want. but if you are trying to debug a program, you first need to build it with debug symbols enabled and not stripped. then if yourapp is already running, run:
gdb attach `pidof yourapp`

after you get to the gdb prompt, type:
bt full

Offline

#6 2007-09-01 18:21:02

Bangel
Member
Registered: 2007-05-17
Posts: 45

Re: Stack Viewing on Archlinux

No, I want to see a list of all running processes. This I can view with top. However, I want to see all the beginning and end addresses of the stack for each running process.
For example ... I do :

cat /proc/1/maps

and I got all the stack space of the init daemon and all it's libraries. However, I want to do this for ALL processes ... is it possible?

Offline

#7 2007-09-01 18:44:24

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,019

Re: Stack Viewing on Archlinux

cat all pids in proc?

Offline

#8 2007-09-01 21:20:25

Bangel
Member
Registered: 2007-05-17
Posts: 45

Re: Stack Viewing on Archlinux

One at a time? That is way to much time.

Offline

#9 2007-09-02 10:12:47

MrWeatherbee
Member
Registered: 2007-08-01
Posts: 288

Re: Stack Viewing on Archlinux

Bangel wrote:

cat /proc/1/maps

Bangel wrote:

One at a time? That is way to much time.

Below is a script that automates the process you described above for all numbered processes (PIDs) in /proc.

CAVEAT: NO DANGEROUS OPERATIONS ARE PERFORMED, ONLY READ OPERATIONS (EXCEPT FOR WRITING OUTPUT FILE). REGARDLESS, PLEASE REVIEW THE CODE CAREFULLY.

Please modify the script in any way that may be useful to you, or scrap it if it has no benefit whatsoever. It wasn't very difficult, and I learned a few things about /proc along the way. smile

Notes:

- You may notice in your review of the code that I took a round-about way of testing for non-zero byte status of files in /proc. Normally, the "-s" test works, but all files in proc evaluate to 0 bytes whether they have contents or not.

- You will notice a Summary line in the output which states:

# Number of PIDs Terminated Before stackmap Could Parse Information:  2

This simply reflects the number of processes that were originally found in /proc (using the 'find' command) but that were no longer running by the time the script attempted to actually process information about that particular PID (i.e., processing status and maps files with 'head' and 'cat' commands, respectively). The terminated PIDs may or may not be associated with the script itself (likely they will be).

The terminated PIDs are identified in the body of the output like this:

=========================== /proc/31107
** PID 31107 TERMINATED BEFORE IT COULD BE PROCESSED BY stackmap
=========================== /proc/31108
** PID 31108 TERMINATED BEFORE IT COULD BE PROCESSED BY stackmap

Script:

#!/bin/bash

# AUTHOR:    Anonymous
# VERSION:    1.0
# LICENSE:    n/a
# Date:        2007 09/02
# REQUIRES:    standard shell commands
# SCRIPT NAME:    stackmap
# DESCRIPTION:    collect maps info of running processes and write to text file 
#               
#=============

scriptname="stackmap"
findproc=$(find /proc/ -maxdepth 1 -type d | grep [0-9] 2> /dev/null)
proccount=$(echo $findproc | wc -w)
file1="status"
file2="maps"
outfile="$HOME/Desktop/stackmaps_out.txt"
timestamp="$(date '+%F_%T')"
countstat1=0
countstat2=0
countmaps1=0
countmaps2=0
countterm=0

echo "# Process Maps Data" > $outfile
echo "# Date: $timestamp" >> $outfile

for proc in $findproc; do
    proccut="$(echo $proc | cut -c7-)"
    if [ -e $proc ] ; then
        headstat=$(head -n1 $proc/$file1)
        headmaps=$(head -n1 $proc/$file2)
        echo "=========================== $proc" >> $outfile
        if [ -n "$headstat" ] ; then
            head -n7  $proc/$file1 >> $outfile
            let "countstat1+=1"
        else
            echo "$file1 File For PID: $proccut Is 0 Bytes (Empty)" >> $outfile
            let "countstat2+=1"
        fi
        echo " -------------------------- maps" >> $outfile
        if [ -n "$headmaps" ] ; then
            cat $proc/$file2 >> $outfile
            let "countmaps1+=1"
        else
            echo "$file2 File For PID: $proccut Is 0 Bytes (Empty)" >> $outfile
            let "countmaps2+=1"
        fi
    else
        echo "=========================== $proc" >> $outfile
        echo "** PID $proccut TERMINATED BEFORE IT COULD BE PROCESSED BY $scriptname" >> $outfile
        let countterm "countterm+=1" 
    fi    
done
echo >> $outfile
echo "# =========================" >> $outfile
echo "# Summary" >> $outfile
echo "# =========================" >> $outfile
echo "# Total Number of Initial PIDs Found in /proc: $proccount" >> $outfile
echo "# Number of PIDs Terminated Before $scriptname Could Parse Information:  $countterm" >> $outfile
echo "# Total Number of PID Status Files Read: $countstat1" >> $outfile
echo "# Number of PID Status Files Read But With No Contents (Empty Files): $countstat2" >> $outfile
echo "# Total Number of Maps Files Read: $countmaps1" >> $outfile
echo "# Number of Maps Files Read But With No Contents (Empty Files): $countmaps2" >> $outfile
echo "# =========================" >> $outfile

exit

Sample output:

# Process Maps Data
# Date: 2007-09-02_05:40:58
=========================== /proc/1
Name:    init
State:    S (sleeping)
SleepAVG:    98%
Tgid:    1
Pid:    1
PPid:    0
TracerPid:    0
 -------------------------- maps
08048000-0804f000 r-xp 00000000 08:29 594        /sbin/init
0804f000-08050000 rwxp 00007000 08:29 594        /sbin/init
08050000-08071000 rwxp 08050000 00:00 0          [heap]
b7da1000-b7da2000 rwxp b7da1000 00:00 0 
b7da2000-b7ecd000 r-xp 00000000 08:29 57         /lib/libc-2.6.1.so
b7ecd000-b7ece000 r-xp 0012b000 08:29 57         /lib/libc-2.6.1.so
b7ece000-b7ed0000 rwxp 0012c000 08:29 57         /lib/libc-2.6.1.so
b7ed0000-b7ed4000 rwxp b7ed0000 00:00 0 
b7ee7000-b7ee8000 r-xp b7ee7000 00:00 0          [vdso]
b7ee8000-b7f02000 r-xp 00000000 08:29 2743       /lib/ld-2.6.1.so
b7f02000-b7f03000 r-xp 00019000 08:29 2743       /lib/ld-2.6.1.so
b7f03000-b7f04000 rwxp 0001a000 08:29 2743       /lib/ld-2.6.1.so
bfd8d000-bfda2000 rw-p bfd8d000 00:00 0          [stack]
=========================== /proc/2
Name:    kthreadd
State:    S (sleeping)
SleepAVG:    85%
Tgid:    2
Pid:    2
PPid:    0
TracerPid:    0
 -------------------------- maps
maps File For PID: 2 Is 0 Bytes (Empty)
=========================== /proc/3
Name:    migration/0
State:    S (sleeping)
SleepAVG:    0%
Tgid:    3
Pid:    3
PPid:    2
TracerPid:    0
 -------------------------- maps
maps File For PID: 3 Is 0 Bytes (Empty)
=========================== /proc/4
Name:    ksoftirqd/0
State:    S (sleeping)
SleepAVG:    98%
Tgid:    4
Pid:    4
PPid:    2
TracerPid:    0
 -------------------------- maps
maps File For PID: 4 Is 0 Bytes (Empty)

<<-------------------------------------  SNIP Hundreds of Lines of Output   --------------------------------->>

=========================== /proc/31103
Name:    stackmap
State:    R (running)
SleepAVG:    0%
Tgid:    31103
Pid:    31103
PPid:    9083
TracerPid:    0
 -------------------------- maps
08048000-080c4000 r-xp 00000000 08:29 77         /bin/bash
080c4000-080c7000 rwxp 0007c000 08:29 77         /bin/bash
080c7000-0810f000 rwxp 080c7000 00:00 0          [heap]
b7c37000-b7c78000 rwxp b7c37000 00:00 0 
b7c78000-b7dec000 r-xp 00000000 fe:00 93967      /usr/lib/locale/locale-archive
b7dec000-b7dee000 rwxp b7dec000 00:00 0 
b7dee000-b7f19000 r-xp 00000000 08:29 57         /lib/libc-2.6.1.so
b7f19000-b7f1a000 r-xp 0012b000 08:29 57         /lib/libc-2.6.1.so
b7f1a000-b7f1c000 rwxp 0012c000 08:29 57         /lib/libc-2.6.1.so
b7f1c000-b7f1f000 rwxp b7f1c000 00:00 0 
b7f1f000-b7f21000 r-xp 00000000 08:29 20         /lib/libdl-2.6.1.so
b7f21000-b7f23000 rwxp 00001000 08:29 20         /lib/libdl-2.6.1.so
b7f23000-b7f5c000 r-xp 00000000 08:29 69         /lib/libncurses.so.5.6
b7f5c000-b7f64000 rwxp 00039000 08:29 69         /lib/libncurses.so.5.6
b7f64000-b7f65000 rwxp b7f64000 00:00 0 
b7f65000-b7f6c000 r-xp 00000000 08:29 169        /lib/libhistory.so.5.2
b7f6c000-b7f6d000 rwxp 00006000 08:29 169        /lib/libhistory.so.5.2
b7f6d000-b7f99000 r-xp 00000000 08:29 2865       /lib/libreadline.so.5.2
b7f99000-b7f9d000 rwxp 0002c000 08:29 2865       /lib/libreadline.so.5.2
b7f9d000-b7f9e000 rwxp b7f9d000 00:00 0 
b7fb0000-b7fb2000 rwxp b7fb0000 00:00 0 
b7fb2000-b7fb3000 r-xp b7fb2000 00:00 0          [vdso]
b7fb3000-b7fcd000 r-xp 00000000 08:29 2743       /lib/ld-2.6.1.so
b7fcd000-b7fce000 r-xp 00019000 08:29 2743       /lib/ld-2.6.1.so
b7fce000-b7fcf000 rwxp 0001a000 08:29 2743       /lib/ld-2.6.1.so
bf8db000-bf8f1000 rw-p bf8db000 00:00 0          [stack]
=========================== /proc/31107
** PID 31107 TERMINATED BEFORE IT COULD BE PROCESSED BY stackmap
=========================== /proc/31108
** PID 31108 TERMINATED BEFORE IT COULD BE PROCESSED BY stackmap

# =========================
# Summary
# =========================
# Total Number of Initial PIDs Found in /proc: 97
# Number of PIDs Terminated Before stackmap Could Parse Information:  2
# Total Number of PID Status Files Read: 95
# Number of PID Status Files Read But With No Contents (Empty Files): 0
# Total Number of Maps Files Read: 65
# Number of Maps Files Read But With No Contents (Empty Files): 30
# =========================

Last edited by MrWeatherbee (2007-09-02 11:29:33)

Offline

Board footer

Powered by FluxBB