Alternative to the /proc

Discussion in 'Mac Programming' started by rmger, Jan 27, 2013.

  1. macrumors newbie

    Joined:
    Jan 26, 2013
    #1
    I know that "proc" absent in OS X, but can you show an alternative?

    Examples:
    strings /proc/PID/environ -will show us variable environments of process.
    file /proc/PID/cwd -will show us working catalog of process.
    stat -c %z /proc/PID -will show us when the process is started.
    cat /proc/PID/status -will show us who is the owner of this process and more.

    Possibly in OS X too there is such place where it is possible to learn a lot of things about process?
     
  2. macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #2
    Try Activity Monitor. Usually the first opened object is its currently working directory.

    Programmatically, I have no clue. Sorry
     
  3. macrumors 6502

    Joined:
    Mar 12, 2010
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    Using what language?

    The posted examples are shell commands. So do you need shell commands? If so, then the 'man ps' suggestion is a good one. Also see 'man top'.

    The sysctl(3) C function is a way to get varied process info using C:
    http://developer.apple.com/library/Mac/#documentation/Darwin/Reference/ManPages/man3/sysctl.3.html

    See the KERN_PROC selector, and also find the search term "kproc" on the man page for an example. You'll need to know the struct def, so refer to the appropriate .h file.

    Finally, the source for the commands 'ps' and 'top' is available from the Darwin project:
    http://www.opensource.apple.com/
    Both programs run setuid-root, so you will need enhanced privileges to obtain some process info. There's an API for that.
     
  5. thread starter macrumors newbie

    Joined:
    Jan 26, 2013
    #5
    Thanks for answers.
    With the 'ps' and 'top' I will only decide this tasks (already decided):

    "file /proc/PID/cwd -will show us working catalog of process.
    stat -c %z /proc/PID -will show us when the process is started.
    cat /proc/PID/status -will show us who is the owner of this process"

    chown33, with shell commands.

    "strings /proc/PID/environ -will show us variable environments of process." -I think that in OS X there is no such.
     
  6. Madd the Sane, Jan 27, 2013
    Last edited: Jan 27, 2013

    macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #6
    atMonitor does display that info, so there is a way.
     
  7. macrumors 603

    Joined:
    Aug 9, 2009
    #7
    See the man page for 'ps':
    -E Display the environment as well. This does not reflect changes in the environment after process launch.
    At the Terminal window, 'ps' is aware of the window width (see its man page). So either use the -w option (repeated, per its man page), or try this:
    Code:
    ps -E | cat
    
     

Share This Page