Recent Tweets

    Elsewhere

     

    February 2010
    S M T W T F S
    « Jan   Mar »
     123456
    78910111213
    14151617181920
    21222324252627
    28  

    Archives

    Getting untruncated command line options passed to a Solaris process

    If you have ever wanted to get the command line options that were passed to a running Solaris process, you might have noticed that the output of command line arguments from ps is truncated to 80 characters. Looking into /usr/include/sys/procfs.h will reveal the reason why! This is because of the restriction in struct psinfo. Here are the relevant fields from the definition of struct psinfo.

    #define	PRFNSZ		16	/* Maximum size of execed filename */
    #define	PRARGSZ		80	/* number of chars of arguments */
     
    typedef struct psinfo {
             /* Fields omitted */
             char pr_fname[PRFNSZ];    /* name of exec'ed file */
             char pr_psargs[PRARGSZ];  /* initial characters of arg list */
             /* Fields omitted */
    } psinfo_t;

    So, due to the 80 characters restriction in psinfo::pr_psargs, the kernel will not be keeping track of arguments beyond the limit. Now, the only way to get the information is from the process’ memory of argv. In order to do this, you should have access to read the processes’ memory. This is the trick employed by both pargs and BSD version of ps with -ww switch.

    To get the full length command line arguments passed to a process, you can do one of the following.

    $ /usr/ucb/ps eww <pid>
    $ pargs -l <pid>

    One catch here is that, if the process has modified the argv since it was started, the output reported by both ps and pargs will show the modified data and not the initial arguments that were passed in. However, modifying argv within a program is not a standard practice and hence the chance of encountering such a scenario is remote.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">