#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Reading proc/pid/mem File


    Hi, I'm trying to read a process's proc/pid/mem file but with no luck.

    While open succeeds, no matter what I try - read always returns -1.

    Any ideas?

    Thanks!

    --sternr
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Minneapolis, MN
    Posts
    356
    Rep Power
    13
    What exactly are you trying to do with that? From what I've read, that file can only be read if the process is halted:

    http://forum.kernelnewbies.org/read....10,210,quote=1

    Are you actually trying to examine the process' memory allocations?
    badger badger badger badger
    badger badger badger badger
    MUSHROOM MUSHROOM
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0
    Yes, to be more specific - the process's stack.

    My code uses the ptrace attach API before trying to read the file to force the process to halt.

    But still no matter what I try I dont seem to be able to read the other process's stack, even when I'm running as root and the target process is my child process.

    Any ideas?
    Are there any alternatives for reading process's stack?
    (not including ptrace, as it allows reading one word at a time)

    Thanks!

    --sternr
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Minneapolis, MN
    Posts
    356
    Rep Power
    13
    Well, first off, if you are looking to examine the stack, have you tried just using gdb? Here's a mac developer article that seems to cover a lot of the basics (mac or linux shouldn't make any real difference here):

    http://developer.apple.com/library/m...gdb/gdb_7.html

    Another option might be to just to manually send it a SIGSTOP (or simply CTRL-Z if you are running it in a shell) and see if you can open the file(s).
    badger badger badger badger
    badger badger badger badger
    MUSHROOM MUSHROOM

IMN logo majestic logo threadwatch logo seochat tools logo